From ef26dcfed522126a22afcb6018923083a8ce5f6e Mon Sep 17 00:00:00 2001 From: Jerry Fu <2072627+jfoo1984@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:01:52 -0800 Subject: [PATCH] feat: move get release tag into composite action (#79) --- .github/actions/get-release-tag/action.yml | 35 +++++++++++++++++++ .github/workflows/deploy-prod.yml | 40 +++++++--------------- 2 files changed, 47 insertions(+), 28 deletions(-) create mode 100644 .github/actions/get-release-tag/action.yml diff --git a/.github/actions/get-release-tag/action.yml b/.github/actions/get-release-tag/action.yml new file mode 100644 index 00000000..81120211 --- /dev/null +++ b/.github/actions/get-release-tag/action.yml @@ -0,0 +1,35 @@ +name: Get release tag from GitHub API +description: This workflow will get the requested release tag specified in the input, or the latest release tag via the Github API +inputs: + requested_release_tag: + description: The release tag to search for + required: false + type: string +outputs: + release_tag: + description: The release tag + value: ${{ steps.get-release.outputs.result }} +runs: + using: "composite" + steps: + - name: Get latest or specified release + uses: actions/github-script@v7 + id: get-release + with: + retries: 3 + result-encoding: string + script: | + let releaseObj; + if (${{ inputs.requested_release_tag != '' }}) { + releaseObj = await github.rest.repos.getReleaseByTag({ + owner: context.repo.owner, + repo: context.repo.repo, + tag: "${{ github.event.inputs.release_tag }}" + }) + } else { + releaseObj = await github.rest.repos.getLatestRelease({ + owner: context.repo.owner, + repo: context.repo.repo + }) + } + return releaseObj.data.tag_name diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index ff08c548..f36f5272 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -8,41 +8,25 @@ on: name: Deploy release to prod jobs: + get-release-tag: + runs-on: [ARM64, self-hosted, Linux] + environment: production + outputs: + release_tag: ${{ steps.get-release.outputs.release_tag}} + steps: + - name: Get latest or specified release + uses: chanzuckerberg/czid-graphql-federation-server/.github/actions/get-release-tag@main + id: get-release + deploy-to-prod-env: + needs: get-release-tag + if: needs.get-release-tag.outputs.release_tag != '' runs-on: [ARM64, self-hosted, Linux] environment: production permissions: id-token: write contents: read steps: - - name: Get latest or specified release - uses: actions/github-script@v7 - id: get-release - with: - retries: 3 - result-encoding: string - script: | - let releaseObj; - if (${{ github.event.inputs.release_tag != '' }}) { - releaseObj = await github.rest.repos.getReleaseByTag({ - owner: context.repo.owner, - repo: context.repo.repo, - tag: "${{ github.event.inputs.release_tag }}" - }) - } else { - releaseObj = await github.rest.repos.getLatestRelease({ - owner: context.repo.owner, - repo: context.repo.repo - }) - } - return releaseObj.data.tag_name - - name: Output Github Release - if: steps.get-release.outputs.result != '' - id: set-release-tag - run: | - parsed_tag_name=${{ steps.get-release.outputs.result }} - echo "Tag name is: $parsed_tag_name" - echo "release_tag=$parsed_tag_name\n" >> $GITHUB_OUTPUT - name: Checkout repository uses: actions/checkout@v3 with: