Skip to content

Commit

Permalink
fix: add npm publish with provenance support
Browse files Browse the repository at this point in the history
  • Loading branch information
ghiscoding committed Nov 26, 2023
1 parent c8d981e commit 30f959c
Show file tree
Hide file tree
Showing 5 changed files with 143 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 3
fetch-depth: 0

- name: Set Node.js version
uses: actions/setup-node@v4
Expand Down
66 changes: 66 additions & 0 deletions .github/workflows/publish-dry-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: 🏷️👀 Publish (dry-run)

on: workflow_dispatch

permissions:
contents: write
id-token: write

jobs:
deploy-npm-latest:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Retrieve current Date Time in EST
shell: bash
run: echo "START_TIME=$(TZ=":America/New_York" date -R|sed 's/.....$//')" >> $GITHUB_ENV

- name: Current datetime - ${{ env.START_TIME }}
run: echo ${{ env.START_TIME }}

- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ github.event.pull_request.merged != true && contains('["ghiscoding"]', github.actor) != true }}
name: Ensure current actor is allowed to run the workflow
run: |
echo "Error: Your GitHub username (${{ github.actor }}) is not on the allowed list of admins for this workflow"
exit 1
- name: Set NodeJS
uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org/'
node-version: 20

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Run yarn install dependencies
run: yarn --frozen-lockfile

- name: Run Project Build
run: yarn run build

- name: "[dry-run] 🧪 NPM Release"
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
npm whoami
npx release-it --ci --dry-run
75 changes: 75 additions & 0 deletions .github/workflows/publish-npm-latest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: 🏷️ Publish NPM Latest

on: workflow_dispatch

permissions:
contents: write
id-token: write

jobs:
deploy-npm-latest:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Retrieve current Date Time in EST
shell: bash
run: echo "START_TIME=$(TZ=":America/New_York" date -R|sed 's/.....$//')" >> $GITHUB_ENV

- name: Current datetime - ${{ env.START_TIME }}
run: echo ${{ env.START_TIME }}

- name: Clone repository
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}

- if: ${{ github.event.pull_request.merged != true && contains('["ghiscoding"]', github.actor) != true }}
name: Ensure current actor is allowed to run the workflow
run: |
echo "Error: Your GitHub username (${{ github.actor }}) is not on the allowed list of admins for this workflow"
exit 1
- name: Set NodeJS
uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org/'
node-version: 20

- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT

- uses: actions/cache@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Run yarn install dependencies
run: yarn --frozen-lockfile

- name: Run Project Build
run: yarn run build

- name: OTP
uses: step-security/wait-for-secrets@v1
id: wait-for-secrets
with:
secrets: |
OTP:
name: 'OTP to publish package'
description: 'OTP from authenticator app'
- name: GitHub Release 🏷️ / NPM Publish 📦
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_CONFIG_PROVENANCE: true
run: |
git config --global user.name "${{ github.actor }}"
git config --global user.email "${{ github.actor }}@users.noreply.github.com"
npm whoami
npx release-it --ci --npm.otp=${{ steps.wait-for-secrets.outputs.OTP }}
2 changes: 0 additions & 2 deletions .npmrc

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
},
"repository": {
"type": "git",
"url": "http://github.com/ghiscoding/angular-slickgrid"
"url": "git+ssh://git@github.com/ghiscoding/angular-slickgrid.git"
},
"main": "src/app/modules/angular-slickgrid/index",
"private": false,
Expand Down

0 comments on commit 30f959c

Please sign in to comment.