Skip to content

Commit da35071

Browse files
committed
ci: autopublish workflows
1 parent 7ec141a commit da35071

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

.github/workflows/publish.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Publish
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
7+
jobs:
8+
publish:
9+
name: Publish
10+
runs-on: ubuntu-latest
11+
permissions:
12+
contents: read
13+
id-token: write
14+
steps:
15+
- name: Chechout
16+
uses: actions/checkout@v4
17+
18+
- name: Verify package.json version
19+
shell: bash
20+
run: |
21+
VERSION=`jq -r '.version' package.json`;
22+
if [[ "refs/tags/v$VERSION" != "$GITHUB_REF" ]]
23+
then
24+
echo "::error::Pushed tag name does not match the package.json version at the tagged commit!";
25+
exit 1;
26+
fi
27+
28+
- name: Set up node
29+
uses: actions/setup-node@v4
30+
with:
31+
node-version: "24"
32+
registry-url: "https://registry.npmjs.org"
33+
34+
- name: Install dependencies
35+
run: npm ci
36+
37+
- name: Lint
38+
run: npm run lint
39+
40+
- name: Run tests
41+
run: npm run test
42+
43+
- name: Build
44+
run: npm run build
45+
46+
- name: Publish
47+
run: npm publish --provenance --access public
48+
env:
49+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/push.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on: push
44

55
jobs:
66
lint:
7+
name: Lint
78
runs-on: ubuntu-latest
89
steps:
910
- name: Checkout
@@ -22,6 +23,7 @@ jobs:
2223
run: npm run lint
2324

2425
test:
26+
name: Test
2527
runs-on: ubuntu-latest
2628
steps:
2729
- name: Checkout
@@ -38,3 +40,26 @@ jobs:
3840

3941
- name: Run unit tests
4042
run: npm run test
43+
44+
create-tag-if-needed:
45+
name: Create version tag on new version
46+
runs-on: ubuntu-latest
47+
needs: [lint, test]
48+
steps:
49+
- name: Checkout
50+
uses: actions/checkout@v4
51+
52+
- name: Create tag if needed
53+
shell: bash
54+
run: |
55+
VERSION=`jq -r '.version' package.json`
56+
if [[ "$VERSION" == "0.0.0" ]];
57+
then
58+
# fake version, quit
59+
exit 0
60+
fi
61+
if ! git fetch origin "v$VERSION"
62+
then
63+
git tag "v$VERSION"
64+
git push origin "v$VERSION"
65+
fi

0 commit comments

Comments
 (0)