-
Notifications
You must be signed in to change notification settings - Fork 0
175 lines (160 loc) · 5.87 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
# 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
- linting
- test
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 }}
GIT_AUTHOR_NAME: VA Automation Bot"
GIT_AUTHOR_EMAIL: [email protected]
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.VA_MOBILE_ROBOT_GITHUB_PAT }}
- uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
node-version-file: .nvmrc
cache: yarn
cache-dependency-path: yarn.lock
- run: yarn install
- name: Get NPM 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: Bump 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 and tag
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
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' }}
run: |
chmod +x .github/scripts/generate-changelog.sh
./.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: Post to a Slack channel
id: slack
uses: slackapi/[email protected]
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.publish.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
}
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN }}