Skip to content

Commit e2e1dc9

Browse files
ci: switch to trusted publisher (#1809)
* ci: add trusted publisher for workflow * ci: merge publish beta workflow * chore: update lock file * chore: fix updated lint error * ci: update pull request workflows
1 parent 0f4cff4 commit e2e1dc9

6 files changed

Lines changed: 10217 additions & 9146 deletions

File tree

‎.github/workflows/pre-run.yml‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,4 @@ jobs:
2323
is_not_fork: ${{ steps.check.outputs.is_not_fork }}
2424
steps:
2525
- id: check
26-
run: echo "::set-output name=is_not_fork::${{ env.NPM_TOKEN != '' }}"
27-
env:
28-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
26+
run: echo "::set-output name=is_not_fork::${{ github.repository_owner == 'hirosystems' }}"

‎.github/workflows/publish-beta.yml‎

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

‎.github/workflows/publish.yml‎

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@ on:
55
branches:
66
- main
77
tags-ignore:
8-
- '**'
8+
- "**"
99
paths-ignore:
10-
- '**.md'
10+
- "**.md"
1111

1212
workflow_dispatch:
1313

14+
permissions:
15+
id-token: write # Required for OIDC
16+
contents: read
17+
1418
jobs:
1519
pre-run:
1620
uses: ./.github/workflows/pre-run.yml
@@ -21,28 +25,58 @@ jobs:
2125
needs: pre-run
2226
if: "needs.pre-run.outputs.is-not-fork == 'true' && (github.event_name == 'workflow_dispatch' || contains(github.event.head_commit.message, 'chore: version packages'))"
2327
steps:
24-
- uses: actions/checkout@v3
28+
- uses: actions/checkout@v4
2529
with:
2630
fetch-depth: 0
27-
- uses: actions/setup-node@v3
31+
- uses: actions/setup-node@v4
2832
with:
29-
node-version: 20
33+
node-version: 24
3034
cache: npm
3135

32-
- run: npm install -g npm@latest
3336
- run: npm ci
3437
- run: npm run build
3538

3639
- run: git config --local user.email 'action@github.com'
3740
- run: git config --local user.name 'GitHub Action'
3841

39-
- run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
40-
env:
41-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
42-
4342
- name: Publish
4443
run: |
4544
npx lerna publish from-package --no-verify-access --yes
4645
RELEASE=$(cat lerna.json | jq -r '.version')
4746
git tag -a v$RELEASE -m v$RELEASE
4847
git push origin v$RELEASE
48+
49+
publish-beta:
50+
runs-on: ubuntu-latest
51+
needs: pre-run
52+
if: "needs.pre-run.outputs.is-not-fork == 'true' && !contains(github.event.head_commit.message, 'chore: version packages')"
53+
steps:
54+
- uses: actions/checkout@v4
55+
with:
56+
fetch-depth: 0
57+
58+
# pulls all tags (needed for lerna to correctly version)
59+
- run: git fetch --depth=1 origin +refs/tags/*:refs/tags/*
60+
61+
- uses: actions/setup-node@v4
62+
with:
63+
node-version: 24
64+
cache: npm
65+
66+
- run: npm ci
67+
68+
- run: git config --local user.email 'action@github.com'
69+
- run: git config --local user.name 'GitHub Action'
70+
71+
- name: Version & Publish
72+
run: |
73+
LATEST=$(git describe --tags --abbrev=0)
74+
npx lerna version $LATEST --force-publish --no-changelog --no-push --no-git-tag-version --yes
75+
git commit -a -m 'DONT PUSH: fast-forward to latest npm release' --allow-empty --no-verify
76+
npx lerna version --force-publish --no-changelog --conventional-commits --conventional-prerelease --preid beta --no-push --no-git-tag-version --yes
77+
git commit -a -m 'DONT PUSH: version beta release' --allow-empty --no-verify
78+
RELEASE=$(cat lerna.json | jq -r '.version')
79+
npx lerna publish from-package --no-verify-access --pre-dist-tag beta --yes
80+
git reset HEAD~2 --hard
81+
git tag v$RELEASE
82+
git push origin v$RELEASE

‎.github/workflows/pull-request.yml‎

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: pull-request
22
on:
33
pull_request:
44
paths-ignore:
5-
- '**.md'
5+
- "**.md"
66

77
workflow_dispatch:
88

@@ -27,52 +27,53 @@ jobs:
2727
uses: ./.github/workflows/tests.yml
2828
secrets: inherit
2929

30-
publish-pr:
31-
runs-on: ubuntu-latest
32-
needs: [pre-run, tests]
33-
if: needs.pre-run.outputs.is-not-fork == 'true'
34-
steps:
35-
- uses: actions/checkout@v3
36-
if: github.event_name == 'pull_request'
37-
with:
38-
ref: ${{ github.event.pull_request.head.ref }}
39-
fetch-depth: 0
40-
- uses: actions/checkout@v3
41-
if: github.event_name == 'workflow_dispatch'
42-
with:
43-
fetch-depth: 0
44-
- uses: actions/setup-node@v3
45-
with:
46-
node-version: 20
47-
cache: npm
48-
- run: npm install -g npm@latest && npm ci
49-
- name: Set up npm auth token
50-
run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
51-
env:
52-
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
53-
- name: Publish to npm (feature branch)
54-
id: publish-pr
55-
run: |
56-
PUBLISH_OUTPUT_FILE=$(mktemp)
57-
npx lerna publish --canary --force-publish --preid pr --dist-tag pr --no-verify-access --no-push --no-git-tag-version --yes | tee $PUBLISH_OUTPUT_FILE
58-
VERSION=$(grep -oP '@stacks/common\s*=>\s*\K[^\s]+' $PUBLISH_OUTPUT_FILE | head -n 1)
59-
echo "Canary version: $VERSION"
60-
echo "::set-output name=version::$VERSION"
61-
if: ${{ (github.head_ref || github.ref_name) != 'nakamoto' && (github.head_ref || github.ref_name) != 'next' }}
62-
env:
63-
SKIP_TESTS: true
64-
- name: Publish to npm (next/nakamoto)
65-
run: |
66-
git reset --hard
67-
npx lerna publish --canary major --force-publish --preid $BRANCH --dist-tag $BRANCH --no-verify-access --no-push --no-git-tag-version --yes
68-
if: ${{ (github.head_ref || github.ref_name) == 'nakamoto' || (github.head_ref || github.ref_name) == 'next' }}
69-
env:
70-
BRANCH: ${{ github.head_ref || github.ref_name }}
71-
SKIP_TESTS: true
72-
- name: Edit pull-request description with published version
73-
uses: janniks/pull-request-fixed-header@v1.0.1
74-
with:
75-
header: "> This PR was published to npm with the version `${{ steps.publish-pr.outputs.version || env.BRANCH }}`\n> e.g. `npm install @stacks/common@${{ steps.publish-pr.outputs.version || env.BRANCH }} --save-exact`"
76-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77-
env:
78-
BRANCH: ${{ github.head_ref || github.ref_name }}
30+
# FOR NOW DISABLE PUBLISHING TO NPM ON EACH PULL-REQUEST PUSH
31+
# publish-pr:
32+
# runs-on: ubuntu-latest
33+
# needs: [pre-run, tests]
34+
# if: needs.pre-run.outputs.is-not-fork == 'true'
35+
# steps:
36+
# - uses: actions/checkout@v3
37+
# if: github.event_name == 'pull_request'
38+
# with:
39+
# ref: ${{ github.event.pull_request.head.ref }}
40+
# fetch-depth: 0
41+
# - uses: actions/checkout@v3
42+
# if: github.event_name == 'workflow_dispatch'
43+
# with:
44+
# fetch-depth: 0
45+
# - uses: actions/setup-node@v3
46+
# with:
47+
# node-version: 20
48+
# cache: npm
49+
# - run: npm install -g npm@latest && npm ci
50+
# - name: Set up npm auth token
51+
# run: echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > ~/.npmrc
52+
# env:
53+
# NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
54+
# - name: Publish to npm (feature branch)
55+
# id: publish-pr
56+
# run: |
57+
# PUBLISH_OUTPUT_FILE=$(mktemp)
58+
# npx lerna publish --canary --force-publish --preid pr --dist-tag pr --no-verify-access --no-push --no-git-tag-version --yes | tee $PUBLISH_OUTPUT_FILE
59+
# VERSION=$(grep -oP '@stacks/common\s*=>\s*\K[^\s]+' $PUBLISH_OUTPUT_FILE | head -n 1)
60+
# echo "Canary version: $VERSION"
61+
# echo "::set-output name=version::$VERSION"
62+
# if: ${{ (github.head_ref || github.ref_name) != 'nakamoto' && (github.head_ref || github.ref_name) != 'next' }}
63+
# env:
64+
# SKIP_TESTS: true
65+
# - name: Publish to npm (next/nakamoto)
66+
# run: |
67+
# git reset --hard
68+
# npx lerna publish --canary major --force-publish --preid $BRANCH --dist-tag $BRANCH --no-verify-access --no-push --no-git-tag-version --yes
69+
# if: ${{ (github.head_ref || github.ref_name) == 'nakamoto' || (github.head_ref || github.ref_name) == 'next' }}
70+
# env:
71+
# BRANCH: ${{ github.head_ref || github.ref_name }}
72+
# SKIP_TESTS: true
73+
# - name: Edit pull-request description with published version
74+
# uses: janniks/pull-request-fixed-header@v1.0.1
75+
# with:
76+
# header: "> This PR was published to npm with the version `${{ steps.publish-pr.outputs.version || env.BRANCH }}`\n> e.g. `npm install @stacks/common@${{ steps.publish-pr.outputs.version || env.BRANCH }} --save-exact`"
77+
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
78+
# env:
79+
# BRANCH: ${{ github.head_ref || github.ref_name }}

0 commit comments

Comments
 (0)