Skip to content

Commit 1107d98

Browse files
committed
CI: create new tag based on semver
1 parent 690766e commit 1107d98

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

.github/workflows/tag-semver.yaml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
name: Tag semver
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
newversion:
7+
description: New version (major | minor | patch | premajor | preminor | prepatch | prerelease)
8+
required: true
9+
default: patch
10+
11+
permissions:
12+
contents: write
13+
pull-requests: write
14+
15+
jobs:
16+
tag-semver:
17+
name: tag semver
18+
19+
runs-on: ubuntu-24.04
20+
environment: automated
21+
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
token: ${{ secrets.GH_TOKEN }}
28+
29+
- name: Increment semver
30+
id: semver
31+
run: |
32+
echo "version=$(npx semver -i "$newversion" $(git describe --tags --abbrev=0))" >> $GITHUB_OUTPUT
33+
env:
34+
newversion: ${{ github.event.inputs.newversion }}
35+
36+
- name: Create tag from the main branch
37+
if: steps.semver.outputs.version
38+
uses: actions/github-script@v7
39+
with:
40+
script: |
41+
const mainRef = await github.rest.git.getRef({
42+
owner: context.repo.owner,
43+
repo: context.repo.repo,
44+
ref: 'heads/main',
45+
});
46+
const result = await github.rest.git.createRef({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
ref: 'refs/tags/v${{ steps.semver.outputs.version }}',
50+
sha: mainRef.data.object.sha,
51+
});
52+
console.log(result);
53+
github-token: ${{ secrets.GH_TOKEN }}

README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
[![GitHub](https://img.shields.io/github/v/release/dex4er/tf?display_name=tag&sort=semver)](https://github.com/dex4er/tf)
44
[![Test](https://github.com/dex4er/tf/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/dex4er/tf/actions/workflows/test.yaml)
5-
[![Release](https://github.com/dex4er/tf/actions/workflows/release.yaml/badge.svg?branch=main)](https://github.com/dex4er/tf/actions/workflows/release.yaml)
65
[![Trunk Check](https://github.com/dex4er/tf/actions/workflows/trunk-check.yaml/badge.svg?branch=main)](https://github.com/dex4er/tf/actions/workflows/trunk-check.yaml)
76
[![OSV Scanner](https://github.com/dex4er/tf/actions/workflows/osv-scanner.yaml/badge.svg?branch=main)](https://github.com/dex4er/tf/actions/workflows/osv-scanner.yaml)
87

0 commit comments

Comments
 (0)