Skip to content

Push [main] -> Tag

Push [main] -> Tag #4

name: Push -> Tag
run-name: Push [${{ github.ref_name }}] -> Tag
on:
push:
branches:
- main
concurrency:
group: Versioning-${{ github.ref_name }}
cancel-in-progress: false
env:
PROJECT_DIR_PATH: TJC.StringExtensions
jobs:
incrementPatch:
name: Push [${{ github.event.head_commit.message }}]
permissions: write-all
runs-on: windows-2022
outputs:
VersionNumber: ${{ steps.incrementVersion.outputs.result }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
token: ${{ secrets.TJC_TOKEN || secrets.GITHUB_TOKEN }}
fetch-depth: 0
- name: Check for Changes to See if Tagging can be Skipped
id: getChanges
uses: tj-actions/[email protected]
with:
files: ${{ env.PROJECT_DIR_PATH }}/**
- name: Get Last Version
id: getLastVersion
if: ${{ steps.getChanges.outputs.any_modified != 'false' }}
uses: actions/[email protected]
with:
result-encoding: string
script: |
try {
var latestTag = require("child_process").execSync("git describe --tags").toString().trim()
console.log('Latest Tag:', latestTag)
return latestTag
} catch {
return ""
}
- name: Get Next Version [${{ steps.getLastVersion.outputs.result }}]
id: getNextVersion
if: ${{ steps.getChanges.outputs.any_modified != 'false' }}
uses: actions/[email protected]
with:
result-encoding: string
script: |
var latestTag = "${{ steps.getLastVersion.outputs.result }}"
if (latestTag == "")
return "v0.1.0"
var ver = latestTag.replace("v","").split("-")[0]
console.log('Last Version:', "v" + ver)
var major = ver.split(".")[0]
var minor = ver.split(".")[1]
var patch = parseInt(ver.split(".")[2]) + 1
var next = "v" + major + "." + minor + "." + patch
console.log('Next Version:', next)
return next
- name: Tag Version [${{ steps.getNextVersion.outputs.result }}]
if: ${{ steps.getChanges.outputs.any_modified != 'false' }}
run: |
git tag ${{ steps.getNextVersion.outputs.result }}
git push origin tag ${{ steps.getNextVersion.outputs.result }}
- name: ${{ (steps.getChanges.outputs.any_modified == 'false') && 'Skipped Incrementing Version' || format('Incremented Version [{0}]', steps.getNextVersion.outputs.result) }}
if: success()
uses: ./.github/actions/tools/annotation/notice
with:
message: ${{ (steps.getChanges.outputs.any_modified == 'false') && 'Skipped Incrementing Version' || format('Incremented Version [{0}]', steps.getNextVersion.outputs.result) }}