Merge pull request #7 from Mikael-RnD/ci/commitsar #1
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: Tag and Release | |
on: | |
push: | |
branches: main | |
jobs: | |
# Set a version tag on the repo, also used for naming the machine image to use. | |
tag: | |
runs-on: ubuntu-latest | |
outputs: | |
new_version: ${{ steps.bump_tag.outputs.new_version }} | |
new_tag: ${{ steps.bump_tag.outputs.new_tag }} | |
changelog: ${{ steps.bump_tag.changelog }} | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: '0' | |
- run: echo Triggered by ${{ github.event_name }} event | |
- id: bump_tag | |
uses: mathieudutour/github-tag-action@v6.1 | |
with: | |
github_token: ${{ secrets.GITHUB_TOKEN }} | |
release_branches: main | |
- name: Create a GitHub release | |
uses: ncipollo/release-action@v1 | |
with: | |
tag: ${{ steps.bump_tag.outputs.new_tag }} | |
name: Release ${{ steps.bump_tag.outputs.new_tag }} | |
body: ${{ steps.bump_tag.outputs.changelog }} | |
- name: Create floating tag | |
uses: 'actions/github-script@v6' | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: |- | |
const sha = process.env.GITHUB_SHA; | |
const new_tag = '${{ steps.bump_tag.outputs.new_tag }}'; | |
const major = new_tag.split(".")[0]; | |
// If exists then update, else create | |
try { | |
await github.rest.git.updateRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: `tags/${major}`, | |
sha: sha, | |
force: true, | |
}); | |
core.info(`Updated ${major} to ${sha}`); | |
} catch(err) { | |
core.info(`Failed to update ${major}: ${err}`); | |
await github.rest.git.createRef({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
ref: `refs/tags/${major}`, | |
sha: sha, | |
}); | |
core.info(`Created ${major} at ${sha}`); | |
} |