From c7a3f579cb56052ec536177d17b8d4939e71bc5b Mon Sep 17 00:00:00 2001 From: Cheuk <90270663+cheukt@users.noreply.github.com> Date: Fri, 26 May 2023 15:17:43 -0400 Subject: [PATCH] update release workflows (#93) --- .github/workflows/main.yml | 6 -- .github/workflows/publish.yml | 44 ++++++-- .github/workflows/publish_candidate.yml | 53 ---------- .github/workflows/release.yml | 32 ++---- .github/workflows/release_candidate.yml | 132 ++++++++++++++++++++++++ 5 files changed, 176 insertions(+), 91 deletions(-) delete mode 100644 .github/workflows/publish_candidate.yml create mode 100644 .github/workflows/release_candidate.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 64acb16fb..56dea074b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -8,9 +8,3 @@ on: jobs: test: uses: viamrobotics/viam-typescript-sdk/.github/workflows/test.yml@main - - publish: - needs: test - uses: viamrobotics/viam-typescript-sdk/.github/workflows/publish.yml@main - secrets: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 27139ced2..c634ab04f 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -1,7 +1,8 @@ name: NPM Publish on: - workflow_call: + release: + types: [published] secrets: NPM_TOKEN: required: true @@ -14,17 +15,44 @@ jobs: image: ghcr.io/viamrobotics/canon:amd64 steps: - - name: Checkout - uses: actions/checkout@v3 + - name: Check if organization member + id: is_organization_member + if: github.event_name == 'workflow_dispatch' + uses: jamessingleton/is-organization-member@1.0.1 with: - persist-credentials: false + organization: viamrobotics + username: ${{ github.actor }} + token: ${{ secrets.GITHUB_TOKEN }} - - name: Build + - name: Cancelling - not an organization member + uses: andymckay/cancel-action@0.2 + if: | + github.event_name == 'workflow_dispatch' && steps.is_organization_member.outputs.result == 'false' + + - name: Download Release + uses: dsaltares/fetch-gh-release-asset@master + with: + file: "viamrobotics\\-sdk\\-.*\\.tgz" + regex: true + target: './' + version: tags/${{ github.event.release.tag_name }} + + - name: Check Files + id: release_file + run: echo "path=$(ls -1 | head -1)" >> $GITHUB_OUTPUT + + - name: Which Tag + id: which_tag run: | - sudo chown -R testbot . - sudo -u testbot bash -lc 'make build' + if [[ ${{ github.event.release.tag_name }} == *"rc"* ]]; then + echo "tag=rc" >> $GITHUB_OUTPUT + else + echo "tag=latest" >> $GITHUB_OUTPUT + fi - name: Publish - uses: JS-DevTools/npm-publish@v1 + uses: JS-DevTools/npm-publish@v2 with: token: ${{ secrets.NPM_TOKEN }} + tag: ${{ steps.which_tag.outputs.tag }} + package: ${{ steps.release_file.outputs.path }} diff --git a/.github/workflows/publish_candidate.yml b/.github/workflows/publish_candidate.yml deleted file mode 100644 index 8e2230277..000000000 --- a/.github/workflows/publish_candidate.yml +++ /dev/null @@ -1,53 +0,0 @@ -name: Publish Release Candidate to NPM - -on: - release: - types: [published] - secrets: - NPM_TOKEN: - required: true - workflow_dispatch: - secrets: - NPM_TOKEN: - required: true - -jobs: - publish_candidate: - if: | - github.repository_owner == 'viamrobotics' - && (github.event_name == 'workflow_dispatch' || github.event_name == 'release') - runs-on: [self-hosted, x64] - container: - image: ghcr.io/viamrobotics/canon:amd64 - - steps: - - name: Check if organization member - id: is_organization_member - if: github.event_name == 'workflow_dispatch' - uses: jamessingleton/is-organization-member@1.0.1 - with: - organization: viamrobotics - username: ${{ github.actor }} - token: ${{ secrets.GITHUB_TOKEN }} - - - name: Cancelling - not an organization member - uses: andymckay/cancel-action@0.2 - if: | - github.event_name == 'workflow_dispatch' && steps.is_organization_member.outputs.result == 'false' - - - name: Download Release - uses: dsaltares/fetch-gh-release-asset@master - with: - file: "viamrobotics\\-sdk\\-.*\\.tgz" - regex: true - target: './' - - - name: Check Files - id: release_file - run: echo "path=$(ls -1 | head -1)" >> $GITHUB_OUTPUT - - - name: Publish - uses: JS-DevTools/npm-publish@v2 - with: - token: ${{ secrets.NPM_TOKEN }} - package: ${{ steps.release_file.outputs.path }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c596451af..50bbdce33 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,25 +2,10 @@ name: Release on: workflow_dispatch: - inputs: - version: - description: 'The type of version bump. Select "nobump" for no version change. See https://github.com/npm/node-semver#functions' - type: choice - required: true - default: nobump - options: - - major - - minor - - patch - - premajor - - preminor - - prepatch - - prerelease - - nobump # this action is custom for this action and does not exist in npm jobs: prepare: - if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main' + if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-') runs-on: [self-hosted, x64] container: image: ghcr.io/viamrobotics/canon:amd64 @@ -48,8 +33,7 @@ jobs: sudo -u testbot bash -lc 'make build lint test' - name: Bump Version - run: npm version ${{ inputs.version }} --preid=pre --no-git-tag-version - if: inputs.version != 'nobump' + run: npm version ${$(npm pkg get version | sed 's/\"//g')%-rc*} --no-git-tag-version - name: Which Version id: which_version @@ -73,7 +57,7 @@ jobs: uses: peter-evans/create-pull-request@v5 with: commit-message: Bump version to ${{ steps.which_version.outputs.version }} - branch: release/${{ steps.which_version.outputs.version }} + branch: rc-${{ steps.which_version.outputs.version }} delete-branch: true base: main title: ${{ steps.which_version.outputs.version }} @@ -81,7 +65,7 @@ jobs: build: needs: prepare - if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main' + if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-') runs-on: [self-hosted, x64] container: image: ghcr.io/viamrobotics/canon:amd64 @@ -89,7 +73,7 @@ jobs: - name: Checkout Code uses: actions/checkout@v3 with: - ref: release/${{ needs.prepare.outputs.version }} + ref: rc-${{ needs.prepare.outputs.version }} - name: Build + Pack run: | @@ -104,7 +88,7 @@ jobs: release: needs: [prepare, build] - if: github.repository_owner == 'viamrobotics' && github.ref == 'refs/heads/main' + if: github.repository_owner == 'viamrobotics' && startsWith(github.ref, 'rc-') runs-on: [self-hosted, x64] container: image: ghcr.io/viamrobotics/canon:amd64 @@ -118,6 +102,6 @@ jobs: tag_name: v${{ needs.prepare.outputs.version }} files: packed/* draft: true - prerelease: ${{ contains(inputs.version, 'pre') }} + prerelease: false fail_on_unmatched_files: true - target_commitish: release/${{ needs.prepare.outputs.version }} + target_commitish: rc-${{ needs.prepare.outputs.version }} diff --git a/.github/workflows/release_candidate.yml b/.github/workflows/release_candidate.yml new file mode 100644 index 000000000..eca3a46f0 --- /dev/null +++ b/.github/workflows/release_candidate.yml @@ -0,0 +1,132 @@ +name: Publish Release Candidate to NPM + +on: + workflow_dispatch: + inputs: + version: + 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' + type: choice + required: true + default: nobump + options: + - premajor + - preminor + - prepatch + - nobump # this action is custom for this action and does not exist in npm + secrets: + NPM_TOKEN: + required: true + +jobs: + prepare: + if: github.repository_owner == 'viamrobotics' + runs-on: [self-hosted, x64] + container: + image: ghcr.io/viamrobotics/canon:amd64 + outputs: + rc_version: ${{ steps.which_version.outputs.rc_version }} + version: ${{ steps.which_version.outputs.version }} + steps: + - name: Check if organization member + id: is_organization_member + uses: jamessingleton/is-organization-member@1.0.1 + with: + organization: viamrobotics + username: ${{ github.actor }} + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Cancelling - not an organization member + uses: andymckay/cancel-action@0.2 + if: steps.is_organization_member.outputs.result == 'false' + + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Build + Lint + Test + run: | + sudo chown -R testbot . + sudo -u testbot bash -lc 'make build lint test' + + - name: Bump Version + id: bump_version + run: | + if [[ $(npm pkg get version) == *"rc"* ]]; then + npm version prerelease --preid=rc --no-git-tag-version + else + npm version ${{ inputs.version }} --preid=rc --no-git-tag-version + fi + if: inputs.version != 'nobump' + + - name: Which Version + id: which_version + run: | + echo "SDK_RC_VERSION=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_ENV + echo "SDK_VERSION=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_ENV + echo "rc_version=$(npm pkg get version | sed 's/\"//g')" >> $GITHUB_OUTPUT + echo "version=${$(npm pkg get version | sed 's/\"//g')%-rc*}" >> $GITHUB_OUTPUT + + - name: Check if release exists + uses: cardinalby/git-get-release-action@1.2.4 + id: release_exists + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + releaseName: v${{ steps.which_version.outputs.rc_version }} + doNotFailIfNotFound: 'true' + + - name: Cancelling - release already exists + uses: andymckay/cancel-action@0.2 + if: steps.release_exists.outputs.id != '' + + - name: Add + Commit + Open PR + uses: peter-evans/create-pull-request@v5 + with: + commit-message: Bump version to ${{ env.RC_SDK_VERSION }} + branch: rc-${{ env.SDK_VERSION }} + delete-branch: false + base: main + title: rc-${{ env.SDK_VERSION }} + body: This is an auto-generated PR to merge the rc branch back into main upon successful release. + + build: + needs: prepare + if: github.repository_owner == 'viamrobotics' + runs-on: [self-hosted, x64] + container: + image: ghcr.io/viamrobotics/canon:amd64 + steps: + - name: Checkout Code + uses: actions/checkout@v3 + with: + ref: rc-${{ needs.prepare.outputs.version }} + + - name: Build + Pack + run: | + sudo chown -R testbot . + sudo -u testbot bash -lc 'make build pack' + + - name: Upload artifacts + uses: actions/upload-artifact@v3 + with: + name: packed + path: viamrobotics-sdk-*.tgz + + release: + needs: [prepare, build] + if: github.repository_owner == 'viamrobotics' + runs-on: [self-hosted, x64] + container: + image: ghcr.io/viamrobotics/canon:amd64 + + steps: + - uses: actions/download-artifact@v3 + + - name: Release + uses: softprops/action-gh-release@v1 + with: + tag_name: v${{ needs.prepare.outputs.rc_version }} + files: dist/* + draft: true + prerelease: true + fail_on_unmatched_files: true + target_commitish: rc-${{ needs.prepare.outputs.version }}