Skip to content

Commit 9d6d595

Browse files
author
Hayden
authored
feature: add github workflow for publishing to npm (#60)
* feature: add github workflow for publishing to npm * feature: add release docs * fix: remove version from "package.json"
1 parent cb75021 commit 9d6d595

File tree

5 files changed

+8270
-32602
lines changed

5 files changed

+8270
-32602
lines changed

.github/workflows/publish.yaml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Publish to NPM
2+
run-name: Publish release ${{ github.event.release.tag_name }} to NPM
3+
4+
on:
5+
release:
6+
types: [released] # A release was published, or a pre-release was changed to a release. https://docs.github.com/en/webhooks-and-events/webhooks/webhook-events-and-payloads?actionType=released#release
7+
8+
jobs:
9+
publish:
10+
name: Publish to NPM
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
17+
18+
- name: Check Input
19+
run: echo "Release Tag - ${{ github.event.release.tag_name }}"
20+
21+
- name: Validate Tag
22+
run: |
23+
if [[ "${{ github.event.release.tag_name }}" =~ ^v?[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
24+
echo "Tag ${{ github.event.release.tag_name }} is valid"
25+
else
26+
echo "Tag is invalid"
27+
exit 1
28+
fi
29+
30+
- name: Clean Tag
31+
id: clean-tag
32+
run: |
33+
echo "::set-output name=TAG::$(grep -Eo '[^v]?[0-9]+\.[0-9]+\.[0-9]+$' <<< '${{ github.event.release.tag_name }}')"
34+
35+
- name: Validated Tag
36+
run: echo "package.json version - ${{ steps.clean-tag.outputs.TAG }}"
37+
38+
- name: Setup node
39+
uses: actions/setup-node@v3
40+
with:
41+
node-version-file: ".nvmrc"
42+
registry-url: https://registry.npmjs.org/
43+
44+
- name: Update package.json version
45+
run: |
46+
tmp=$(mktemp)
47+
jq '.version = "${{ steps.clean-tag.outputs.TAG }}"' ./package.json > "$tmp" && mv "$tmp" ./package.json
48+
49+
- name: Publish package
50+
uses: JS-DevTools/npm-publish@v1
51+
with:
52+
token: ${{ secrets.PLATFORM_SA_NPM_TOKEN }}
53+
access: public
54+
tag: "latest"

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v18.17.1

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,6 @@ git push origin <your-branch-name>
7777
**IMPORTANT**: Please make sure to read through the [cla](cla.txt) file as part of opening a pull request.
7878

7979
9. We will review the pull requests and request any necessary changes. If all the checks (linting, compilation, tests) pass and everything looks good, your code will be merged into the original repository. Congratulations, and thank you for your contribution!
80+
81+
## Releasing
82+
To release the package to NPM, simply create a new GitHub release and the "Publish to NPM" GitHub action will release it to NPM.

0 commit comments

Comments
 (0)