Create release tag #12
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Create release tag | |
on: workflow_dispatch | |
permissions: | |
contents: write | |
jobs: | |
tag: | |
name: Create tag | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check out repository code | |
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 | |
- name: Run tests | |
run: | | |
tag=$(bash scripts/generate-release-tag) | |
echo "generated-tag=$tag" >> $GITHUB_OUTPUT | |
id: generate_tag | |
- uses: actions/github-script@d7906e4ad0b1822421a7e6a35d5ca353c962f410 # v6.4.1 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const tag = '${{ steps.generate_tag.outputs.generated-tag }}' | |
const branch = '${{ github.ref_name }}' | |
try { | |
const resp = await github.rest.git.getRef({...context.repo, ref: `tags/${tag}`}); | |
return core.setFailed(`the tag ${tag} already exists on ${resp.data.object.type} ${resp.data.object.sha}`); | |
} catch(err) { | |
if(err.status !== 404){ | |
throw err; | |
} | |
} | |
github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: `refs/tags/${tag}`, | |
sha: context.sha | |
}) |