-
Notifications
You must be signed in to change notification settings - Fork 0
133 lines (122 loc) · 4.4 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
# 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
version_bump:
description: Version bump
required: true
type: choice
options:
- alpha
- beta
- patch
- minor
- major
jobs:
publish-package:
runs-on: ubuntu-latest
defaults:
run:
working-directory: packages/${{ inputs.package }}
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
registry-url: https://registry.npmjs.org/
node-version-file: '.nvmrc'
- run: yarn install
- name: Bump version and publish to NPM
id: bump-version
run: |
NPM_PACKAGE=$(jq -r .name package.json)
echo "NPM_PACKAGE_NAME=$NPM_PACKAGE" >> "$GITHUB_OUTPUT"
echo "NPM Package name: $NPM_PACKAGE"
CURRENT_VERSION=$(jq -r .version package.json)
LATEST_VERSION=$(npm view $NPM_PACKAGE versions --json | jq -r '.[-1]')
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
BUMP=${{ inputs.version_bump }}
echo "Bumping $BUMP version and publishing to NPM..."
if [[ "$BUMP" == "alpha" ]] || [[ "$BUMP" == "beta" ]]; then
npm version prerelease --preid $BUMP
npm publish --access public --tolerate-republish --tag $BUMP
else
npm version $BUMP
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 package.json changes and tag
env:
GITHUB_TOKEN: ${{ secrets.VA_MOBILE_ROBOT_GITHUB_PAT }}
run: |
git config --global user.name 'VA Automation Bot'
git config --global user.email '[email protected]'
git pull
git add package.json
git commit -m 'Version bump: ${{ steps.bump-version.outputs.GIT_TAG }}'
git push
TAG=${{ steps.bump-version.outputs.GIT_TAG }}
echo $TAG
git tag -a $TAG -m $TAG
git push origin $TAG
- 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.bump-version.outputs.NPM_PACKAGE_NAME }}* to NPM"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Version:* ${{ steps.bump-version.outputs.NEW_VERSION }}"
},
{
"type": "mrkdwn",
"text": "<https://www.npmjs.com/package/${{ steps.bump-version.outputs.NPM_PACKAGE_NAME }}|NPM>"
},
{
"type": "mrkdwn",
"text": "<https://github.com/department-of-veterans-affairs/va-mobile-library/releases/tag/${{ steps.bump-version.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 }}