Skip to content

Commit

Permalink
Merge pull request #81 from department-of-veterans-affairs/bug/74-nar…
Browse files Browse the repository at this point in the history
…in-publish-new-package-support

[Bug] Update publish workflow to support new packages
  • Loading branch information
narin authored Dec 29, 2023
2 parents 0bca619 + 7815774 commit 3dc6247
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 26 deletions.
115 changes: 90 additions & 25 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ on:
- components
- tokens
- linting
version_bump:
description: Version bump
version_type:
description: Version type
required: true
type: choice
options:
Expand All @@ -23,6 +23,7 @@ on:
- patch
- minor
- major
- new package

jobs:
publish-package:
Expand All @@ -35,44 +36,75 @@ jobs:
with:
fetch-depth: 0
token: ${{ secrets.VA_MOBILE_ROBOT_GITHUB_PAT }}
- uses: ruby/setup-ruby@v1
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.2'
bundler-cache: true
- name: Use Node.js 18.x
- 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
- run: yarn install
- name: Bump version and publish to NPM
id: bump-version
- name: Set git config
run: |
git config --global user.name 'VA Automation Bot'
git config --global user.email '[email protected]'
- 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 "NPM Package name: $NPM_PACKAGE"
echo "Checking package.json version..."
CURRENT_VERSION=$(jq -r .version package.json)
LATEST_VERSION=$(npm view $NPM_PACKAGE versions --json | jq -r '.[-1]')
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
BUMP=${{ inputs.version_bump }}
echo "Bumping $BUMP version and publishing to NPM..."
echo "Bumping $BUMP version..."
if [[ "$BUMP" == "alpha" ]] || [[ "$BUMP" == "beta" ]]; then
npm version prerelease --preid $BUMP
npm publish --access public --tolerate-republish --tag $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
Expand All @@ -81,30 +113,34 @@ jobs:
echo "NEW_VERSION=$NEW_VERSION" >> "$GITHUB_OUTPUT"
echo "GIT_TAG=${{ inputs.package }}-v$NEW_VERSION" >> "$GITHUB_OUTPUT"
- name: Commit changes and tag
- name: Commit changes to git
if: ${{ inputs.version_type != 'new package' }}
working-directory: packages/${{ inputs.package }}
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 commit -m 'Version bump: ${{ steps.publish.outputs.GIT_TAG }}'
git push
TAG=${{ steps.bump-version.outputs.GIT_TAG }}
- 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_bump != 'alpha' && inputs.version_bump != 'beta' }}
if: ${{ inputs.version_type != 'alpha' && inputs.version_type != 'beta' && github.ref.name == 'main' }}
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.bump-version.outputs.GIT_TAG }}'
git commit -m 'Changelog for ${{ steps.publish.outputs.GIT_TAG }}'
git push
- name: Post to a Slack channel
- name: Send success message to Slack
id: slack
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN }}
with:
channel-id: C062TM03HN2 # DSVA #va-mobile-library-alerts channel
payload: |
Expand All @@ -114,23 +150,23 @@ jobs:
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Published *${{ steps.bump-version.outputs.NPM_PACKAGE_NAME }}* to NPM"
"text": "Published *${{ steps.package-name.outputs.NPM_PACKAGE_NAME }}* to NPM"
}
},
{
"type": "context",
"elements": [
{
"type": "mrkdwn",
"text": "*Version:* ${{ steps.bump-version.outputs.NEW_VERSION }}"
"text": "*Version:* ${{ steps.publish.outputs.NEW_VERSION }}"
},
{
"type": "mrkdwn",
"text": "<https://www.npmjs.com/package/${{ steps.bump-version.outputs.NPM_PACKAGE_NAME }}|NPM>"
"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.bump-version.outputs.GIT_TAG }}|GitHub>"
"text": "<https://github.com/department-of-veterans-affairs/va-mobile-library/releases/tag/${{ steps.publish.outputs.GIT_TAG }}|GitHub>"
},
{
"type": "mrkdwn",
Expand All @@ -143,5 +179,34 @@ jobs:
"unfurl_links": false,
"unfurl_media": false
}
- name: Send failure message to Slack
if: failure()
id: slack-error
uses: slackapi/[email protected]
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 *${{ steps.package-name.outputs.NPM_PACKAGE_NAME }}* 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
}
2 changes: 1 addition & 1 deletion packages/components/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@department-of-veterans-affairs/mobile-component-library",
"version": "0.3.5",
"version": "0.3.6-alpha.6",
"description": "VA Design System Mobile Component Library",
"main": "src/index.tsx",
"scripts": {
Expand Down

0 comments on commit 3dc6247

Please sign in to comment.