-
Notifications
You must be signed in to change notification settings - Fork 43
85 lines (69 loc) · 2.67 KB
/
npm-publish.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
name: Publish package to NPM Registry
on:
release:
types: [created]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Allow only one concurrent deployment,but do NOT cancel in-progress runs as
# we want to allow these release deployments to complete.
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: false
permissions:
contents: read
id-token: write # necessary for NPM provenance
jobs:
publish-npm:
defaults:
run:
shell: bash
name: NPM Publish
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 'lts/*'
registry-url: https://registry.npmjs.org/
- name: Install latest npm
run: npm install -g npm@latest
- name: Install semver utility
run: npm install -g [email protected]
# Note - this is not required but it gives a clean failure prior to attempting a release if the GH workflow runner is not authenticated with NPMjs.com
- name: Verify NPM token is authenticated with NPMjs.com
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
run: npm whoami
- name: Check if GitHub repo package version is latest
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
run: |
# Fetch the published version on NPMjs.com.
PUBLISHED_VERSION=$(npm view @web5/dwn-server version 2>/dev/null || echo "0.0.0")
echo "Published Version: $PUBLISHED_VERSION"
# Fetch the version in the GitHub repo's package.json file.
REPO_VERSION=$(node -p "require('./package.json').version")
echo "REPO_VERSION=$REPO_VERSION" >> $GITHUB_ENV
echo "Repo Version: $REPO_VERSION"
# Compare the repo and NPMjs.com package versions.
IS_GREATER=$(semver --range ">$PUBLISHED_VERSION" $REPO_VERSION || true)
if [ -n "$IS_GREATER" ] ; then
echo "@web5/dwn-server@$REPO_VERSION is latest"
echo "IS_LATEST=true" >> $GITHUB_ENV
else
echo "@web5/dwn-server@$REPO_VERSION is already published or repo version is lower"
echo "IS_LATEST=false" >> $GITHUB_ENV
fi
- name: Install dependencies
if: env.IS_LATEST == 'true'
run: npm ci
- name: Build
if: env.IS_LATEST == 'true'
run: npm run build
- name: Publish @web5/dwn-server@${{ env.REPO_VERSION }}
if: env.IS_LATEST == 'true'
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
run: npm publish --access public --provenance