Skip to content

Commit 51c16a4

Browse files
authored
GH-1594: Switch to trusted publishing (#453)
- Setup trusted publish.yml workflow for NPM publishing - Update to lerna 9.x
1 parent 8c40df4 commit 51c16a4

File tree

4 files changed

+1697
-1252
lines changed

4 files changed

+1697
-1252
lines changed

.github/workflows/publish-next.yml

Lines changed: 0 additions & 48 deletions
This file was deleted.

.github/workflows/publish.yml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
name: 'Publish to NPM'
2+
3+
on:
4+
workflow_run:
5+
workflows: ['CI']
6+
types:
7+
- completed
8+
branches: [master]
9+
workflow_call:
10+
inputs:
11+
ref:
12+
description: 'Git ref (branch, tag, or commit SHA) to checkout and publish'
13+
required: true
14+
type: string
15+
dist-tag:
16+
description: 'NPM dist-tag to use for publishing'
17+
required: false
18+
type: string
19+
default: 'next'
20+
workflow_dispatch:
21+
inputs:
22+
ref:
23+
description: 'Git ref (branch, tag, or commit SHA) to checkout and publish'
24+
required: true
25+
type: string
26+
dist-tag:
27+
description: 'NPM dist-tag to use for publishing'
28+
required: false
29+
type: choice
30+
options:
31+
- next
32+
- latest
33+
default: 'next'
34+
35+
permissions:
36+
contents: read
37+
id-token: write
38+
39+
jobs:
40+
publish:
41+
name: Build & Publish
42+
runs-on: ubuntu-22.04
43+
if: github.repository == 'eclipse-glsp/glsp-client' && (github.event_name == 'workflow_dispatch' || github.event_name == 'workflow_call' || (github.event.workflow_run.conclusion == 'success'))
44+
steps:
45+
- uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
46+
with:
47+
ref: ${{ inputs.ref || github.event.inputs.ref || github.event.workflow_run.head_commit.id || github.sha }}
48+
# Fetch all history for lerna to determine versions
49+
fetch-depth: 0
50+
51+
- name: Check for changes in "packages" or "examples" directory
52+
id: check_changes
53+
run: |
54+
DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}"
55+
# For 'next' dist-tag: check for changes when triggered by workflow_run or workflow_call
56+
# For 'latest' dist-tag or workflow_dispatch: always publish
57+
if [[ "$DIST_TAG" == "next" ]] && [[ "${{ github.event_name }}" != "workflow_dispatch" ]]; then
58+
if git diff --name-only HEAD^ HEAD | grep -qE '^(packages|examples)'; then
59+
echo "should_publish=true" >> $GITHUB_OUTPUT
60+
else
61+
echo "should_publish=false" >> $GITHUB_OUTPUT
62+
fi
63+
else
64+
echo "should_publish=true" >> $GITHUB_OUTPUT
65+
fi
66+
67+
- uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5.0.0
68+
if: steps.check_changes.outputs.should_publish == 'true'
69+
with:
70+
node-version: 20.x
71+
registry-url: 'https://registry.npmjs.org'
72+
73+
- name: Build
74+
if: steps.check_changes.outputs.should_publish == 'true'
75+
run: yarn
76+
77+
- name: Publish to NPM
78+
if: steps.check_changes.outputs.should_publish == 'true'
79+
run: |
80+
DIST_TAG="${{ inputs.dist-tag || github.event.inputs.dist-tag || 'next' }}"
81+
if [[ "$DIST_TAG" == "next" ]]; then
82+
yarn publish:next
83+
elif [[ "$DIST_TAG" == "latest" ]]; then
84+
yarn publish:latest
85+
else
86+
echo "Unknown dist-tag: $DIST_TAG"
87+
exit 1
88+
fi
89+
env:
90+
NPM_CONFIG_PROVENANCE: 'true'

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"lint:ci": "yarn lint --output-file eslint_report.json --format json",
2222
"lint:fix": " yarn lint --fix",
2323
"prepare": "yarn build",
24+
"publish:latest": "lerna publish from-package --no-git-reset -y",
2425
"publish:next": "lerna publish preminor --exact --canary --preid next --dist-tag next --no-git-reset --no-git-tag-version --no-push --ignore-scripts --yes",
2526
"standalone": "yarn --cwd ./examples/workflow-standalone",
2627
"start:exampleServer": "yarn standalone start:exampleServer",
@@ -36,7 +37,7 @@
3637
"@types/lodash": "4.14.191",
3738
"@types/node": "20.x",
3839
"concurrently": "^8.2.2",
39-
"lerna": "^7.1.1",
40+
"lerna": "^9.0.0",
4041
"mocha-ctrf-json-reporter": "^0.0.9",
4142
"typescript": "^5.9.2"
4243
},

0 commit comments

Comments
 (0)