Skip to content

Commit c05d284

Browse files
committed
ci: automatically bundle & push the GitHub Actions to the v1 branch
We converted GitGitGadget into a bunch of GitHub Actions. The core logic of these is implemented in Typescript, which means that the code needs to be transpiled and bundled before it can be used as GitHub Action. This new workflow does exactly that. It maintains a new branch, called `v1`, and incremental tags of the `v1` tip commits, that are updated whenever the `main` branch advances. The updates consist of merging in `main`'s commit history, but the actual tree contents reflect the transpiled output, ready to be called as a GitHub Action from GitHub workflows. To reduce bandwidth when using the Action, all source code is removed from these tip commits, except for the few resources (`WELCOME.md` and two shell scripts) that are moved into the location where they need to be in order to be picked up by the GitHub Actions whenever needed. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
1 parent a209ca3 commit c05d284

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Push GitHub Actions
2+
on:
3+
push:
4+
branches:
5+
- main
6+
paths:
7+
- '**/action.yml'
8+
- '**/*.js'
9+
- '**/*.ts'
10+
- 'package*.json'
11+
- 'res/**/*'
12+
- 'script/**/*'
13+
- '.github/workflows/push-github-actions.yml'
14+
15+
permissions:
16+
contents: write
17+
18+
jobs:
19+
push-github-action:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v5
24+
with:
25+
persist-credentials: true
26+
- name: Set up Node.js
27+
uses: actions/setup-node@v4
28+
with:
29+
node-version: '20'
30+
- name: Install dependencies
31+
run: npm ci
32+
- name: Build dist/
33+
run: npm run build-dist
34+
- name: Commit the result
35+
id: commit
36+
run: |
37+
git config --local user.name "GitGitGadget CI" &&
38+
git config --local user.email "ci@noreply.github.com" &&
39+
40+
if ! git fetch --tags origin v1
41+
then
42+
# Starting from scratch
43+
v1=HEAD &&
44+
tag_name=v1.0
45+
else
46+
v1=FETCH_HEAD &&
47+
tag_name="$(git name-rev '--refs=refs/tags/v[0-9]*.[0-9]*' $v1)" &&
48+
case "$tag_name" in
49+
*' tags/v1.'*) incr="${tag_name#* tags/v1.}"; tag_name="v1.$(($incr + 1))";;
50+
*)
51+
tag_name=v1.0
52+
! git rev-parse --verify refs/tags/$tag_name || {
53+
echo "v1.0 already exists but is not reachable from v1?!?" >&2
54+
exit 1
55+
}
56+
;;
57+
esac
58+
fi &&
59+
60+
echo '{"type":"module"}' >dist/package.json &&
61+
# Include WELCOME.md in the dist/ directory
62+
cp -R res dist/ &&
63+
# Include the shell scripts for updating the mail-to-commit and commit-to-mail notes
64+
mkdir -p dist/script &&
65+
cp script/{lookup-commit,update-mail-to-commit-notes}.sh dist/script/ &&
66+
# Now, add the generated files
67+
git add -A dist/ &&
68+
# Remove the rest
69+
git rm -r -- \* ':(exclude)dist/' ':(exclude)*/action.yml' ':(exclude)*/index.js' &&
70+
71+
# Now make that fake merge commit
72+
tree=$(git write-tree) &&
73+
msg="Sync v1 with ($(git show -s --pretty=reference HEAD))" &&
74+
case "$v1" in
75+
HEAD) commit=$(git commit-tree -m "$msg" $tree -p HEAD);;
76+
*) commit=$(git commit-tree -m "$msg" $tree -p $v1 -p HEAD);;
77+
esac &&
78+
79+
# Now update the v1 branch and tag it
80+
git update-ref refs/heads/v1 $commit &&
81+
git tag $tag_name $commit &&
82+
echo "result=$tag_name" >>$GITHUB_OUTPUT
83+
- name: Push to v1
84+
run: git push origin v1 ${{ steps.commit.outputs.result }}

0 commit comments

Comments
 (0)