-
Notifications
You must be signed in to change notification settings - Fork 1
136 lines (114 loc) · 4.88 KB
/
release.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
name: Release
on:
push:
branches:
- main # Trigger only on pushes to the main branch
workflow_dispatch: # Allows manually triggering the workflow for testing or urgent releases
concurrency: ${{ github.workflow }}-${{ github.ref }}
jobs:
release:
if: github.repository == 'Ingvarstep/GLiNER.js'
permissions:
contents: write # Required to create the release
actions: read # For checking token permissions
issues: write # For creating an issue
name: Create GitHub Release and Publish to npm
runs-on: ubuntu-latest
steps:
# Set NPM Registry to ensure the correct registry is used
- name: Set NPM Registry
run:
npm config set registry https://registry.npmjs.org/
# Set NPM registry and authentication token via .npmrc
- name: Create .npmrc file with auth token
run: |
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
# Verify NPM Authentication
- name: Verify NPM Authentication
run: npm whoami
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
# Checkout the code
- name: Checkout code
uses: actions/checkout@v3
# Set up Node.js
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18
# Set up pnpm
- name: Set up pnpm
uses: pnpm/action-setup@v2
with:
version: 6.0.2
# Install dependencies
- name: Install dependencies
run: pnpm install
# Check for pending changesets before proceeding with the release
- name: Check for changesets
id: check_changesets
run: |
if pnpm changeset status | grep -q "No unreleased changesets"; then
echo "No unreleased changesets found. Skipping version bump and release."
exit 0
fi
continue-on-error: false # If no changesets are found, this step will stop the workflow
# Run Changesets to version the packages and apply changelogs
- name: Run Changesets version
if: steps.check_changesets.outcome == 'success'
run: pnpm changeset version
# Commit the version bump and changelog updates (if applicable)
- name: Commit version bump
if: steps.check_changesets.outcome == 'success'
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "[email protected]"
git add .
git commit -m "Version bump and changelog update"
git push
# Extract package name and version from package.json
- name: Get name and version from package.json
id: get_package_info
run: |
NAME=$(jq -r '.name' package.json)
VERSION=$(jq -r '.version' package.json)
echo "PACKAGE_NAME=$NAME" >> $GITHUB_ENV
echo "PACKAGE_VERSION=$VERSION" >> $GITHUB_ENV
# Create a new Git tag based on the version from package.json
- name: Create Tag
if: steps.check_changesets.outcome == 'success'
run: |
git tag v${{ env.PACKAGE_VERSION }}
git push origin v${{ env.PACKAGE_VERSION }}
# Build the package (after version bump)
- name: Build the package
if: steps.check_changesets.outcome == 'success'
run: pnpm run build # Ensure you have a build script in your package.json
# Create release archives (zip and gzip)
- name: Create source code archives
if: steps.check_changesets.outcome == 'success'
run: |
zip -r ${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.zip dist package.json src README.md CHANGELOG.md
tar -czvf ${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.tar.gz dist package.json src README.md CHANGELOG.md
# Create GitHub Release and Upload Release Assets (with display name "Source Code")
- name: Create GitHub Release and Upload Assets
if: steps.check_changesets.outcome == 'success'
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ env.PACKAGE_VERSION }} # Use the tag created in the previous step
name: ${{ env.PACKAGE_VERSION }} # Use the version as the release name
files: |
${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.zip#Source Code
${{ env.PACKAGE_NAME }}-${{ env.PACKAGE_VERSION }}.tar.gz#Source Code
env:
GITHUB_TOKEN:
${{ secrets.GITHUB_TOKEN }} # GitHub token for authentication
# Set the NPM authentication token using pnpm
- name: Set NPM Auth Token
run: pnpm config set //registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}
# Publish to npm (activated)
- name: Publish to npm
if: steps.check_changesets.outcome == 'success'
run: pnpm publish --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} # Use NPM token for publishing