Skip to content

Commit 6bf6b4c

Browse files
authored
ci: publish to npm (#433)
1 parent 21bc481 commit 6bf6b4c

3 files changed

Lines changed: 29 additions & 21 deletions

File tree

.github/workflows/release.yml

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,17 @@ jobs:
114114
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
115115
- uses: ./.github/actions/clone
116116

117-
- uses: oxc-project/setup-node@fdbf0dfd334c4e6d56ceeb77d91c76339c2a0885 # v1.0.4
117+
- uses: pnpm/action-setup@41ff72655975bd51cab0327fa583b6e92b6d3061 # v4.2.0
118+
119+
- uses: actions/setup-node@6044e13b5dc448c55e2357c09f80417699197238 # v6.2.0
120+
with:
121+
node-version-file: .node-version
122+
package-manager-cache: false
123+
registry-url: 'https://registry.npmjs.org'
124+
cache: 'pnpm'
125+
126+
- name: Install dependencies
127+
run: pnpm install
118128

119129
- name: Configure Git for access to vite-task
120130
run: git config --global url."https://x-access-token:${{ secrets.VITE_TASK_TOKEN }}@github.com/".insteadOf "ssh://git@github.com/"
@@ -172,32 +182,30 @@ jobs:
172182
sed -i 's/"version": "0.0.0"/"version": "0.0.0-${{ github.sha }}"/' packages/cli/package.json
173183
sed -i 's/"version": "0.0.0"/"version": "0.0.0-${{ github.sha }}"/' packages/global/package.json
174184
175-
# Setup node correctly for publishing to github registry
176-
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
177-
with:
178-
node-version-file: .node-version
179-
registry-url: 'https://npm.pkg.github.com'
180-
scope: '@voidzero-dev'
181-
package-manager-cache: false
182-
183185
- name: Build test
184186
run: pnpm --filter=@voidzero-dev/vite-plus-test build
185187

186-
- run: npm install -g npm@latest # For trusted publishing support
188+
- name: 'Setup npm'
189+
run: |
190+
npm install -g npm@latest
191+
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
192+
env:
193+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
187194

188195
- name: Publish native addons
189196
run: |
190-
echo '@voidzero-dev:registry=https://npm.pkg.github.com/' >> ~/.npmrc
191-
pnpm --filter=vite-plus publish-native
192-
pnpm --filter=vite-plus-cli publish-native
197+
node ./packages/cli/publish-native-addons.ts
198+
node ./packages/global/publish-native-addons.ts
193199
env:
194-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
200+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
201+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
195202

196203
- name: Publish
197204
run: |
198-
pnpm publish --filter=./packages/core --registry https://npm.pkg.github.com --no-git-checks
199-
pnpm publish --filter=./packages/test --registry https://npm.pkg.github.com --no-git-checks
200-
pnpm publish --filter=./packages/cli --registry https://npm.pkg.github.com --no-git-checks
201-
pnpm publish --filter=./packages/global --registry https://npm.pkg.github.com --no-git-checks
205+
pnpm publish --filter=./packages/core --access public --no-git-checks
206+
pnpm publish --filter=./packages/test --access public --no-git-checks
207+
pnpm publish --filter=./packages/cli --access public --no-git-checks
208+
pnpm publish --filter=./packages/global --access public --no-git-checks
202209
env:
203-
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
210+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
211+
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

packages/cli/publish-native-addons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ await cli.prePublish({
2929

3030
const npmDir = await readdir(join(currentDir, 'npm'));
3131
for (const file of npmDir) {
32-
execSync(`npm publish --tag latest --registry https://npm.pkg.github.com --no-git-checks`, {
32+
execSync(`npm publish --tag latest --access public --no-git-checks`, {
3333
cwd: join(currentDir, 'npm', file),
3434
env: process.env,
3535
stdio: 'inherit',

packages/global/publish-native-addons.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ await cli.prePublish({
2929

3030
const npmDir = await readdir(join(currentDir, 'npm'));
3131
for (const file of npmDir) {
32-
execSync(`npm publish --tag latest --registry https://npm.pkg.github.com --no-git-checks`, {
32+
execSync(`npm publish --tag latest --access public --no-git-checks`, {
3333
cwd: join(currentDir, 'npm', file),
3434
env: process.env,
3535
stdio: 'inherit',

0 commit comments

Comments
 (0)