-
Notifications
You must be signed in to change notification settings - Fork 33
90 lines (81 loc) · 3.15 KB
/
release.yml
File metadata and controls
90 lines (81 loc) · 3.15 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
name: Update latest Release
on:
release:
types:
- published
- deleted
- edited
- unpublished
workflow_dispatch:
jobs:
update-latest:
runs-on: ubuntu-latest
steps:
- name: Update or Create latest Release
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const latestTag = 'latest';
async function getLatestReleaseSafe() {
try {
console.log("Fetching the latest release using the API");
const latestResponse = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
});
console.log("Current latest release:", latestResponse.data.tag_name);
return latestResponse.data;
} catch (error) {
if (error.status === 404) {
console.log("No published (non-prerelease) release found.");
return null;
}
throw error;
}
}
const currentRelease = await getLatestReleaseSafe();
// 정식 릴리즈가 하나도 없으면 latest 태그를 삭제하거나 그냥 끝낼지 선택
if (!currentRelease) {
console.log("No latest release. Trying to delete 'latest' tag if exists.");
try {
await github.rest.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${latestTag}`,
});
console.log("Deleted 'latest' tag because there is no published release.");
} catch (error) {
console.log("No 'latest' tag to delete or failed to delete:", error.message);
}
return;
}
const releaseTagName = currentRelease.tag_name;
console.log(`Fetching commit SHA for release tag: ${releaseTagName}`);
const tagRef = await github.rest.git.getRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${releaseTagName}`,
});
const currentSha = tagRef.data.object.sha;
console.log(`Found commit SHA for latest release: ${currentSha}`);
// latest 태그를 업데이트 또는 생성
try {
await github.rest.git.updateRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `tags/${latestTag}`,
sha: currentSha,
force: true,
});
console.log('Updated tag latest');
} catch (error) {
console.log("Failed to update 'latest', will try to create. Reason:", error.message);
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `refs/tags/${latestTag}`,
sha: currentSha,
});
console.log('Created tag latest');
}