Repository navigation
97 lines (92 loc) · 2.62 KB
/
Copy pathdefault.yml
File metadata and controls
97 lines (92 loc) · 2.62 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
88
89
90
91
92
93
94
95
96
97
name: Lint and Test
on:
push:
branches:
- '**'
pull_request:
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install dependencies
run: npm ci
- name: Lint
run: npm run lint
test:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [20, 22, 24]
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install node
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm ci
- name: Test
run: npm test
release:
needs: [lint, test]
if: github.event_name == 'push' && github.ref == format('refs/heads/{0}', github.event.repository.default_branch)
runs-on: ubuntu-latest
permissions:
contents: write
concurrency:
group: release
cancel-in-progress: false
outputs:
tag: ${{ steps.version.outputs.tag }}
created: ${{ steps.release.outputs.created }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Read version
id: version
run: |
version=$(sed -nE 's/^ *"version": *"([^"]+)".*/\1/p' package.json | head -1)
if [ -z "$version" ]; then
echo "No version found in package.json" >&2
exit 1
fi
echo "tag=v$version" >> "$GITHUB_OUTPUT"
- name: Create tag and release
id: release
env:
GH_TOKEN: ${{ github.token }}
TAG: ${{ steps.version.outputs.tag }}
run: |
status=0
git ls-remote --exit-code --tags origin "refs/tags/$TAG" > /dev/null || status=$?
case "$status" in
0)
echo "Tag $TAG already exists; nothing to release."
echo "created=false" >> "$GITHUB_OUTPUT"
;;
2)
gh release create "$TAG" --target "$GITHUB_SHA" --title "$TAG" --generate-notes
echo "created=true" >> "$GITHUB_OUTPUT"
;;
*)
echo "Could not check whether tag $TAG exists (git ls-remote exited with $status)" >&2
exit "$status"
;;
esac
publish:
needs: release
if: needs.release.outputs.created == 'true'
permissions:
contents: read
id-token: write
uses: ./.github/workflows/release.yml
with:
tag: ${{ needs.release.outputs.tag }}
secrets: inherit