-
Notifications
You must be signed in to change notification settings - Fork 0
147 lines (118 loc) · 4.21 KB
/
main.yml
File metadata and controls
147 lines (118 loc) · 4.21 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: CI
on:
push:
branches: ['main']
pull_request:
branches: ['main']
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: write
id-token: write
jobs:
check:
name: Lint, Format & Test
runs-on: ubuntu-latest
# Skip release commits pushed by the release workflow
if: ${{ !startsWith(github.event.head_commit.message, 'chore(release):') }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --no-fund
- name: Run format check
run: npm run format:check
- name: Run linter
run: npm run lint
- name: Run tests
run: npm test
build:
name: Build
runs-on: ubuntu-latest
needs: [check]
steps:
- name: Checkout repository
uses: actions/checkout@v5
- name: Setup Node.js
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Install dependencies
run: npm ci --prefer-offline --no-audit --no-fund
- name: Build
run: npm run build:only
release:
name: Release
runs-on: ubuntu-latest
needs: [build]
# Only release on push to main, not on PRs
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout repository
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Install git-cliff
uses: kenji-miyake/setup-git-cliff@v2
- name: Determine next version
id: version
run: |
NEXT=$(git-cliff --bumped-version 2>/dev/null)
CURRENT=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
if [ "$NEXT" = "$CURRENT" ]; then
echo "No version bump needed"
echo "bump=false" >> "$GITHUB_OUTPUT"
else
echo "Next version: $NEXT"
echo "bump=true" >> "$GITHUB_OUTPUT"
echo "version=$NEXT" >> "$GITHUB_OUTPUT"
fi
- name: Setup Node.js
if: steps.version.outputs.bump == 'true'
uses: actions/setup-node@v5
with:
node-version-file: .nvmrc
cache: 'npm'
cache-dependency-path: package-lock.json
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
if: steps.version.outputs.bump == 'true'
run: npm ci --prefer-offline --no-audit --no-fund
- name: Build
if: steps.version.outputs.bump == 'true'
run: npm run build:only
- name: Bump package.json version
if: steps.version.outputs.bump == 'true'
run: npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
- name: Generate changelog
if: steps.version.outputs.bump == 'true'
run: git-cliff --tag "${{ steps.version.outputs.version }}" -o CHANGELOG.md
- name: Commit and tag
if: steps.version.outputs.bump == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add package.json package-lock.json CHANGELOG.md
git commit -m "chore(release): ${{ steps.version.outputs.version }}"
git tag -a "${{ steps.version.outputs.version }}" -m "${{ steps.version.outputs.version }}"
git push origin main --follow-tags
- name: Publish to npm
if: steps.version.outputs.bump == 'true'
run: npm publish --provenance --access public --ignore-scripts
- name: Generate release notes
if: steps.version.outputs.bump == 'true'
run: git-cliff --latest --strip header > RELEASE_NOTES.md
- name: Create GitHub Release
if: steps.version.outputs.bump == 'true'
run: gh release create "${{ steps.version.outputs.version }}" --title "${{ steps.version.outputs.version }}" --notes-file RELEASE_NOTES.md
env:
GH_TOKEN: ${{ github.token }}