|
| 1 | +name: Publish Release Candidate to NPM |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + version: |
| 7 | + description: 'The type of version bump. Select "nobump" for no version change. `rc` version bumps will happen automatically, so select the type of version bump for the final release. See https://github.com/npm/node-semver#functions' |
| 8 | + type: choice |
| 9 | + required: true |
| 10 | + default: nobump |
| 11 | + options: |
| 12 | + - premajor |
| 13 | + - preminor |
| 14 | + - prepatch |
| 15 | + - nobump # this action is custom for this action and does not exist in npm |
| 16 | + secrets: |
| 17 | + NPM_TOKEN: |
| 18 | + required: true |
| 19 | + |
| 20 | +jobs: |
| 21 | + prepare: |
| 22 | + if: github.repository_owner == 'viamrobotics' |
| 23 | + runs-on: [self-hosted, x64] |
| 24 | + container: |
| 25 | + image: ghcr.io/viamrobotics/canon:amd64 |
| 26 | + outputs: |
| 27 | + rc_version: ${{ steps.which_version.outputs.rc_version }} |
| 28 | + version: ${{ steps.which_version.outputs.version }} |
| 29 | + steps: |
| 30 | + - name: Check if organization member |
| 31 | + id: is_organization_member |
| 32 | + uses: jamessingleton/[email protected] |
| 33 | + with: |
| 34 | + organization: viamrobotics |
| 35 | + username: ${{ github.actor }} |
| 36 | + token: ${{ secrets.GITHUB_TOKEN }} |
| 37 | + |
| 38 | + - name: Cancelling - not an organization member |
| 39 | + |
| 40 | + if: steps.is_organization_member.outputs.result == 'false' |
| 41 | + |
| 42 | + - name: Checkout Code |
| 43 | + uses: actions/checkout@v3 |
| 44 | + |
| 45 | + - name: Build + Lint + Test |
| 46 | + run: | |
| 47 | + sudo chown -R testbot . |
| 48 | + sudo -u testbot bash -lc 'make build lint test' |
| 49 | +
|
| 50 | + - name: Bump Version |
| 51 | + id: bump_version |
| 52 | + run: | |
| 53 | + if [[ $(npm pkg get version) == *"rc"* ]]; then |
| 54 | + npm version prerelease --preid=rc --no-git-tag-version |
| 55 | + else |
| 56 | + npm version ${{ inputs.version }} --preid=rc --no-git-tag-version |
| 57 | + fi |
| 58 | + if: inputs.version != 'nobump' |
| 59 | + |
| 60 | + - name: Which Version |
| 61 | + id: which_version |
| 62 | + run: | |
| 63 | + echo "SDK_RC_VERSION=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_ENV |
| 64 | + echo "SDK_VERSION=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_ENV |
| 65 | + echo "rc_version=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_OUTPUT |
| 66 | + echo "version=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_OUTPUT |
| 67 | +
|
| 68 | + - name: Check if release exists |
| 69 | + uses: cardinalby/[email protected] |
| 70 | + id: release_exists |
| 71 | + env: |
| 72 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + with: |
| 74 | + releaseName: v${{ steps.which_version.outputs.rc_version }} |
| 75 | + doNotFailIfNotFound: 'true' |
| 76 | + |
| 77 | + - name: Cancelling - release already exists |
| 78 | + |
| 79 | + if: steps.release_exists.outputs.id != '' |
| 80 | + |
| 81 | + - name: Add + Commit + Open PR |
| 82 | + uses: peter-evans/create-pull-request@v5 |
| 83 | + with: |
| 84 | + commit-message: Bump version to ${{ env.RC_SDK_VERSION }} |
| 85 | + branch: rc-${{ env.SDK_VERSION }} |
| 86 | + delete-branch: false |
| 87 | + base: main |
| 88 | + title: rc-${{ env.SDK_VERSION }} |
| 89 | + body: This is an auto-generated PR to merge the rc branch back into main upon successful release. |
| 90 | + |
| 91 | + build: |
| 92 | + needs: prepare |
| 93 | + if: github.repository_owner == 'viamrobotics' |
| 94 | + runs-on: [self-hosted, x64] |
| 95 | + container: |
| 96 | + image: ghcr.io/viamrobotics/canon:amd64 |
| 97 | + steps: |
| 98 | + - name: Checkout Code |
| 99 | + uses: actions/checkout@v3 |
| 100 | + with: |
| 101 | + ref: rc-${{ needs.prepare.outputs.version }} |
| 102 | + |
| 103 | + - name: Build + Pack |
| 104 | + run: | |
| 105 | + sudo chown -R testbot . |
| 106 | + sudo -u testbot bash -lc 'make build pack' |
| 107 | +
|
| 108 | + - name: Upload artifacts |
| 109 | + uses: actions/upload-artifact@v3 |
| 110 | + with: |
| 111 | + name: packed |
| 112 | + path: viamrobotics-sdk-*.tgz |
| 113 | + |
| 114 | + release: |
| 115 | + needs: [prepare, build] |
| 116 | + if: github.repository_owner == 'viamrobotics' |
| 117 | + runs-on: [self-hosted, x64] |
| 118 | + container: |
| 119 | + image: ghcr.io/viamrobotics/canon:amd64 |
| 120 | + |
| 121 | + steps: |
| 122 | + - uses: actions/download-artifact@v3 |
| 123 | + |
| 124 | + - name: Release |
| 125 | + uses: softprops/action-gh-release@v1 |
| 126 | + with: |
| 127 | + tag_name: v${{ needs.prepare.outputs.rc_version }} |
| 128 | + files: dist/* |
| 129 | + draft: true |
| 130 | + prerelease: true |
| 131 | + fail_on_unmatched_files: true |
| 132 | + target_commitish: rc-${{ needs.prepare.outputs.version }} |
0 commit comments