Skip to content

Commit df427b1

Browse files
committed
chore(ci): merge CI and release into a single workflow
1 parent 3755968 commit df427b1

2 files changed

Lines changed: 84 additions & 89 deletions

File tree

.github/workflows/main.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ concurrency:
1010
group: ${{ github.workflow }}-${{ github.ref }}
1111
cancel-in-progress: true
1212

13+
permissions:
14+
contents: write
15+
id-token: write
16+
1317
jobs:
1418
check:
1519
name: Lint, Format & Test
@@ -61,3 +65,83 @@ jobs:
6165

6266
- name: Build
6367
run: npm run build:only
68+
69+
release:
70+
name: Release
71+
runs-on: ubuntu-latest
72+
needs: [build]
73+
74+
# Only release on push to main, not on PRs
75+
if: ${{ github.event_name == 'push' }}
76+
77+
steps:
78+
- name: Checkout repository
79+
uses: actions/checkout@v5
80+
with:
81+
fetch-depth: 0
82+
83+
- name: Install git-cliff
84+
uses: kenji-miyake/setup-git-cliff@v2
85+
86+
- name: Determine next version
87+
id: version
88+
run: |
89+
NEXT=$(git-cliff --bumped-version 2>/dev/null)
90+
CURRENT=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
91+
if [ "$NEXT" = "$CURRENT" ]; then
92+
echo "No version bump needed"
93+
echo "bump=false" >> "$GITHUB_OUTPUT"
94+
else
95+
echo "Next version: $NEXT"
96+
echo "bump=true" >> "$GITHUB_OUTPUT"
97+
echo "version=$NEXT" >> "$GITHUB_OUTPUT"
98+
fi
99+
100+
- name: Setup Node.js
101+
if: steps.version.outputs.bump == 'true'
102+
uses: actions/setup-node@v5
103+
with:
104+
node-version-file: .nvmrc
105+
cache: 'npm'
106+
cache-dependency-path: package-lock.json
107+
registry-url: 'https://registry.npmjs.org'
108+
109+
- name: Install dependencies
110+
if: steps.version.outputs.bump == 'true'
111+
run: npm ci --prefer-offline --no-audit --no-fund
112+
113+
- name: Build
114+
if: steps.version.outputs.bump == 'true'
115+
run: npm run build:only
116+
117+
- name: Bump package.json version
118+
if: steps.version.outputs.bump == 'true'
119+
run: npm version "${{ steps.version.outputs.version }}" --no-git-tag-version
120+
121+
- name: Generate changelog
122+
if: steps.version.outputs.bump == 'true'
123+
run: git-cliff --tag "${{ steps.version.outputs.version }}" -o CHANGELOG.md
124+
125+
- name: Commit and tag
126+
if: steps.version.outputs.bump == 'true'
127+
run: |
128+
git config user.name "github-actions[bot]"
129+
git config user.email "github-actions[bot]@users.noreply.github.com"
130+
git add package.json package-lock.json CHANGELOG.md
131+
git commit -m "chore(release): ${{ steps.version.outputs.version }}"
132+
git tag -a "${{ steps.version.outputs.version }}" -m "${{ steps.version.outputs.version }}"
133+
git push origin main --follow-tags
134+
135+
- name: Publish to npm
136+
if: steps.version.outputs.bump == 'true'
137+
run: npm publish --provenance --access public
138+
139+
- name: Generate release notes
140+
if: steps.version.outputs.bump == 'true'
141+
run: git-cliff --latest --strip header > RELEASE_NOTES.md
142+
143+
- name: Create GitHub Release
144+
if: steps.version.outputs.bump == 'true'
145+
run: gh release create "${{ steps.version.outputs.version }}" --title "${{ steps.version.outputs.version }}" --notes-file RELEASE_NOTES.md
146+
env:
147+
GH_TOKEN: ${{ github.token }}

.github/workflows/release.yml

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)