Skip to content

Commit 2a18804

Browse files
authored
Merge pull request #1983 from gitgitgadget/publish-github-actions
Publish the GitHub Actions to a separate branch This PR is part 4 (the final part in this repository) of addressing gitgitgadget/gitgitgadget#609, and it is stacked on top of gitgitgadget/gitgitgadget#1980, gitgitgadget/gitgitgadget#1981, and #1982 (and therefore contains also the commits of those PRs), therefore I will leave this in draft mode until those PRs are merged. After laying the groundwork for, and implementing, the set of GitHub Actions that can perform the same job as GitGitGadget's current Azure Pipelines can perform, this here PR adds automation to 1. transpile the `CIHelper` class (together with its dependencies) from Typescript to JavaScript, 2. bundle it as a single, dependency-less `dist/index.js`, 3. copy the required resources (`WELCOME.md`, some shell scripts) into the location expected by that `dist/index.js`, 4. remove all the rest except for the minimal GitHub Actions (`*/action.yml`, `*/index.js`), 5. commit the result as the new tip commit of the `v1` branch (creating it as needed), 6. tag that tip commit as `v1.<running-number>`, 7. push out the `v1` branch and the tag. The result of this is that GitGitGadget can still be developed conveniently in this here repository, and whenever anything gets merged to the `main` branch, the `v1` branch is automatically updated so that it will be picked up by GitHub workflows containing statements like: ```yaml - uses: gitgitgadget/gitgitgadget/handle-pr-comment@v1 ``` That way, we _finally_ address the fragile nature of the current setup where a set of Azure Pipelines maintain their own clone of `gitgitgadget/gitgitgadget`, and having to run `npm ci && npm run build` as needed. This closes gitgitgadget/gitgitgadget#1759
2 parents fb43b1c + c05d284 commit 2a18804

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)