diff --git a/.github/workflows/publish-package.yml b/.github/workflows/publish-package.yml deleted file mode 100644 index 3c15c90e..00000000 --- a/.github/workflows/publish-package.yml +++ /dev/null @@ -1,54 +0,0 @@ -# Bump version and release a specific package to NPM -# https://github.com/department-of-veterans-affairs/va-mobile-app/actions/workflows/on_demand_build.yml - -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 - env: - YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }} - steps: - - uses: actions/checkout@v4 - - name: Use Node.js 18.x - uses: actions/setup-node@v3 - with: - node-version-file: '.nvmrc' - - run: yarn install - - name: Install dependencies in components - run: yarn install - - name: Bump version and publish to NPM - run: | - cd packages/${{ inputs.package }} - NPM_PACKAGE=$(jq -r .name package.json) - echo "NPM Package name: $NPM_PACKAGE" - LATEST_VERSION=$(npm view $NPM_PACKAGE version) - echo "Latest NPM version: $LATEST_VERSION" - npm version ${{ inputs.version_bump }} - NEW_VERSION=$(jq -r .version package.json) - GIT_TAG="${{ inputs.package }}-v$NEW_VERSION" - echo $GIT_TAG - - name: Setup tmate session - uses: mxschmitt/action-tmate@v3 - timeout-minutes: 15 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 766e5211..f4bc1c9d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,22 +1,129 @@ -name: Publish to NPM +# Bump version and release specified package to NPM + +name: 'Publish Package' on: workflow_dispatch: - release: - types: [published] + 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: + 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 - 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: Install dependencies in components - run: yarn install - - run: yarn publish-workspaces + - 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 + 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.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/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.bump-version.outputs.NPM_PACKAGE_NAME }}* to NPM" + } + }, + { + "type": "context", + "elements": [ + { + "type": "mrkdwn", + "text": "*Version:* ${{ steps.bump-version.outputs.NEW_VERSION }}" + }, + { + "type": "mrkdwn", + "text": "" + }, + { + "type": "mrkdwn", + "text": "" + }, + { + "type": "mrkdwn", + "text": "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Workflow Run>" + } + + ] + } + ], + "unfurl_links": false, + "unfurl_media": false + } env: - YARN_NPM_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_KEY }} + SLACK_BOT_TOKEN: ${{ secrets.SLACK_OAUTH_TOKEN }} diff --git a/packages/components/package.json b/packages/components/package.json index 4491007e..814b414e 100644 --- a/packages/components/package.json +++ b/packages/components/package.json @@ -1,6 +1,6 @@ { "name": "@department-of-veterans-affairs/mobile-component-library", - "version": "0.0.23", + "version": "0.0.31", "description": "VA Design System Mobile Component Library", "main": "src/index.tsx", "scripts": { diff --git a/packages/tokens/package.json b/packages/tokens/package.json index 4905f10c..4d5478f8 100644 --- a/packages/tokens/package.json +++ b/packages/tokens/package.json @@ -1,6 +1,6 @@ { "name": "@department-of-veterans-affairs/mobile-tokens", - "version": "0.0.10", + "version": "0.0.12", "description": "VA Design System Mobile Token Library", "main": "dist/js/tokens.js", "types": "dist/index.d.ts", diff --git a/yarn.lock b/yarn.lock index cf95f7d1..94799404 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2766,7 +2766,14 @@ __metadata: languageName: unknown linkType: soft -"@department-of-veterans-affairs/mobile-tokens@0.0.10, @department-of-veterans-affairs/mobile-tokens@workspace:packages/tokens": +"@department-of-veterans-affairs/mobile-tokens@npm:0.0.10": + version: 0.0.10 + resolution: "@department-of-veterans-affairs/mobile-tokens@npm:0.0.10" + checksum: 7590c87fb87e72891fe270f9dc53be8af3d0471d43cd448ead234b40d3f1fd5612740f049c121062c2beffd2597e81fa4e705e808bf3dc3110c33fbc1213f928 + languageName: node + linkType: hard + +"@department-of-veterans-affairs/mobile-tokens@workspace:packages/tokens": version: 0.0.0-use.local resolution: "@department-of-veterans-affairs/mobile-tokens@workspace:packages/tokens" dependencies: