Skip to content

Commit 6284eeb

Browse files
committed
convert to js fetching & test builds from all velocity versions
1 parent 933a9ea commit 6284eeb

2 files changed

Lines changed: 65 additions & 57 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
const core = require('@actions/core');
2+
const fs = require('fs');
3+
const util = require('util');
4+
5+
const readFile = util.promisify(fs.readFile);
6+
const writeFile = util.promisify(fs.writeFile);
7+
8+
const versionsUrl = `https://fill.papermc.io/v3/projects/velocity/versions`;
9+
core.startGroup(`Fetching versions from ${versionsUrl}`);
10+
11+
const versionsRes = await fetch(versionsUrl);
12+
const versionsJson = await versionsRes.json();
13+
const versions = versionsJson['versions']
14+
.filter(v => v.version.support.status === 'SUPPORTED')
15+
.map(v => v.version.id)
16+
17+
const versionBuilds = await Promise.all(versions.map(async version => {
18+
const buildsUrl = `https://fill.papermc.io/v3/projects/velocity/versions/${version}/builds`;
19+
core.info(`Fetching builds from ${buildsUrl}`);
20+
21+
const buildsRes = await fetch(buildsUrl);
22+
const buildsJson = await buildsRes.json();
23+
return buildsJson
24+
.filter(v => v.channel === 'STABLE')
25+
.map(v => {
26+
return {
27+
id: v.id,
28+
version: version,
29+
url: v.downloads['server:default'].url,
30+
};
31+
});
32+
}))
33+
const builds = versionBuilds.flatMap(v => v);
34+
core.endGroup();
35+
36+
const lastPath = '.last_builds';
37+
let lastSet = new Set();
38+
if (existsSync(lastPath)) {
39+
const lines = await readFile(lastPath, 'utf-8')
40+
.then(v => v.split('\n').map(s => s.trim()));
41+
lines.forEach(lastSet.add);
42+
}
43+
44+
const newBuilds = builds.filter(v => !lastSet.add(v.id));
45+
46+
if (newBuilds.length === 0) {
47+
core.info('No new builds found.');
48+
core.setOutput('matrix', '[]');
49+
return;
50+
}
51+
52+
core.startGroup(`Detected ${newBuilds.length} new build(s).`);
53+
newBuilds.forEach(v => core.info(JSON.stringify(v)));
54+
core.endGroup();
55+
56+
const updated = Array.from(lastSet).sort();
57+
await writeFile(lastPath, updated.join('\n') + '\n');
58+
59+
core.setOutput('matrix', JSON.stringify(newBuilds));

.github/workflows/testing.yml

Lines changed: 6 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -41,62 +41,11 @@ jobs:
4141
ref: build-state
4242
fetch-depth: 0
4343

44-
- name: Fetch new builds
45-
id: fetch
46-
run: |
47-
set -euo pipefail
48-
echo "Fetching builds from PaperMC API..."
49-
if ! curl -fsSL "https://fill.papermc.io/v3/projects/velocity/versions/${{ vars.PAPERMC_VELOCITY_VERSION }}/builds" -o builds.json; then
50-
echo "::error::Failed to fetch builds.json from PaperMC API."
51-
exit 1
52-
fi
53-
if ! jq empty builds.json 2>/dev/null; then
54-
echo "::error::Invalid JSON received from API."
55-
cat builds.json
56-
exit 1
57-
fi
58-
echo "Builds successfully fetched."
59-
- name: Determine new builds
44+
- name: Fetch builds to matrix
6045
id: set-matrix
61-
run: |
62-
set -euo pipefail
63-
64-
if [ ! -f builds.json ]; then
65-
echo "::error::Missing builds.json file. Previous step may have failed."
66-
exit 1
67-
fi
68-
69-
echo "Extracting build IDs and download URLs..."
70-
jq -c '.[] | {id: .id, url: .downloads["server:default"].url}' builds.json > all_builds.txt
71-
72-
touch .last_builds
73-
sort -u .last_builds -o .last_builds || true
74-
75-
NEW_BUILDS_FILE=new_builds.txt
76-
> "$NEW_BUILDS_FILE"
77-
while read line; do
78-
ID=$(echo "$line" | jq -r '.id')
79-
if ! grep -qx "$ID" .last_builds; then
80-
echo "$line" >> "$NEW_BUILDS_FILE"
81-
fi
82-
done < all_builds.txt
83-
84-
if [ ! -s "$NEW_BUILDS_FILE" ]; then
85-
echo "No new builds found."
86-
echo "matrix=[]" >> "$GITHUB_OUTPUT"
87-
exit 0
88-
fi
89-
90-
echo "New builds detected:"
91-
cat "$NEW_BUILDS_FILE"
92-
93-
MATRIX_JSON=$(jq -c -s '.' "$NEW_BUILDS_FILE")
94-
echo "matrix=$MATRIX_JSON" >> "$GITHUB_OUTPUT"
95-
96-
while read line; do
97-
echo "$line" | jq -r '.id' >> .last_builds
98-
done < "$NEW_BUILDS_FILE"
99-
sort -u .last_builds -o .last_builds
46+
uses: actions/github-script@v8
47+
with:
48+
script: await require('.github/workflows/scripts/fetch-builds.js')();
10049

10150
- name: Commit updated .last_builds
10251
if: steps.set-matrix.outputs.matrix != '[]'
@@ -216,7 +165,7 @@ jobs:
216165
FIRST_LINE=$(timeout "$RCON_TIMEOUT" ./tools/rcon-cli --host 127.0.0.1 --port 25575 --password PASSWORD velocity info | tee rcon.log | head -n 1)
217166
FIRST_LINE=$(echo "$FIRST_LINE" | sed -r 's/\x1B\[[0-9;]*[mK]//g' | tr -d '\r' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
218167
219-
VERSION="${{ vars.PAPERMC_VELOCITY_VERSION }}"
168+
VERSION="${{ matrix.version }}"
220169
BUILD="${{ matrix.id }}"
221170
if echo "$FIRST_LINE" | grep -E -q "^Velocity ${VERSION} \(git-[0-9a-fA-F]+-b${BUILD}\)$"; then
222171
echo "RCON test succeeded! First line matches pattern."
@@ -251,7 +200,7 @@ jobs:
251200
# Test failure report
252201
253202
**Velocity Build ID:** ${{ matrix.id }}
254-
**Velocity Version:** ${{ vars.PAPERMC_VELOCITY_VERSION }}
203+
**Velocity Version:** ${{ matrix.version }}
255204
**Velocity Build URL:** [Download Link](${{ matrix.url }})
256205
**Velocircon Release:** ${{ needs.prepare.outputs.latest_release }}
257206

0 commit comments

Comments
 (0)