Skip to content

Commit 3a6b097

Browse files
authored
ci: add workflow to auto-tag and update version on merge (#24)
1 parent c75566c commit 3a6b097

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

.github/workflows/release.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: Release
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
branches:
7+
- main
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
release:
14+
runs-on: ubuntu-latest
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
cache: yarn
25+
26+
- name: Configure Git
27+
run: |
28+
git config user.name "github-actions"
29+
git config user.email "[email protected]"
30+
31+
- name: Install dependencies
32+
run: yarn install --frozen-lockfile
33+
34+
- name: Generate version from date
35+
id: generate_version
36+
run: |
37+
VERSION="v$(date +'%Y.%m.%d' | sed 's/0//g')"
38+
echo "VERSION=$VERSION" >> $GITHUB_ENV
39+
echo "Generated version: $VERSION"
40+
41+
- name: Update version in package.json
42+
run: |
43+
jq --arg new_version "${{ env.VERSION }}" '.version = $new_version' package.json > temp.json && mv temp.json package.json
44+
echo "Updated package.json to version: ${{ env.VERSION }}"
45+
46+
- name: Commit updated package.json
47+
run: |
48+
git add package.json
49+
git commit -m "chore: update version to ${{ env.VERSION }}"
50+
git push origin main
51+
52+
- name: Create Git tag
53+
run: |
54+
git tag -a "${{ env.VERSION }}" -m "Release ${{ env.VERSION }}"
55+
git push origin "${{ env.VERSION }}"
56+
57+
- name: Build the package
58+
run: yarn build
59+
60+
- name: Notify release
61+
run: echo "Release ${{ env.VERSION }} has been successfully created."
62+
63+
- name: Set up NPM auth
64+
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
65+
66+
- name: Publish to npm
67+
run: yarn publish --non-interactive
68+
env:
69+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

0 commit comments

Comments
 (0)