-
Notifications
You must be signed in to change notification settings - Fork 46
110 lines (97 loc) · 3.91 KB
/
publish.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: QPP Measures Data Publish
on:
workflow_dispatch:
inputs:
version:
description: 'Version number to use'
required: true
release:
types: [published]
jobs:
update-version-and-publish:
runs-on: ubuntu-latest
steps:
- name: Checkout Codebase
uses: actions/checkout@v4
with:
ref: develop
fetch-depth: 0 # Ensures fetching of history for all branches and tags
token: ${{ secrets.ACTIONS_NICHOLAS_PAT }}
- name: Ensure 'develop' branch is checked out
run: |
CURRENT_BRANCH=$(git branch --show-current)
if [ "$CURRENT_BRANCH" != "develop" ]; then
git checkout develop
fi
- name: Configure Node version and registry
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- name: Install Dependencies and Build
run: |
npm ci
npm run build
- name: Update version in package.json and package-lock.json
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_NICHOLAS_PAT }}
run: |
VERSION=${{ github.event_name == 'workflow_dispatch' && github.event.inputs.version || github.event.release.tag_name }}
echo "Updating version to $VERSION"
# Fail the action if VERSION isn't set
if [ -z "$VERSION" ]; then
echo "VERSION is not set. Failing the action."
exit 1
fi
# Update version in package.json
jq --arg version "$VERSION" '.version = $version' package.json > temp.json && mv temp.json package.json
# Update version in package-lock.json
jq --arg version "$VERSION" '.version = $version' package-lock.json > temp-lock.json && mv temp-lock.json package-lock.json
# Check if there are changes (version was actually updated)
git diff --exit-code || HAS_CHANGES=1
if [ "$HAS_CHANGES" ]; then
git config user.name "GitHub actions"
git config user.email [email protected]
git add package.json package-lock.json
git commit -m "Update version to $VERSION"
git push --force
else
echo "Version is already up to date."
fi
- name: Publish to NPM
run: npm publish
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Merge develop into master
env:
GITHUB_TOKEN: ${{ secrets.ACTIONS_NICHOLAS_PAT }}
run: |
git config user.name "GitHub actions"
git config user.email [email protected]
git fetch origin master:master
git checkout master
git merge --no-ff develop -m "Merging develop into master via GitHub Action"
git push origin master
notify-others:
runs-on: ubuntu-latest
needs: update-version-and-publish
strategy:
matrix:
repo:
- CMSgov/qpp-submissions-api
steps:
- name: Repository Dispatch
uses: peter-evans/repository-dispatch@v3
with:
token: ${{ secrets.GH_USER_TOKEN }}
repository: ${{ matrix.repo }}
event-type: lib-update-event
client-payload: '{"ref": "${{ github.ref }}", "private_package": "@CMSGov/qpp-measures-data", "public_package":"qpp-measures-data" ,"tag_name": "${{ github.event.release.tag_name }}", "html_url": "${{github.event.release.html_url}}"}'
- name: Notify APP Submissions API Channel
uses: rtCamp/action-slack-notify@96d5e2a64fc78a6b7ac13265f55bee296869967a
env:
SLACK_WEBHOOK: ${{ secrets.SUBMISSIONS_API_SLACK_WEBHOOK }}
SLACK_CHANNEL: "p-qppsf-api"
SLACK_MESSAGE: "`qpp-measures-data` has been updated to version <${{github.event.release.html_url}}|${{ github.event.release.tag_name }}>"
SLACK_TITLE: New qpp-measures-data release
SLACK_USERNAME: releaseNotify