Skip to content

Commit 3238515

Browse files
committed
copilot's first pass at update-ci automation
1 parent 7eb342f commit 3238515

File tree

1 file changed

+95
-0
lines changed

1 file changed

+95
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Update CI when PR title starts with "tested-with"
2+
3+
on:
4+
pull_request:
5+
# Fire for typical PR lifecycle events
6+
types: [opened, edited, synchronize, reopened]
7+
# Only run when the specified file(s) are part of the PR diff.
8+
# CHANGE THIS to the path(s) you care about (supports globs).
9+
paths:
10+
- 'package.cabal'
11+
# - 'cabal.project'
12+
# - 'path/to/your/tested-with.txt'
13+
# - '**/*.cabal'
14+
15+
permissions:
16+
contents: write
17+
pull-requests: write
18+
19+
concurrency:
20+
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
21+
cancel-in-progress: true
22+
23+
jobs:
24+
update-ci:
25+
# Require: title starts with "tested-with" (case-insensitive)
26+
# and PR originates from the same repository (safe to push back)
27+
if: >
28+
startsWith(toLower(github.event.pull_request.title), 'tested-with') &&
29+
github.event.pull_request.head.repo.full_name == github.repository
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- name: Check out PR branch
34+
uses: actions/checkout@v4
35+
with:
36+
# Checkout the PR head branch so we can commit back to it
37+
ref: ${{ github.head_ref }}
38+
39+
# If you already have a repo script that regenerates CI, just run it.
40+
# Otherwise, the next steps show installing and running haskell-ci directly.
41+
- name: Run project CI update script (if present)
42+
id: maybe_script
43+
shell: bash
44+
run: |
45+
set -euxo pipefail
46+
if [ -x ./scripts/update-ci.sh ]; then
47+
./scripts/update-ci.sh
48+
echo "ran_script=true" >> "$GITHUB_OUTPUT"
49+
else
50+
echo "ran_script=false" >> "$GITHUB_OUTPUT"
51+
fi
52+
53+
# Haskell-specific: install haskell-ci from source and regenerate workflows
54+
- name: Set up Haskell toolchain
55+
if: steps.maybe_script.outputs.ran_script == 'false'
56+
uses: haskell/actions/setup@v2
57+
with:
58+
ghc-version: "9.6.6"
59+
cabal-version: "3.10.3.0"
60+
61+
- name: Install haskell-ci
62+
if: steps.maybe_script.outputs.ran_script == 'false'
63+
run: |
64+
set -euxo pipefail
65+
git clone --depth 1 https://github.com/haskell-CI/haskell-ci.git .tooling/haskell-ci
66+
cd .tooling/haskell-ci
67+
cabal update
68+
cabal build exe:haskell-ci
69+
cabal install exe:haskell-ci --overwrite-policy=always --installdir="$HOME/.local/bin" --install-method=copy
70+
echo "$HOME/.local/bin" >> "$GITHUB_PATH"
71+
72+
- name: Regenerate workflows with haskell-ci
73+
if: steps.maybe_script.outputs.ran_script == 'false'
74+
run: |
75+
set -euxo pipefail
76+
# If your repo uses a .haskell-ci file, regenerate from it:
77+
if [ -f .haskell-ci ]; then
78+
haskell-ci regenerate
79+
else
80+
# Fallback: generate from cabal metadata (adjust command as needed)
81+
haskell-ci generate
82+
fi
83+
84+
- name: Commit changes back to PR branch
85+
uses: stefanzweifel/git-auto-commit-action@v5
86+
with:
87+
commit_message: "chore(ci): regenerate CI from tested-with PR"
88+
branch: ${{ github.head_ref }}
89+
# Limit to the typical files haskell-ci and your script may edit
90+
file_pattern: |
91+
.github/workflows/**
92+
.haskell-ci
93+
*.cabal
94+
cabal.project*
95+
ci/**

0 commit comments

Comments
 (0)