Repository navigation
87 lines (83 loc) · 2.99 KB
/
Copy pathrelease.yml
File metadata and controls
87 lines (83 loc) · 2.99 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
83
84
85
86
87
name: Release
# Two ways to release; the version always comes from the newest CHANGELOG.md section.
# - Run this workflow by hand on the default branch: it tags the checked-out commit
# with that version and publishes the release.
# - Push a tag yourself: the tag must match that version.
on:
push:
tags:
- '[0-9]*.[0-9]*.[0-9]*'
- 'v[0-9]*.[0-9]*.[0-9]*'
workflow_dispatch:
permissions:
contents: read
concurrency:
group: release
cancel-in-progress: false
jobs:
release:
if: >-
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) ||
(github.event_name == 'workflow_dispatch' &&
github.ref == format('refs/heads/{0}', github.event.repository.default_branch))
runs-on: ubuntu-24.04
timeout-minutes: 15
permissions:
contents: write
steps:
- uses: actions/checkout@v6
with:
persist-credentials: false
- uses: actions/setup-node@v7
with:
node-version: 22
- name: Resolve release tag
id: tag
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
run: |
if [ "$EVENT" = push ]; then
node scripts/release.mjs --print-version "$REF_NAME" >/dev/null
tag="$REF_NAME"
else
tag=$(node scripts/release.mjs --print-version)
if ref=$(gh api "repos/$GH_REPO/git/ref/tags/$tag" --jq '.object.type + " " + .object.sha' 2>/dev/null); then
set -- $ref
sha=$2
[ "$1" = tag ] && sha=$(gh api "repos/$GH_REPO/git/tags/$sha" --jq .object.sha)
if [ "$sha" != "$GITHUB_SHA" ]; then
echo "::error::tag $tag already exists on $sha, not on $GITHUB_SHA; add a new version section to CHANGELOG.md"
exit 1
fi
fi
fi
if gh release view "$tag" >/dev/null 2>&1; then
echo "::error::release $tag already exists"
exit 1
fi
echo "Release tag: $tag"
echo "name=$tag" >> "$GITHUB_OUTPUT"
- name: Install locked dependencies
run: npm ci --ignore-scripts
- name: Build release archive and notes
env:
RELEASE_TAG: ${{ steps.tag.outputs.name }}
run: npm run release -- "$RELEASE_TAG"
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
EVENT: ${{ github.event_name }}
RELEASE_TAG: ${{ steps.tag.outputs.name }}
run: |
# --target creates the tag on this commit when it does not exist yet.
if [ "$EVENT" = push ]; then
tag_opt=--verify-tag
else
tag_opt="--target=$GITHUB_SHA"
fi
gh release create "$RELEASE_TAG" build/LabelPlus_PS-Script_*.zip "$tag_opt" \
--title "v${RELEASE_TAG#v}" --notes-file build/release-notes.md