-
Notifications
You must be signed in to change notification settings - Fork 5
97 lines (82 loc) · 2.67 KB
/
release.yml
File metadata and controls
97 lines (82 loc) · 2.67 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: Release
on:
push:
branches: [ main ]
paths-ignore:
- '.github/workflows/test.yml'
- 'examples/**'
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
name: Test, Build and Release
runs-on: ubuntu-latest
timeout-minutes: 30
# Skip if commit message contains [skip ci]
if: "!contains(github.event.head_commit.message, '[skip ci]')"
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
token: ${{ secrets.GH_PAT || secrets.GITHUB_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20.19.0'
cache: 'npm'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Run tests
run: npm test
- name: Build project
run: npm run build
- name: Bump version
id: version
run: |
# Configure git
git config --local user.email "action@github.com"
git config --local user.name "GitHub Action"
# Get current version
CURRENT_VERSION=$(node -p "require('./package.json').version")
echo "Current version: $CURRENT_VERSION"
# Bump version
npm version patch --no-git-tag-version
NEW_VERSION=$(node -p "require('./package.json').version")
echo "New version: $NEW_VERSION"
echo "version=${NEW_VERSION}" >> $GITHUB_OUTPUT
# Commit changes
git add package.json package-lock.json
if git diff --staged --quiet; then
echo "No changes to commit"
echo "skip_push=true" >> $GITHUB_OUTPUT
else
git commit -m "chore(release): ${NEW_VERSION} [skip ci]"
git tag "v${NEW_VERSION}"
echo "skip_push=false" >> $GITHUB_OUTPUT
fi
- name: Check if we should publish
id: should_publish
run: |
if [ -z "${{ secrets.NPM_TOKEN }}" ]; then
echo "NPM_TOKEN not set, skipping publish"
echo "publish=false" >> $GITHUB_OUTPUT
else
echo "NPM_TOKEN is set, will publish"
echo "publish=true" >> $GITHUB_OUTPUT
fi
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
if: steps.should_publish.outputs.publish == 'true'
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GH_PAT }}
branch: ${{ github.ref }}
tags: true
if: steps.version.outputs.skip_push != 'true'