Repository navigation
82 lines (72 loc) · 3.04 KB
/
Copy pathrelease-github-actions.yml
File metadata and controls
82 lines (72 loc) · 3.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
name: Release github-actions
# Auto-publishes the github-actions/ actions whenever they change on main.
# On each qualifying push it rebuilds the esbuild bundles, verifies the
# committed dist/ is up to date, then cuts an immutable vX.Y.Z tag and moves
# the vX major alias to the same commit so `@vX` consumers get the update.
#
# Versioning: the full version (vMAJOR.MINOR.PATCH) is read straight from
# github-actions/package.json — package.json is the single source of truth.
# Bump "version" there in your PR (patch, minor, or major); the workflow tags
# exactly that version and points the vMAJOR alias at it. A major bump creates
# a fresh vN alias and leaves older majors untouched. If a tag for the current
# version already exists, the run fails — that's the signal to bump the version.
on:
push:
branches: [ main ]
paths:
- 'github-actions/**'
workflow_dispatch:
permissions:
contents: write
concurrency:
group: release-github-actions
cancel-in-progress: false
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # full history + tags needed to compute the next version
- uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
with:
node-version: '24'
- name: Build action bundles
working-directory: github-actions
run: |
npm ci
npm run build
- name: Verify committed dist/ is up to date
run: |
if ! git diff --quiet -- github-actions/dist; then
echo "::error::github-actions/dist is stale. Run 'npm ci && npm run build' in github-actions/ and commit the result before merging."
git --no-pager diff --stat -- github-actions/dist
exit 1
fi
- name: Resolve version from package.json
id: ver
run: |
VER=$(node -p "require('./github-actions/package.json').version")
MAJOR=$(echo "$VER" | cut -d. -f1)
NEW="v${VER}"
ALIAS="v${MAJOR}"
git fetch --tags --force
if git rev-parse -q --verify "refs/tags/${NEW}" >/dev/null; then
echo "::error::Tag ${NEW} already exists. Bump \"version\" in github-actions/package.json before merging."
exit 1
fi
echo "new=$NEW" >> "$GITHUB_OUTPUT"
echo "alias=$ALIAS" >> "$GITHUB_OUTPUT"
echo "Releasing $NEW (alias $ALIAS) at $GITHUB_SHA"
- name: Tag and move major alias
env:
NEW: ${{ steps.ver.outputs.new }}
ALIAS: ${{ steps.ver.outputs.alias }}
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git tag -a "$NEW" -m "$NEW" "$GITHUB_SHA"
git tag -fa "$ALIAS" -m "$ALIAS -> $NEW" "$GITHUB_SHA"
git push origin "$NEW"
git push -f origin "$ALIAS"
echo "::notice::Released $NEW; $ALIAS now points at $NEW"