Skip to content

Commit c1f3b93

Browse files
ci: migrate to npm trusted publisher (#51)
1 parent 66addcb commit c1f3b93

File tree

1 file changed

+41
-36
lines changed

1 file changed

+41
-36
lines changed

.github/workflows/publish-npm.yml

Lines changed: 41 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
1+
# ⚠️ THIS WORKFLOW IS THE TRUSTED PUBLISHER CONFIGURED ON NPMJS.COM, DO NOT RENAME OR DELETE THIS FILE ⚠️
12
name: Publish to npm
23

34
on:
5+
# For staging releases
6+
workflow_dispatch:
7+
# For latest releases
48
release:
59
types: [published]
6-
workflow_dispatch:
7-
inputs:
8-
version:
9-
description: "Version (e.g., 1.0.0)"
10-
required: true
11-
type: string
10+
11+
permissions:
12+
id-token: write # Required for OIDC
13+
packages: write
14+
contents: read
1215

1316
jobs:
14-
publish:
17+
set-staging-version:
18+
# Only run for manual dispatch on main branch
19+
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
1520
runs-on: ubuntu-latest
1621
steps:
17-
- name: Checkout
22+
- name: Checkout code
1823
uses: actions/checkout@v4
19-
20-
- name: Setup Node.js
24+
- name: Set up Node.js
2125
uses: actions/setup-node@v4
22-
with:
23-
node-version: "18"
24-
registry-url: "https://registry.npmjs.org"
25-
26-
- name: Get version
27-
id: version
28-
run: |
29-
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
30-
VERSION="${{ github.event.inputs.version }}"
31-
else
32-
VERSION=${GITHUB_REF#refs/tags/v}
33-
fi
34-
echo "version=$VERSION" >> $GITHUB_OUTPUT
35-
echo "Publishing version: $VERSION"
36-
37-
- name: Install and build
26+
- name: Set publish version
27+
id: set-staging-version
3828
run: |
39-
npm ci
40-
npm run build
29+
CURRENT_VERSION=$(npm pkg get version | tr -d '"')
30+
NIGHTLY_VERSION="${CURRENT_VERSION}-nightly-${GITHUB_SHA::7}"
31+
echo "VERSION=${NIGHTLY_VERSION}" >> $GITHUB_OUTPUT
32+
outputs:
33+
VERSION: ${{ steps.set-staging-version.outputs.VERSION }}
4134

42-
- name: Publish to npm
43-
run: npm publish --tag latest
44-
env:
45-
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
35+
publish-npm-staging:
36+
# Only run for manual dispatch on main branch
37+
if: ${{ github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/main' }}
38+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
39+
needs: set-staging-version
40+
with:
41+
scope: "@iexec/mcp-server"
42+
registry: "https://registry.npmjs.org"
43+
node-version: "20"
44+
tag: "nightly"
45+
version: ${{ needs.set-staging-version.outputs.VERSION }}
4646

47-
- name: Success
48-
run: |
49-
echo "✅ Published v${{ steps.version.outputs.version }}"
50-
echo "📦 npm: https://www.npmjs.com/package/@iexec/mcp-server"
47+
publish-npm-latest:
48+
# # Only run for release published with tag "v*"
49+
if: ${{ github.event_name == 'release' && startsWith(github.ref_name,'v') }}
50+
uses: iExecBlockchainComputing/github-actions-workflows/.github/workflows/[email protected]
51+
with:
52+
scope: "@iexec/mcp-server"
53+
registry: "https://registry.npmjs.org"
54+
node-version: "20"
55+
tag: "latest"

0 commit comments

Comments
 (0)