Skip to content

Commit 3cb58e1

Browse files
committed
workflows: add ghcp setup
1 parent 4b9175c commit 3cb58e1

4 files changed

Lines changed: 130 additions & 2 deletions

File tree

.github/commands/send.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = async ([mergedArtifactURL], helpers) => {
99
branch: 'main',
1010
inputs: {
1111
versions: JSON.stringify(require('../../versions.json')),
12-
mergedArtifactURL: mergedArtifactURL,
12+
mergedArtifactURL,
1313
prNumber: process.env.PR_NUMBER
1414
}
1515
}

.github/commands/setupCopilot.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
/**
2+
* setupCopilot.js
3+
*
4+
* Reads versions from:
5+
* - versions.json at repo root (if present), else
6+
* - directories under mc/
7+
*
8+
* For each version it runs:
9+
* ./gradlew :mc:<version>:runServer --stacktrace
10+
*
11+
* Uses child_process.execSync(cmd, { stdio: 'inherit' }) so logs stream to the action console.
12+
* Errors are caught, logged, and the loop continues. At the end the script writes
13+
* success_versions and failed_versions to $GITHUB_OUTPUT (if available) for downstream steps.
14+
*
15+
* To force the action to fail if any version errors, set env FAIL_ON_ERROR=true in the workflow.
16+
*/
17+
18+
const cp = require('child_process')
19+
const fs = require('fs')
20+
const { join } = require('path')
21+
22+
const failOnError = process.env.FAIL_ON_ERROR === 'true'
23+
24+
// Save some time by skipping old versions as we are not parallelizing builds
25+
const versions = require('../../versions.json')
26+
const SKIP_VERSIONS = versions.slice(0, versions.indexOf('1.21.3'))
27+
28+
async function main () {
29+
30+
if (!Array.isArray(versions) || versions.length === 0) {
31+
console.error('No versions found (no VERSION env, no versions.json, no mc/* directories).')
32+
process.exit(1)
33+
}
34+
35+
console.log('Versions to build:', versions.join(', '))
36+
37+
process.chdir(join(__dirname, '../../'))
38+
39+
const successes = []
40+
const failures = []
41+
42+
for (const v of versions) {
43+
if (SKIP_VERSIONS.includes(v)) {
44+
console.log(`Skipping old version ${v}...`)
45+
continue
46+
}
47+
console.log('')
48+
console.log('=== Building version:', v, '===')
49+
const cmd = `./gradlew :mc:${v}:runServer --stacktrace`
50+
try {
51+
// stream output to the runner logs
52+
cp.execSync(cmd, { stdio: 'inherit' })
53+
successes.push(v)
54+
console.log(`✅ ${v} succeeded`)
55+
} catch (err) {
56+
failures.push(v)
57+
console.error(`❌ ${v} failed (continuing to next version)`)
58+
// continue to next version
59+
}
60+
}
61+
62+
// Write outputs for downstream jobs, if GITHUB_OUTPUT available
63+
const ghOut = process.env.GITHUB_OUTPUT
64+
if (ghOut) {
65+
try {
66+
fs.appendFileSync(ghOut, `success_versions=${JSON.stringify(successes)}\n`)
67+
fs.appendFileSync(ghOut, `failed_versions=${JSON.stringify(failures)}\n`)
68+
} catch (e) {
69+
console.warn('Could not write to GITHUB_OUTPUT:', e && e.message)
70+
}
71+
} else {
72+
console.log('GITHUB_OUTPUT not found; printing summaries to stdout instead.')
73+
console.log('success_versions=', JSON.stringify(successes))
74+
console.log('failed_versions=', JSON.stringify(failures))
75+
}
76+
77+
console.log('')
78+
console.log('Summary:')
79+
console.log(' succeeded:', JSON.stringify(successes))
80+
console.log(' failed: ', JSON.stringify(failures))
81+
82+
if (failOnError && failures.length > 0) {
83+
console.error('FAIL_ON_ERROR is true and some builds failed — exiting with non-zero code.')
84+
process.exit(1)
85+
}
86+
87+
// otherwise exit 0 so the workflow continues (Copilot can triage failures)
88+
process.exit(0)
89+
}
90+
91+
main()
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment
2+
on:
3+
workflow_dispatch:
4+
push:
5+
paths:
6+
- .github/workflows/copilot-setup-steps.yml
7+
pull_request:
8+
paths:
9+
- .github/workflows/copilot-setup-steps.yml
10+
11+
jobs:
12+
copilot-setup-steps:
13+
name: Build and generate data (single-step loop via Node)
14+
runs-on: ubuntu-latest
15+
timeout-minutes: 20
16+
17+
steps:
18+
- name: Checkout repository
19+
uses: actions/checkout@v4
20+
21+
- name: Validate Gradle wrapper
22+
uses: gradle/actions/wrapper-validation@v4
23+
24+
- name: Set up JDK 21
25+
uses: actions/setup-java@v4
26+
with:
27+
java-version: '21'
28+
distribution: 'temurin'
29+
30+
- name: Setup Gradle
31+
uses: gradle/actions/setup-gradle@v4
32+
with:
33+
add-job-summary-as-pr-comment: on-failure
34+
35+
- name: Run Copilot setup script
36+
run: node .github/commands/setupCopilot.js
37+
shell: bash

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "This tool generates minecraft-data files based on a running a server on client classpath using a fabric mod. The supported versions can be read in the directory structure. Every version has its own directory.",
55
"main": "index.js",
66
"scripts": {
7-
"fix": "standard --fix",
7+
"fix": "standard --fix .github tools",
88
"bump": "node tools/newVersion.js"
99
},
1010
"author": "",

0 commit comments

Comments
 (0)