-
Notifications
You must be signed in to change notification settings - Fork 4
70 lines (60 loc) · 2.34 KB
/
tag.yaml
File metadata and controls
70 lines (60 loc) · 2.34 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
---
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
name: Tag
on:
workflow_dispatch:
schedule:
- cron: 0 0 1 * *
permissions:
contents: read
jobs:
main:
name: Tag
runs-on: ubuntu-latest
steps:
- name: Generate Token
uses: actions/create-github-app-token@29824e69f54612133e76f7eaac726eef6c875baf # v2.2.1
id: app-token
with:
app-id: ${{ secrets.BOT_APP_ID }}
private-key: ${{ secrets.BOT_APP_PRIVATE_KEY }}
- name: Get Previous Tag and Determine Next Tag
id: determine-next-tag
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
github-token: ${{ steps.app-token.outputs.token }}
result-encoding: string
script: |-
const { data: tags } = await github.rest.repos.listTags({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 1,
});
const prevTag = tags[0]?.name || "0.0.0"; // Default to "0.0.0" if no tags exist
const [prevMajor, prevMinor, prevPatch] = prevTag.split('.').map(Number);
const now = new Date();
const nextMajorMinor = `${now.getFullYear()}.${now.getMonth() + 1}`; // Months are 0-indexed in JavaScript
const nextPatch = `${prevMajor}.${prevMinor}` === nextMajorMinor ? prevPatch + 1 : 0;
console.log(`Previous tag: ${prevTag}`);
console.log(`Next tag: ${nextMajorMinor}.${nextPatch}`);
return `${nextMajorMinor}.${nextPatch}`;
- name: Create Tag
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
github-token: ${{ steps.app-token.outputs.token }}
script: |-
const tagName = "${{ steps.determine-next-tag.outputs.result }}";
const tag = await github.rest.git.createTag({
owner: context.repo.owner,
repo: context.repo.repo,
tag: tagName,
message: tagName,
object: context.sha,
type: "commit"
});
github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${tagName}`,
sha: tag.data.sha
});