feat(workflows): add GitHub Action to create release on new tag

This workflow automates the release creation process whenever a new
tag is pushed to the repository. It checks if a release for the tag
already exists and creates one if it doesn't, enhancing the release
management and streamlining the deployment process.
This commit is contained in:
Yidi 2024-09-26 21:09:51 -04:00
parent 68434b76eb
commit 09a39d42a3

43
.github/workflows/release-on-tag.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: Create Release on Tag
on:
push:
tags:
- '*'
jobs:
create_release:
runs-on: ubuntu-latest
steps:
- name: Check if Release Exists
id: check_release
uses: actions/github-script@v7
with:
script: |
try {
const release = await github.rest.repos.getReleaseByTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: context.ref.replace('refs/tags/', ''),
})
core.setOutput('release_exists', 'true')
} catch (error) {
if (error.status === 404) {
core.setOutput('release_exists', 'false')
} else {
throw error
}
}
- name: Create Release
if: steps.check_release.outputs.release_exists == 'false'
uses: actions/create-release@v1
with:
tag_name: ${{ github.ref_name }}
release_name: ${{ github.ref_name }}
body: |
Release ${{ github.ref_name }} of GORM.
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}