Repository navigation
69 lines (60 loc) · 1.89 KB
/
Copy pathauto-release.yml
File metadata and controls
69 lines (60 loc) · 1.89 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
name: auto-release
on:
push:
branches:
- main
- master
paths:
- package.json
permissions:
contents: write
actions: write
concurrency:
group: auto-release-${{ github.ref }}
cancel-in-progress: false
jobs:
tag:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Resolve tag from package.json
id: meta
shell: bash
run: |
VERSION=$(node -e "const fs=require('node:fs'); const p=JSON.parse(fs.readFileSync('package.json','utf8')); process.stdout.write(String(p.version||''));")
if [[ -z "$VERSION" ]]; then
echo "package.json version is empty" >&2
exit 1
fi
TAG="v${VERSION}"
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
- name: Create and push tag (if missing)
id: tagger
shell: bash
env:
TAG: ${{ steps.meta.outputs.tag }}
run: |
CREATED=0
if git ls-remote --tags origin "refs/tags/${TAG}" | grep -q "refs/tags/${TAG}$"; then
echo "Tag already exists: ${TAG}"
else
GIT_AUTHOR_NAME="github-actions[bot]" \
GIT_AUTHOR_EMAIL="41898282+github-actions[bot]@users.noreply.github.com" \
GIT_COMMITTER_NAME="github-actions[bot]" \
GIT_COMMITTER_EMAIL="41898282+github-actions[bot]@users.noreply.github.com" \
git tag -a "${TAG}" -m "Release ${TAG}"
git push origin "${TAG}"
CREATED=1
fi
echo "created=${CREATED}" >> "$GITHUB_OUTPUT"
- name: Dispatch release workflow
if: steps.tagger.outputs.created == '1'
shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
TAG: ${{ steps.meta.outputs.tag }}
run: |
gh workflow run release --field tag="$TAG"