Skip to content

Commit c2aa795

Browse files
authored
Create npm-publish.yml
1 parent 8a5aee9 commit c2aa795

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

.github/workflows/npm-publish.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: NPM publish CD workflow
2+
3+
on:
4+
release:
5+
# This specifies that the build will be triggered when we publish a release
6+
types: [published]
7+
8+
jobs:
9+
build:
10+
11+
# Run on latest version of ubuntu
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v2
16+
with:
17+
# "ref" specifies the branch to check out.
18+
# "github.event.release.target_commitish" is a global variable and specifies the branch the release targeted
19+
ref: ${{ github.event.release.target_commitish }}
20+
# install Node.js
21+
- name: Use Node.js 12
22+
uses: actions/setup-node@v1
23+
with:
24+
node-version: 12
25+
# Specifies the registry, this field is required!
26+
registry-url: https://registry.npmjs.org/
27+
# clean install of your projects' deps. We use "npm ci" to avoid package lock changes
28+
- run: npm ci
29+
# set up git since we will later push to the repo
30+
- run: git config --global user.name "GitHub CD bot"
31+
- run: git config --global user.email "github-cd-bot@example.com"
32+
# upgrade npm version in package.json to the tag used in the release.
33+
- run: npm version ${{ github.event.release.tag_name }}
34+
# build the project
35+
- run: npm run build
36+
# run tests just in case
37+
# - run: npm test
38+
- run: npm publish
39+
env:
40+
# Use a token to publish to NPM. See below for how to set it up
41+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
42+
# push the version changes to GitHub
43+
- run: git push
44+
env:
45+
# The secret is passed automatically. Nothing to configure.
46+
github-token: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)