ci: auto tag

This commit is contained in:
octopus_yan 2024-09-18 05:11:50 +08:00
parent cecfda1171
commit 1d77473c5c

73
.github/workflows/auto-tag.yml vendored Normal file
View File

@ -0,0 +1,73 @@
name: auto-tag
on:
workflow_dispatch:
inputs:
release_body:
description: "Release note"
type: string
required: false
ref:
description: "Commit to build (git checkout)"
type: string
required: false
jobs:
auto-tag:
runs-on: windows-latest
strategy:
matrix:
include:
- msbuild_target: x64
lowercase_target: x64
fail-fast: false
outputs:
tag: ${{ steps.set_tag.outputs.tag }}
pre_version: ${{ steps.set_tag.outputs.pre_version }}
main_tag_name: ${{ steps.push_main_tag.outputs.main_tag_name }}
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Install semver
run: |
npm install --global --progress semver
- name: Set tag
id: set_tag
run: |
# pre_version是上一个公版这里需要拉上一个tag避免堆积过多commit
$latest_tag=$(git describe --tags --abbrev=0)
echo "latest_tag=$latest_tag" >> $env:GITHUB_OUTPUT
$described = $(git describe --tags --long --match 'v*')
$ids = $($described -split "-")
if ($ids.length -eq 3) {
$ver = "v$(semver --increment $ids[0].Substring(1))"
$pre_version = "$($ids[0])"
$dist = `printf "%03d"` $ids[1]
echo "tag=$ver-alpha.1.d$($dist).$($ids[2])" >> $env:GITHUB_OUTPUT
echo "pre_version=$pre_version" >> $env:GITHUB_OUTPUT
exit 0
}
if ($ids.length -eq 4) {
$dist = `printf "%03d"` $ids[2]
$pre_version = "$($ids[0])-$($ids[1])"
echo "pre_version=$pre_version" >> $env:GITHUB_OUTPUT
echo "tag=$pre_version.d$($dist).$($ids[3])" >> $env:GITHUB_OUTPUT
exit 0
}
exit 1
- name: Push tag to main repo
id: push_main_tag
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
$main_tag_name=$(echo "alpha/${{ steps.set_tag.outputs.tag }}")
git tag $main_tag_name -f
git push --tags origin HEAD:refs/tags/$main_tag_name -f
echo "main_tag_name=$main_tag_name" >> $env:GITHUB_OUTPUT