Skip to content

Commit

Permalink
feat: move get release tag into composite action (#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfoo1984 authored Jan 27, 2024
1 parent 929ebf5 commit ef26dcf
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 28 deletions.
35 changes: 35 additions & 0 deletions .github/actions/get-release-tag/action.yml
Original file line number Diff line number Diff line change
@@ -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
40 changes: 12 additions & 28 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit ef26dcf

Please sign in to comment.