-
Notifications
You must be signed in to change notification settings - Fork 678
49 lines (46 loc) · 1.58 KB
/
tag.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
name: Tag on SemVer Commit
on:
push:
branches:
- main
env:
NODE_OPTIONS: --max-old-space-size=8192
jobs:
create_tag:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Use Node.js
uses: actions/setup-node@v4
with:
node-version: 22
- name: Extract SemVer using Node.js
id: extract_semver
run: |
node -e '
const execSync = require("child_process").execSync;
const fs = require("fs");
const commitMessage = execSync("git log -1 --pretty=%B").toString("utf-8");
const semverRegex = /chore: Release (v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-.]+)?)/;
const match = commitMessage.match(semverRegex);
if (match) {
fs.appendFileSync(process.env.GITHUB_ENV, `tag_version=${match[1]}\n`);
} else {
console.log("No SemVer found in commit body.");
process.exit(0);
}
'
- name: Create a new tag
if: ${{ env.tag_version }}
run: |
git tag ${{ env.tag_version }}
git push origin ${{ env.tag_version }}
- name: Trigger Build Workflow
if: ${{ env.tag_version }}
run: |
curl -X POST \
-H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/build.yml/dispatches \
-d '{"ref":"main", "inputs": {"tag_version": "${{ env.tag_version }}"}}'