-
-
Notifications
You must be signed in to change notification settings - Fork 7
165 lines (154 loc) · 6.68 KB
/
check-for-updates.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
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
name: Check For New Snapshots
on:
# schedule:
# - cron: "*/30 6-19 * * *"
workflow_dispatch:
concurrency:
group: check-for-updates
permissions:
actions: write
jobs:
check:
env:
LATEST_VERSION: ${{ vars.LATEST_MC_VERSION }}
LATEST_MAINLINE: ${{ vars.LATEST_MAINLINE_VERSION }}
runs-on: ubuntu-latest
if: ${{ vars.LATEST_MC_VERSION != vars.TARGET_MC_VERSION }}
outputs:
is_new: ${{ fromJson(steps.check.outputs.result).is_new }}
old_version: ${{ toJson(fromJson(steps.check.outputs.result).old_version) }}
new_version: ${{ toJson(fromJson(steps.check.outputs.result).new_version) }}
steps:
- name: Get Version Manifest
id: version_manifest
run: echo "latest_snapshot=$(wget -O - https://piston-meta.mojang.com/mc/game/version_manifest_v2.json | jq -r .latest.snapshot)" >> $GITHUB_OUTPUT
- name: Check latest snapshot
id: check
uses: actions/github-script@v7
env:
NEW_LATEST_VERSION: ${{ steps.version_manifest.outputs.latest_snapshot }}
with:
script: |
function getInfo(name) {
var type = "";
var april = false;
if (/^\d+\.\d+(\.\d+)?$/.test(name)) {
type = "release";
} else if (/^\d{2}w\d{2}[a-z]$/.test(name)) {
type = "snapshot";
} else if (/^\d+\.\d+(.\d+)?-(pre|rc)\d+$/.test(name) || /^\d+\.\d+.\d+-rc\d+$/.test(name)) {
type = "pre";
} else {
// If it doesn't match anything guess that it's an april fools release
type = "snapshot";
april = true;
}
return {type: type, april: april, version: name}
}
const latestSnapshot = process.env.NEW_LATEST_VERSION
const newVersionInfo = getInfo(latestSnapshot);
const oldVersion = process.env.LATEST_MAINLINE;
const oldVersionInfo = getInfo(oldVersion);
if (process.env.LATEST_VERSION === latestSnapshot) {
core.info("No new snapshots have been released since " + process.env.LATEST_VERSION)
return {old_version: oldVersionInfo, new_version: newVersionInfo, is_new: false};
}
core.info("Found new snapshot: " + latestSnapshot)
return {old_version: oldVersionInfo, new_version: newVersionInfo, is_new: true};
check-srgutils:
runs-on: ubuntu-latest
needs: check
if: ${{ needs.check.outputs.is_new == 'true' && fromJson(needs.check.outputs.new_version).april }}
steps:
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: ${{ vars.JAVA_VERSION }}
- name: Install fast-xml-parser
run: sudo npm install -g fast-xml-parser
- name: Get latest version of srgutils
id: srgutils_version
run: echo "srgutils_version=$(wget -O - https://maven.neoforged.net/releases/net/neoforged/srgutils/maven-metadata.xml | fxparser -c | jq .metadata.versioning.latest -r)" >> $GITHUB_OUTPUT
- name: Download srgutils
run: wget https://maven.neoforged.net/releases/net/neoforged/srgutils/${{ steps.srgutils_version.outputs.srgutils_version }}/srgutils-${{ steps.srgutils_version.outputs.srgutils_version }}.jar -O srgutils.jar
- name: Download parser
run: wget ${{ vars.PARSE_VERSION_JAVA }}
- name: Run parser
run: java -cp srgutils.jar Main.java ${{ fromJson(needs.check.outputs.new_version).version }}
run-update:
runs-on: ubuntu-latest
needs:
- check
- check-srgutils
if: ${{ always() && !cancelled() && !failure() && needs.check.result == 'success' && needs.check.outputs.is_new == 'true' }}
env:
TARGET_VERSION: ${{ vars.TARGET_MC_VERSION }}
steps:
- name: Run update workflow
id: update
uses: actions/github-script@v7
env:
OLD_VERSION_INFO: ${{ needs.check.outputs.old_version }}
NEW_VERSION_INFO: ${{ needs.check.outputs.new_version }}
with:
script: |
const oldVersionInfo = JSON.parse(process.env.OLD_VERSION_INFO);
const newVersionInfo = JSON.parse(process.env.NEW_VERSION_INFO);
function getVersionPrefix(info) {
if (info.april) {
return "snapshot/april/";
} else if (info.type === "snapshot" || info.type === "pre") {
const targetSplit = process.env.TARGET_VERSION.split(".")
return info.type + "/" + targetSplit[0] + "." + targetSplit[1] + "/";
} else {
return info.type + "/";
}
}
function getBranch(info) {
var release = info.type === "release";
if (release || info.april) {
return "main";
} else {
return process.env.TARGET_VERSION + "-dev";
}
}
var inputs = {}
inputs.old_version = getVersionPrefix(oldVersionInfo) + oldVersionInfo.version;
inputs.new_version = getVersionPrefix(newVersionInfo) + newVersionInfo.version;
inputs.publish = true
var oldBranch = getBranch(oldVersionInfo);
var newBranch = getBranch(newVersionInfo);
if (oldBranch !== newBranch) {
inputs.new_branch = newBranch;
}
core.info("Using inputs:");
for (const key in inputs) {
core.info(key + ": " + inputs[key]);
}
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: context.repo.repo,
workflow_id: "update.yml",
ref: oldBranch,
inputs: inputs
});
- name: Store Latest Version
uses: octokit/[email protected]
with:
route: PATCH /repos/{repo}/actions/variables/{name}
repo: ${{ github.repository }}
name: LATEST_MC_VERSION
value: "\"${{ fromJson(needs.check.outputs.new_version).version }}\""
env:
GITHUB_TOKEN: ${{ secrets.VARIABLES_TOKEN }}
- name: Store Latest Version
if: ${{ !fromJson(needs.check.outputs.new_version).april }}
uses: octokit/[email protected]
with:
route: PATCH /repos/{repo}/actions/variables/{name}
repo: ${{ github.repository }}
name: LATEST_MAINLINE_VERSION
value: "\"${{ fromJson(needs.check.outputs.new_version).version }}\""
env:
GITHUB_TOKEN: ${{ secrets.VARIABLES_TOKEN }}