forked from toko-bifrost/ms-teams-deploy-card
-
Notifications
You must be signed in to change notification settings - Fork 6
87 lines (80 loc) · 2.91 KB
/
publish.yaml
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
name: Publish version
on:
workflow_dispatch:
push:
branches:
- master
paths-ignore:
- '.github/**'
- 'README.md'
- 'package.json'
- 'yarn.lock'
concurrency: publish
jobs:
job:
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4
- name: setup node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- name: Fetch major version
id: version
run: echo "majorMinor=$(jq --raw-output '.version' package.json)" >> $GITHUB_OUTPUT
- name: Tag release
uses: actions/github-script@v7.0.1
with:
script: |
// Parse major and minor version from package.json
const majorMinorVersion = '${{ steps.version.outputs.majorMinor }}';
const majorVersion = 'v' + majorMinorVersion.split('.')[0];
// Fetch latest patch version for the given major and minor version
const response = await github.rest.git.listMatchingRefs({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/v' + majorMinorVersion,
per_page: 100
});
// If we ever reach more than 100 releases for a major version, we will have to add pagination.
const refs = response.data;
// Create a new patch version by either incrementing the last patch version or by starting with .0
let newVersion = `v${majorMinorVersion}.`;
let updateMajorTag;
if (refs.length === 0) {
// Create initial version
newVersion += '0';
updateMajorTag = false;
} else {
// Fetch last version and increment
const currentVersion = refs[refs.length - 1].ref;
const patchVersion = Number(currentVersion.split('.')[2]);
newVersion += (patchVersion + 1);
updateMajorTag = true;
}
// Create the patch tag
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/' + newVersion,
sha: context.sha
});
if (updateMajorTag) {
// Update the major tag to point to the new commit
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'tags/' + majorVersion,
sha: context.sha,
force: true
});
} else {
// Create the major tag
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: 'refs/tags/' + majorVersion,
sha: context.sha
});
}