-
-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (98 loc) · 3.55 KB
/
publish.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
89
90
91
92
93
94
95
96
97
98
99
100
name: Publish GitHub Action
on:
release:
types: [created]
workflow_dispatch:
jobs:
manage-releases:
# Read the semver version from the release tag, get the major version, delete the releases matching major version and the latest tag,create a tag and release for the major version and the latest tag
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Get the version
id: version
run: |
MAJOR_VERSION=$(echo "${GITHUB_REF#refs/*/}" | cut -d'.' -f1)
echo "MAJOR_VERSION=$MAJOR_VERSION" >> $GITHUB_OUTPUT
- name: Delete release
uses: actions/github-script@v7
with:
script: |
const majorVersion = "${{ steps.version.outputs.MAJOR_VERSION }}";
const releases = await github.rest.repos.listReleases({
owner: context.repo.owner,
repo: context.repo.repo
});
const releaseToDelete = releases.data.find(release => release.tag_name.startsWith(`v${majorVersion}.`));
if (releaseToDelete) {
await github.rest.repos.deleteRelease({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseToDelete.id
});
}
- name: Create major tag
uses: actions/github-script@v7
with:
script: |
const tag = 'refs/tags/${{ steps.version.outputs.MAJOR_VERSION }}';
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tag.replace('refs/', '')
});
} catch (error) {}
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tag,
sha: context.sha
});
- name: Create major release
uses: actions/github-script@v7
with:
script: |
const majorVersion = "${{ steps.version.outputs.MAJOR_VERSION }}";
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: `${majorVersion}`,
name: `${majorVersion}`,
body: `Latest ${majorVersion} release. See specific version release notes for details.`,
draft: false,
prerelease: false
});
- name: Create latest tag
uses: actions/github-script@v7
with:
script: |
const tag = 'refs/tags/latest';
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tag.replace('refs/', '')
});
} catch (error) {}
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tag,
sha: context.sha
});
- name: Create latest release
uses: actions/github-script@v7
with:
script: |
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: 'latest',
name: 'latest',
body: 'Latest release. See specific version release notes for details.',
draft: false,
prerelease: false
});