-
Notifications
You must be signed in to change notification settings - Fork 18
202 lines (178 loc) · 7.05 KB
/
Copy pathzip-release.yml
File metadata and controls
202 lines (178 loc) · 7.05 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Zip Release
on:
schedule:
- cron: '0 8 * * 0'
workflow_dispatch:
concurrency:
group: ss_ci-${{ github.ref }}
cancel-in-progress: true
jobs:
release:
name: CI Main
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[noci]')"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Check Changes
id: check_changes
uses: actions/github-script@v7
with:
script: |
if (context.eventName === "workflow_dispatch") {
core.setOutput("should_proceed", "true");
return;
}
const { owner, repo } = context.repo;
const tags = await github.rest.repos.listTags({ owner, repo });
if (tags.data.length === 0) {
core.setOutput("should_proceed", "true");
return;
}
const lastTag = tags.data[0].name;
const compare = await github.rest.repos.compareCommits({
owner,
repo,
base: lastTag,
head: "HEAD"
});
const files = compare.data.files || [];
const luaFiles = files.filter(f => f.filename.endsWith(".lua"));
core.setOutput(
"should_proceed",
luaFiles.length != 0 ? "true" : "false"
);
- name: Increment Tag
id: increment_tag
if: steps.check_changes.outputs.should_proceed == 'true'
uses: actions/github-script@v7
with:
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const tags = await github.rest.repos.listTags({ owner, repo });
let no_prefix;
let new_tag;
let old_tag;
if (tags.data.length === 0) {
new_tag = 'v1.0.0';
no_prefix = '1.0.0';
} else {
const latest = tags.data[0].name.substring(1).split('.').map(Number);
if (latest[1] === 9 && latest[2] === 9) {
latest[0] += 1; latest[1] = 0; latest[2] = 0;
} else if (latest[2] === 9) {
latest[1] += 1; latest[2] = 0;
} else {
latest[2] += 1;
}
no_prefix = latest.join('.');
new_tag = `v${latest.join('.')}`;
old_tag = tags.data[0].name;
}
core.setOutput("version_number", new_tag);
core.setOutput("no_prefix", no_prefix);
core.setOutput("old_tag", old_tag);
- name: Generate Changelog
id: changelog
if: steps.check_changes.outputs.should_proceed == 'true'
uses: actions/github-script@v7
with:
script: |
const { owner, repo } = context.repo;
const lastTag = "${{ steps.increment_tag.outputs.old_tag }}";
const { data: tagRefs } = await github.rest.git.getRef({ owner, repo, ref: `tags/${lastTag}` });
const tagSha = tagRefs.object.sha;
const { data: tagCommit } = await github.rest.repos.getCommit({ owner, repo, ref: tagSha });
const lastTagDate = new Date(tagCommit.commit.committer.date);
const { data: pulls } = await github.rest.pulls.list({
owner, repo, state: "closed", sort: "updated", direction: "asc", per_page: 100
});
let changelog = "";
let breaking = false;
let breakingMsg = ">[!Important]\n>**This is a breaking change**\n>To install this update, please remove the previous version completely and then install the new version.\n\n";
function isBreakingChange(str) { return str.toLowerCase().includes("breaking change"); }
const commitHashes = new Set();
const mergedPRs = pulls.filter(pr => pr.merged_at && new Date(pr.merged_at) > lastTagDate);
if (mergedPRs.length > 0) {
for (const pr of mergedPRs) {
changelog += `### PR #${pr.number}: ${pr.title}\n`;
const body = pr.body;
if (body) {
breaking = breaking || isBreakingChange(body);
changelog += `${body.trim()}\n\n`;
}
const prCommits = await github.paginate(
github.rest.pulls.listCommits,
{
owner,
repo,
pull_number: pr.number,
per_page: 100
}
);
for (const prCommit of prCommits) {
commitHashes.add(prCommit.sha);
}
}
}
const compared = await github.rest.repos.compareCommits({
owner,
repo,
base: lastTag,
head: "main"
});
const commits = compared.data.commits;
for (const commit of commits) {
if (commitHashes.has(commit.sha)) {
continue;
}
const msg = commit.commit.message || "";
const body = commit.commit.body;
const msgLower = msg.toLowerCase();
if (msgLower.startsWith("merge ") || msgLower.startsWith("[noci]"))
continue;
breaking = breaking || isBreakingChange(msg);
changelog += `## ${msg}\n\n`;
if (body) {
breaking = breaking || isBreakingChange(body);
changelog += `${body.trim()}\n\n`;
}
}
if (breaking) {
changelog = `${breakingMsg}${changelog}`
}
core.setOutput("changelog", changelog);
- name: Bump Version
if: steps.check_changes.outputs.should_proceed == 'true'
run: |
sed -i "s|return \".*\"|return \"${{ steps.increment_tag.outputs.no_prefix }}\"|" SSV2/includes/version.lua
sed -i "s|https://img.shields.io/badge/Script%20Version-v[0-9]\+\.[0-9]\+\.[0-9]\+-blue|https://img.shields.io/badge/Script%20Version-${{ steps.increment_tag.outputs.version_number }}-blue|g" README.md
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add SSV2/includes/version.lua README.md
git diff --cached --quiet || git commit -m "[noci] bump version"
git push
- name: Create Archive
if: steps.check_changes.outputs.should_proceed == 'true'
uses: thedoctor0/zip-release@0.7.6
with:
type: 'zip'
path: './SSV2'
filename: 'Samurais_Scripts_${{ steps.increment_tag.outputs.version_number }}.zip'
exclusions: '**/*.json **/*.md **/*.editorconfig **/*.py **/*.txt **/*.ps1 **/*.gitignore'
- name: Upload Release
if: steps.check_changes.outputs.should_proceed == 'true'
uses: softprops/action-gh-release@v2
with:
name: Samurai's Scripts ${{ steps.increment_tag.outputs.version_number }}
tag_name: ${{ steps.increment_tag.outputs.version_number }}
body: |
## Changelog
${{ steps.changelog.outputs.changelog }}
files: |
Samurais_Scripts_${{ steps.increment_tag.outputs.version_number }}.zip