-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
88 lines (71 loc) · 2.4 KB
/
action.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
name: autotag
description: 'Automatically create tags in yyyy.mm.dd.n format'
inputs:
dry-run:
description: "Don't create the tag"
default: 'false'
required: false
github-token:
description: "GitHub access token. Use a personal access token to trigger workflow runs from created tags."
default: ${{ github.token }}
required: false
outputs:
tag:
description: "Generated tag name"
value: ${{ fromJson(steps.tag.outputs.result).tag }}
ref:
description: "Generated tag ref"
value: ${{ fromJson(steps.tag.outputs.result).ref }}
sha:
description: "Tagged commit sha"
value: ${{ fromJson(steps.tag.outputs.result).sha }}
json:
description: "All outputs in JSON"
value: ${{ steps.tag.outputs.result }}
runs:
using: composite
steps:
- id: tag
uses: actions/github-script@v7
with:
debug: true
github-token: ${{ inputs.github-token }}
script: |
const today = new Date();
const prefix = [
today.getUTCFullYear().toString(),
(today.getUTCMonth() + 1).toString().padStart(2, '0'),
today.getUTCDate().toString().padStart(2, '0'),
].join('.') + '.';
core.info(`Tag prefix: ${prefix}`);
let lastComponent = 0;
for await (const response of github.paginate.iterator(github.rest.repos.listTags, context.repo)) {
for (const tag of response.data) {
if (!tag.name.startsWith(prefix))
continue;
core.debug(`Found matching tag: ${tag.name}`);
try {
const components = tag.name.split('.', 4);
const n = parseInt(components[3], 10);
if (n >= lastComponent)
lastComponent = n + 1;
} catch (err) {
core.warning(`Can't parse tag ${tag}: ${err}`);
}
}
}
const tag = `${prefix}${lastComponent}`;
const ref = `refs/tags/${tag}`;
const sha = context.sha;
const dryRun = ${{ inputs.dry-run }};
if (dryRun) {
core.info(`Generated tag: ${tag}`);
return { tag, ref, sha };
}
core.info(`Tagging ${sha} as ${ref}`);
await github.rest.git.createRef({
...context.repo,
ref,
sha,
});
return { tag, ref, sha };