-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (199 loc) · 7.2 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
# Bump version and release specified package to NPM
name: 'Publish Package'
on:
workflow_dispatch:
inputs:
package:
description: Package
required: true
type: choice
options:
- components
- tokens
- assets
- linting
version_type:
description: Version type
required: true
type: choice
options:
- alpha
- beta
- patch
- minor
- major
- new package
jobs:
publish-package:
runs-on: ubuntu-latest
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.VA_MOBILE_ROBOT_GITHUB_PAT }}
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Setup Node
uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
node-version-file: .nvmrc
cache: yarn
cache-dependency-path: yarn.lock
- name: Set git config
run: |
git config --global user.name 'VA Automation Bot'
git config --global user.email 'va-mobileapp@adhocteam.us'
- name: Install dependencies
run: yarn install
- name: Get package name
id: package-name
working-directory: packages/${{ inputs.package }}
run: |
NPM_PACKAGE=$(jq -r .name package.json)
echo "NPM Package name: $NPM_PACKAGE"
echo "NPM_PACKAGE_NAME=$NPM_PACKAGE" >> "$GITHUB_OUTPUT"
- name: Increment version
if: ${{ inputs.version_type != 'new package' }}
working-directory: packages/${{ inputs.package }}
run: |
BUMP=${{ inputs.version_type }}
NPM_PACKAGE=${{ steps.package-name.outputs.NPM_PACKAGE_NAME }}
echo "Checking package.json version..."
CURRENT_VERSION=$(jq -r .version package.json)
echo "Checking latest version on NPM..."
LATEST_VERSION=$(npm view $NPM_PACKAGE versions --json | \
jq -r 'if type=="string" then . elif type=="array" then .[-1] else "error" end')
if [[ "$LATEST_VERSION" == "error" ]]; then
echo "Unexpected result getting version. Exiting..."
exit 1
fi
echo "Latest NPM version: $LATEST_VERSION"
if [[ "$CURRENT_VERSION" != "$LATEST_VERSION" ]]; then
echo "Setting package.json version to $LATEST_VERSION"
npm version $LATEST_VERSION
fi
echo "Bumping $BUMP version..."
if [[ "$BUMP" == "alpha" ]] || [[ "$BUMP" == "beta" ]]; then
npm version prerelease --preid $BUMP
else
npm version $BUMP
fi
- name: Publish to NPM
id: publish
working-directory: packages/${{ inputs.package }}
run: |
BUMP="${{ inputs.version_type }}"
echo "Publishing to NPM..."
if [[ "$BUMP" == "alpha" ]] || [[ "$BUMP" == "beta" ]]; then
npm publish --access public --tolerate-republish --tag $BUMP
else
npm publish --access public --tolerate-republish
fi
NEW_VERSION=$(jq -r .version package.json)
echo "Updated version: $NEW_VERSION"
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "GIT_TAG=${{ inputs.package }}-v$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Commit changes to git
if: ${{ inputs.version_type != 'new package' }}
working-directory: packages/${{ inputs.package }}
run: |
git pull
git add package.json
git commit -m 'Version bump: ${{ steps.publish.outputs.GIT_TAG }}'
git push
- name: Create git tag
working-directory: packages/${{ inputs.package }}
run: |
TAG=${{ steps.publish.outputs.GIT_TAG }}
echo $TAG
git tag -a $TAG -m $TAG
git push origin $TAG
- name: Generate changelog
if: ${{ inputs.version_type != 'alpha' && inputs.version_type != 'beta' && github.ref_name == 'main' }}
run: |
chmod +x .github/scripts/generate-changelog.sh
cd documentation
./../.github/scripts/generate-changelog.sh ${{ inputs.package }} ${{ secrets.VA_MOBILE_ROBOT_GITHUB_PAT }}
git add CHANGELOG.md
git commit -m 'Changelog for ${{ steps.publish.outputs.GIT_TAG }}'
git push
- name: Send success message to Slack
id: slack
uses: slackapi/slack-github-action@v1.24.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN }}
with:
channel-id: C062TM03HN2 # DSVA #va-mobile-library-alerts channel
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Published *${{ steps.package-name.outputs.NPM_PACKAGE_NAME }}* to NPM"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Version:* ${{ steps.publish.outputs.NEW_VERSION }}"
},
{
"type": "mrkdwn",
"text": "<https://www.npmjs.com/package/${{ steps.package-name.outputs.NPM_PACKAGE_NAME }}|NPM>"
},
{
"type": "mrkdwn",
"text": "<https://github.com/department-of-veterans-affairs/va-mobile-library/releases/tag/${{ steps.publish.outputs.GIT_TAG }}|GitHub>"
},
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Workflow Run>"
}
]
}
],
"unfurl_links": false,
"unfurl_media": false
}
- name: Send failure message to Slack
if: failure()
id: slack-error
uses: slackapi/slack-github-action@v1.24.0
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN }}
with:
channel-id: C062TM03HN2 # DSVA #va-mobile-library-alerts channel
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ":red-x: Error publishing *${{ inputs.package }}* to NPM"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Workflow Run>"
}
]
}
],
"unfurl_links": false,
"unfurl_media": false
}