Skip to content

Commit

Permalink
CI: create new tag based on semver
Browse files Browse the repository at this point in the history
  • Loading branch information
dex4er committed Jan 20, 2025
1 parent 690766e commit 4db6ae1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
53 changes: 53 additions & 0 deletions .github/workflows/tag-semver.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Tag semver

on:
workflow_dispatch:
inputs:
newversion:
description: New version (major | minor | patch | premajor | preminor | prepatch | prerelease)
required: true
default: patch

permissions:
contents: write
pull-requests: write

jobs:
tag-semver:
name: tag semver

runs-on: ubuntu-24.04
environment: automated

steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ secrets.GH_TOKEN }}

- name: Increment semver
id: semver
run: |
echo "version=v$(npx semver -i "$newversion" $(git describe --tags --abbrev=0))" >> $GITHUB_OUTPUT
env:
newversion: ${{ github.event.inputs.newversion }}

- name: Create tag from the main branch
if: steps.semver.outputs.version != 'v'
uses: actions/github-script@v7
with:
script: |
const mainRef = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'heads/main',
});
const result = await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/v${{ steps.semver.outputs.version }}',
sha: mainRef.data.object.sha,
});
console.log(result);
github-token: ${{ secrets.GH_TOKEN }}
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

[![GitHub](https://img.shields.io/github/v/release/dex4er/tf?display_name=tag&sort=semver)](https://github.com/dex4er/tf)
[![Test](https://github.com/dex4er/tf/actions/workflows/test.yaml/badge.svg?branch=main)](https://github.com/dex4er/tf/actions/workflows/test.yaml)
[![Release](https://github.com/dex4er/tf/actions/workflows/release.yaml/badge.svg?branch=main)](https://github.com/dex4er/tf/actions/workflows/release.yaml)
[![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)
[![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)

Expand Down

0 comments on commit 4db6ae1

Please sign in to comment.