Publish Package #104
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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_bump: | |
description: Version bump | |
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 }} | |
- 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_bump != 'new package' }} | |
working-directory: packages/${{ inputs.package }} | |
run: | | |
BUMP=${{ inputs.version_bump }} | |
NPM_PACKAGE=${{ steps.package-name.outputs.NPM_PACKAGE_NAME }} | |
echo "Checking latest version on NPM..." | |
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 | |
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_bump }}" | |
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 | |
working-directory: packages/${{ inputs.package }} | |
run: | | |
git config --global user.name 'VA Automation Bot' | |
git config --global user.email 'va-mobileapp@adhocteam.us' | |
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_bump != 'alpha' && inputs.version_bump != '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/slack-github-action@v1.24.0 | |
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 }} |