Skip to content

Instantly share code, notes, and snippets.

@ranaroussi
Created August 17, 2023 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranaroussi/ed78ee8bf30cb2812704de64b3e48db5 to your computer and use it in GitHub Desktop.
Save ranaroussi/ed78ee8bf30cb2812704de64b3e48db5 to your computer and use it in GitHub Desktop.
GitHub action: Set version => Tag => Create Release (triggered by PR merge)
name: Versioning
permissions: write-all
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the "main" branch
pull_request:
branches:
- main
types:
- closed
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a job called "calculate-version"
create-release:
name: Create a new release
# Condition for the runner
if: github.event.pull_request.merged == true
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0 #.10.2
with:
versionSpec: '5.x'
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Determine Version
id: gitversion
uses: gittools/actions/gitversion/execute@v0 #.10.2
- name: Update version file
run: |
echo "Updating version file to ${{ steps.gitversion.outputs.semVer }}..."
git config user.email "no-reply@github.com"
git config user.name "Release Bot"
echo "${{ steps.gitversion.outputs.semVer }} (${{ steps.gitversion.outputs.ShortSha }})"> .version
git add .version
git commit -m "Updated version file to ${{ steps.gitversion.outputs.semVer }}"
git push origin
- name: Create git tag
run: |
git tag ${{ steps.gitversion.outputs.semVer }}
git push origin ${{ steps.gitversion.outputs.semVer }}
- name: Create Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token
SEMVER: ${{ steps.gitversion.outputs.semVer }}
uses: comnoco/create-release-action@v2
with:
tag_name: ${{ steps.gitversion.outputs.semVer }}
release_name: "v${{ steps.gitversion.outputs.semVer }}"
body: |
Build version: ${{ steps.gitversion.outputs.semVer }}+${{ steps.gitversion.outputs.ShortSha }}
PR #${{ github.event.pull_request.number }}
### Release notes
${{ github.event.pull_request.body }}
draft: false
prerelease: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment