Skip to content

Commit ee5d762

Browse files
chore: enhance GitHub Actions workflow for npm package release process
1 parent 3335f46 commit ee5d762

File tree

1 file changed

+44
-18
lines changed

1 file changed

+44
-18
lines changed

.github/workflows/release.yml

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,43 +8,69 @@ jobs:
88
build:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v4
12-
- uses: actions/setup-node@v4
11+
# Checkout the repository
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
15+
# Setup Node.js environment
16+
- name: Setup Node.js
17+
uses: actions/setup-node@v4
1318
with:
1419
node-version: "22.x"
15-
- run: npm install
1620

17-
- name: get-package-details
21+
# Install dependencies
22+
- name: Install dependencies
23+
run: npm install
24+
25+
# Fetch package details (name and version)
26+
- name: Get package details
1827
id: package
1928
uses: codex-team/[email protected]
20-
- name: install npm packall
29+
30+
# Install npm-pack-all to create a package archive
31+
- name: Install npm-pack-all
2132
run: npm install npm-pack-all
2233

23-
- run: node node_modules/.bin/npm-pack-all
24-
- uses: Klemensas/action-autotag@stable
34+
# Pack the package into a .tgz archive
35+
- name: Pack the npm package
36+
run: node node_modules/.bin/npm-pack-all
37+
38+
# Publish the package to npm
39+
- name: Publish to npm
40+
id: publish_npm
41+
uses: JS-DevTools/npm-publish@v3
42+
with:
43+
token: ${{ secrets.NPM_TOKEN }}
44+
45+
# Auto-tag the new version if a change is detected
46+
- name: Auto-tag new version
2547
id: update_tag
48+
uses: Klemensas/action-autotag@stable
2649
with:
2750
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
2851
tag_prefix: "v"
29-
- name: Create Release
30-
if: steps.update_tag.outputs.tagname
52+
53+
# Create a new GitHub Release
54+
- name: Create GitHub Release
55+
if: steps.update_tag.outputs.tagname != ''
3156
uses: actions/create-release@v4
3257
id: create_release
3358
env:
34-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
59+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3560
with:
3661
tag_name: ${{ steps.update_tag.outputs.tagname }}
3762
release_name: Release ${{ steps.update_tag.outputs.tagname }}
38-
draft: false # Default value, but nice to set explicitly
39-
prerelease: false # Default value, but nice to set explicitly
63+
draft: false
64+
prerelease: false
65+
66+
# Upload the packaged .tgz file as a release asset
4067
- name: Upload Release Asset
41-
if: steps.update_tag.outputs.tagname
42-
id: upload-release-asset
68+
if: steps.update_tag.outputs.tagname != ''
4369
uses: actions/upload-release-asset@v4
4470
env:
4571
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4672
with:
47-
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing its ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
48-
asset_path: ./${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}.tgz
49-
asset_name: ${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}.tgz
50-
asset_content_type: application/tgz
73+
upload_url: ${{ steps.create_release.outputs.upload_url }}
74+
asset_path: "./${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}.tgz"
75+
asset_name: "${{ steps.package.outputs.name }}-${{ steps.package.outputs.version }}.tgz"
76+
asset_content_type: application/gzip

0 commit comments

Comments
 (0)