-
Notifications
You must be signed in to change notification settings - Fork 1
64 lines (52 loc) · 1.92 KB
/
release-to-npm.yml
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
name: Release to NPM
on:
release:
types: [published]
permissions:
contents: write # Allow pushing changes to the repository
jobs:
release:
runs-on: ubuntu-latest
steps:
# Step 1: Check out the repository
- name: Checkout code
uses: actions/checkout@v3
# Step 2: Set up Node.js without caching
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
# Step 3: Clear npm cache
- name: Clear npm cache
run: npm cache clean --force
# Step 4: Install dependencies (without lock file)
- name: Install dependencies
run: npm install --no-package-lock
# Step 5: Sync package.json version with release tag
- name: Sync version with release tag
run: |
RELEASE_VERSION=${GITHUB_REF#refs/tags/}
echo "Updating package.json to version ${RELEASE_VERSION}"
npm version ${RELEASE_VERSION} --no-git-tag-version
# Step 6: Generate/update changelog
- name: Update changelog
run: npx standard-version --skip.tag --skip.commit
# Step 7: Authenticate with npm
- name: Authenticate with npm
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
# Step 8: Publish package to npm
- name: Publish to npm
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Step 9: Push updated files back to repository
- name: Push updated files back
run: |
git config user.name "GitHub Actions"
git config user.email "actions@github.com"
git checkout ${{ github.ref_name }}
git add package.json CHANGELOG.md
git commit -m "chore(release): ${GITHUB_REF#refs/tags/} [skip ci]" || echo "No changes to commit"
git push origin ${{ github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}