Skip to content

Commit 7e89882

Browse files
Merge pull request #205 from fingerprintjs/feat/CI-npm-deploy-pipeline
Feat: Add CI pipeline to NPM deployment
2 parents 2a496d5 + f317272 commit 7e89882

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

.github/workflows/npm_release.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Reference on this file: https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
2+
# In order to work properly, this workflow requires the repository to have an environment called "npm". The environment
3+
# must have a secret called NPM_ACCESS_TOKEN that holds an NPM access token that allows to publish the packages.
4+
# The environment should be protected to allow running only on the master branch.
5+
6+
name: Publish to NPM
7+
on: workflow_dispatch
8+
9+
jobs:
10+
publish:
11+
name: Build and publish
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 5
14+
environment: npm
15+
steps:
16+
- name: Checkout
17+
uses: actions/checkout@v4
18+
with:
19+
submodules: true
20+
- name: Cache
21+
uses: actions/cache@v4
22+
with:
23+
path: node_modules
24+
key: nodemodules-${{ hashFiles('yarn.lock') }}
25+
restore-keys: nodemodules-
26+
- name: Install Node packages
27+
run: yarn install
28+
- name: Build
29+
run: yarn build
30+
- name: Get the package version
31+
id: version
32+
run: |
33+
version=$(node -p "require('./package.json').version")
34+
tag=$(echo "$version" | grep -oP '(?<=-)[^.]+' || echo "latest")
35+
echo -e "Version: $version\nVersion tag: $tag"
36+
echo -e "version=$version\ntag=$tag" >> $GITHUB_OUTPUT
37+
- name: Publish to NPM
38+
# This command will automatically fail because of some common mistakes (this is a wanted behavior):
39+
# - The current version is already published
40+
# - The package uses a local directory as a dependency
41+
# - The NPM access token is invalid or expired
42+
run: |
43+
echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_ACCESS_TOKEN }}" > ~/.npmrc
44+
yarn publish --access public --tag "${{ steps.version.outputs.tag }}"
45+
- name: Create a Git tag
46+
uses: rickstaa/action-create-tag@v1
47+
with:
48+
tag: v${{ steps.version.outputs.version }}
49+
message: ' '

0 commit comments

Comments
 (0)