Skip to content

Commit 0e2dcf1

Browse files
committed
add release package script
0 parents  commit 0e2dcf1

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

.github/workflows/release.yaml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Heavily borrowed from https://superface.ai/blog/npm-publish-gh-actions-changelog
2+
3+
name: Release package
4+
run-name: "Release ${{ inputs.release-type }} by ${{ github.actor }}${{ inputs.dry-run && ' --dry-run'}}"
5+
6+
on:
7+
workflow_dispatch:
8+
inputs:
9+
release-type:
10+
description: "Release type"
11+
type: choice
12+
required: true
13+
options: [patch, minor, prepatch, preminor, prerelease]
14+
dry-run:
15+
description: "Dry Run - skip commit and publish"
16+
type: boolean
17+
default: false
18+
19+
jobs:
20+
release:
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: write
24+
25+
steps:
26+
# Checkout project repository
27+
- name: Checkout
28+
uses: actions/checkout@v3
29+
with:
30+
fetch-depth: 0
31+
token: ${{ secrets.SVC_DEVREV_TOKEN }}
32+
33+
# Setup Node.js environment
34+
- name: Setup Node.js
35+
uses: actions/setup-node@v3
36+
with:
37+
registry-url: https://registry.npmjs.org/
38+
node-version: '18.x'
39+
scope: '@devrev'
40+
token: ${{ secrets.NPM_TOKEN }}
41+
42+
- name: Git configuration
43+
run: |
44+
git config --global user.email "[email protected]"
45+
git config --global user.name "svc-devrev-sdk"
46+
47+
# Bump package version
48+
# Use tag latest
49+
- name: Bump release version
50+
if: startsWith(github.event.inputs.release-type, 'pre') != true
51+
run: |
52+
echo "NEW_VERSION=$(npm --no-git-tag-version version $RELEASE_TYPE)" >> $GITHUB_ENV
53+
echo "RELEASE_TAG=latest" >> $GITHUB_ENV
54+
env:
55+
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
56+
57+
# Bump package pre-release version
58+
# Use tag beta for pre-release versions
59+
- name: Bump pre-release version
60+
if: startsWith(github.event.inputs.release-type, 'pre')
61+
run: |
62+
echo "NEW_VERSION=$(npm --no-git-tag-version --preid=beta version $RELEASE_TYPE
63+
echo "RELEASE_TAG=beta" >> $GITHUB_ENV
64+
env:
65+
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
66+
67+
# Commit changes
68+
- name: Commit package.json changes and create tag
69+
run: |
70+
git add "package.json"
71+
git commit -m "chore: release ${{ env.NEW_VERSION }}"
72+
git tag ${{ env.NEW_VERSION }}
73+
74+
# Push repository changes
75+
- name: Push changes to repository
76+
if: ${{ github.event.inputs.dry-run == 'false' }}
77+
env:
78+
GITHUB_TOKEN: ${{ secrets.SVC_DEVREV_TOKEN }}
79+
run: |
80+
git push origin && git push --tags
81+
82+
# Documentation on config options https://github.com/softprops/action-gh-release
83+
- name: Update GitHub release documentation
84+
if: ${{ github.event.inputs.dry-run == 'false' }}
85+
uses: softprops/action-gh-release@v1
86+
with:
87+
tag_name: ${{ env.NEW_VERSION }}
88+
name: ${{ env.NEW_VERSION }}
89+
generate_release_notes: true
90+
prerelease: ${{ startsWith(github.event.inputs.release-type, 'pre') }}
91+
env:
92+
GITHUB_TOKEN: ${{ secrets.SVC_DEVREV_TOKEN }}
93+
94+
# Publish version to public repository
95+
- name: Publish
96+
run: |
97+
npm ci \
98+
&& npm run build \
99+
&& npm publish --verbose --access public --tag ${{ env.RELEASE_TAG }} ${{ env.DRY_RUN }}
100+
env:
101+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
102+
DRY_RUN: ${{ github.event.inputs.dry-run != 'false' && '--dry-run' || ' '}}

0 commit comments

Comments
 (0)