64 lines (60 loc) · 2.24 KB
/
publish-npm-gh.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
name: Publish NPM & Github Release
on:
workflow_dispatch:
inputs:
isProdRelease:
type: boolean
description: Is this a production release?
required: true
default: false
workflow_call:
inputs:
isProdRelease:
type: boolean
description: Is this a production release?
required: true
default: false
jobs:
publish-npm-and-github:
# pub-hk-ubuntu-22.04- due to IP allow list issues with public repos: https://salesforce.quip.com/bu6UA0KImOxJ
runs-on: pub-hk-ubuntu-22.04-small
steps:
- uses: actions/checkout@v3
with:
# fetch entire repo, not just this branch. Tags & commits are needed for release notes
fetch-depth: 0
- name: Use Node.js 16.x
uses: actions/setup-node@v3
with:
node-version: 16.x
cache: yarn
- run: yarn --frozen-lockfile --network-timeout 1000000
- name: set NPM auth
run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_PUBLISH_KEY }}" > ~/.npmrc
- name: set git user
run: |
git config user.name "GitHub Actions Bot"
git config user.email "heroku-front-end+npm-releases@salesforce.com"
- name: Publish to NPM
run: |
if ${{ fromJSON(inputs.isProdRelease) }}
then
bash scripts/publish-npm-latest
else
bash scripts/publish-npm-prerelease
fi
shell: bash
- name: Release to Github
if: fromJSON(inputs.isProdRelease)
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# the script below will fail if run in a separate shell file
run: |
PACKAGE_VERSION=$(node -e "console.log(require('./lerna.json').version)")
TAG_NAME="v${PACKAGE_VERSION}"
SORTED_TAGS=$(git tag --sort="-version:refname" --list --format="%(refname:strip=2)")
FILTERED_TAGS=$(echo "${SORTED_TAGS}" | grep 'v[0-9.]*' | grep -v '-')
LAST_PUBLISHED_TAG=$(echo "${FILTERED_TAGS}" | head -n1)
RELEASE_NOTES=$(git log --graph --format="%h %s" "${LAST_PUBLISHED_TAG}..${TAG_NAME}~1")
gh release create "${TAG_NAME}" --title="${TAG_NAME}" --notes="${RELEASE_NOTES}"
shell: bash