Skip to content

Commit a46f28f

Browse files
authored
Fixes/versioning (#29)
Merged automatically after successful CI.
1 parent 3aeeceb commit a46f28f

4 files changed

Lines changed: 173 additions & 2 deletions

File tree

.github/workflows/ci-main.yml

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
name: CI · Main Push · Patch Release
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: write
11+
12+
concurrency:
13+
group: ci-main-github-workflows
14+
cancel-in-progress: true
15+
16+
jobs:
17+
lint:
18+
name: Run actionlint
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Install actionlint
25+
run: |
26+
curl -sSfL https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash \
27+
| bash -s -- latest /usr/local/bin
28+
29+
- name: Run actionlint
30+
run: actionlint
31+
32+
calculate_tag:
33+
name: Compute next tag
34+
needs:
35+
- lint
36+
if: |
37+
github.event_name == 'push' &&
38+
github.ref == 'refs/heads/main' &&
39+
github.actor != 'github-actions[bot]' &&
40+
needs.lint.result == 'success'
41+
uses: ./.github/workflows/workflow-compute-next-tag.yml
42+
with:
43+
target-branch: main
44+
version-bump: patch
45+
secrets:
46+
gh_token: ${{ secrets.GITHUB_TOKEN }}
47+
48+
create_tag:
49+
name: Create git tag
50+
needs:
51+
- lint
52+
- calculate_tag
53+
if: ${{ needs.calculate_tag.result == 'success' }}
54+
uses: ./.github/workflows/workflow-create-tag.yml
55+
with:
56+
target-branch: main
57+
next-tag: ${{ needs.calculate_tag.outputs['new-tag'] }}
58+
previous-tag: ${{ needs.calculate_tag.outputs['previous-tag'] }}
59+
secrets:
60+
gh_token: ${{ secrets.GITHUB_TOKEN }}
61+
62+
create_release:
63+
name: Publish release
64+
needs:
65+
- create_tag
66+
if: ${{ needs.create_tag.result == 'success' }}
67+
uses: ./.github/workflows/workflow-create-release.yml
68+
with:
69+
tag-name: ${{ needs.create_tag.outputs['new-tag'] }}
70+
previous-tag: ${{ needs.create_tag.outputs['previous-tag'] }}
71+
merged-prs: "[]"
72+
secrets:
73+
gh_token: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: CI · Merge · Release
1+
name: CI · PR Auto-merge · Release
22

33
on:
44
pull_request:
@@ -16,7 +16,7 @@ permissions:
1616
pull-requests: write
1717

1818
concurrency:
19-
group: ci-github-workflows
19+
group: ci-pr-github-workflows
2020
cancel-in-progress: true
2121

2222
jobs:
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
name: Update version file
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
target-branch:
7+
description: Branch to check out before writing the version file
8+
required: false
9+
default: master
10+
type: string
11+
version-file:
12+
description: Path to the version file to overwrite
13+
required: false
14+
default: public/version.txt
15+
type: string
16+
next-tag:
17+
description: Tag value to write into the version file
18+
required: true
19+
type: string
20+
secrets:
21+
gh_token:
22+
required: true
23+
24+
outputs:
25+
new-tag:
26+
description: Tag that was written into the version file
27+
value: ${{ jobs.update_version_file.outputs.new_tag }}
28+
29+
jobs:
30+
update_version_file:
31+
name: Update version file
32+
runs-on: ubuntu-latest
33+
permissions:
34+
contents: write
35+
outputs:
36+
new_tag: ${{ steps.write_version.outputs.new_tag }}
37+
steps:
38+
- name: Check out branch with tags
39+
uses: actions/checkout@v4
40+
with:
41+
ref: ${{ inputs['target-branch'] }}
42+
fetch-depth: 0
43+
token: ${{ secrets.gh_token }}
44+
45+
- name: Write version marker
46+
id: write_version
47+
env:
48+
NEXT_TAG: ${{ inputs['next-tag'] }}
49+
VERSION_FILE: ${{ inputs['version-file'] }}
50+
run: |
51+
set -euo pipefail
52+
if [ -z "${NEXT_TAG:-}" ]; then
53+
echo "next-tag input is required" >&2
54+
exit 1
55+
fi
56+
mkdir -p "$(dirname "$VERSION_FILE")"
57+
printf '%s\n' "$NEXT_TAG" > "$VERSION_FILE"
58+
echo "new_tag=${NEXT_TAG}" >> "$GITHUB_OUTPUT"
59+
60+
- name: Commit version marker
61+
env:
62+
VERSION_FILE: ${{ inputs['version-file'] }}
63+
NEW_TAG: ${{ steps.write_version.outputs.new_tag }}
64+
run: |
65+
set -euo pipefail
66+
git config --local user.name "github-actions[bot]"
67+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
68+
git add "$VERSION_FILE"
69+
if git diff --cached --quiet; then
70+
echo "Version file already up to date."
71+
exit 0
72+
fi
73+
git commit -m "Record version ${NEW_TAG}"
74+
git push origin HEAD:${{ inputs['target-branch'] }}

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,30 @@ jobs:
112112
gh_token: ${{ secrets.GITHUB_TOKEN }}
113113
```
114114

115+
### `workflow-update-version-file.yml`
116+
Writes the provided tag into a version file on a target branch and pushes the commit.
117+
118+
**Inputs**
119+
- `target-branch` (default `master`): branch to check out before writing the version file.
120+
- `version-file` (default `public/version.txt`): path to overwrite with the new tag.
121+
- `next-tag` (required): tag value to write.
122+
123+
**Outputs**
124+
- `new-tag`: tag that was written.
125+
126+
**Example**
127+
```yaml
128+
jobs:
129+
write-version:
130+
uses: vinitu-net/github-workflows/.github/workflows/[email protected]
131+
with:
132+
target-branch: master
133+
version-file: public/version.txt
134+
next-tag: ${{ needs.calculate-tag.outputs.new-tag }}
135+
secrets:
136+
gh_token: ${{ secrets.GITHUB_TOKEN }}
137+
```
138+
115139
### `workflow-create-release.yml`
116140
Publishes a GitHub Release for a given tag. If `merged-prs` is omitted or empty, it collects merged PRs between `previous-tag` and `tag-name`.
117141

0 commit comments

Comments
 (0)