From 3cb58e1aa738d82d7dc02aa2fa183be775d75527 Mon Sep 17 00:00:00 2001 From: extremeheat Date: Sat, 6 Sep 2025 21:16:35 +0000 Subject: [PATCH] workflows: add ghcp setup --- .github/commands/send.js | 2 +- .github/commands/setupCopilot.js | 91 +++++++++++++++++++++++ .github/workflows/copilot-setup-steps.yml | 37 +++++++++ package.json | 2 +- 4 files changed, 130 insertions(+), 2 deletions(-) create mode 100644 .github/commands/setupCopilot.js create mode 100644 .github/workflows/copilot-setup-steps.yml diff --git a/.github/commands/send.js b/.github/commands/send.js index 97aa08b..3ab851e 100644 --- a/.github/commands/send.js +++ b/.github/commands/send.js @@ -9,7 +9,7 @@ module.exports = async ([mergedArtifactURL], helpers) => { branch: 'main', inputs: { versions: JSON.stringify(require('../../versions.json')), - mergedArtifactURL: mergedArtifactURL, + mergedArtifactURL, prNumber: process.env.PR_NUMBER } } diff --git a/.github/commands/setupCopilot.js b/.github/commands/setupCopilot.js new file mode 100644 index 0000000..7d248c9 --- /dev/null +++ b/.github/commands/setupCopilot.js @@ -0,0 +1,91 @@ +/** + * setupCopilot.js + * + * Reads versions from: + * - versions.json at repo root (if present), else + * - directories under mc/ + * + * For each version it runs: + * ./gradlew :mc::runServer --stacktrace + * + * Uses child_process.execSync(cmd, { stdio: 'inherit' }) so logs stream to the action console. + * Errors are caught, logged, and the loop continues. At the end the script writes + * success_versions and failed_versions to $GITHUB_OUTPUT (if available) for downstream steps. + * + * To force the action to fail if any version errors, set env FAIL_ON_ERROR=true in the workflow. + */ + +const cp = require('child_process') +const fs = require('fs') +const { join } = require('path') + +const failOnError = process.env.FAIL_ON_ERROR === 'true' + +// Save some time by skipping old versions as we are not parallelizing builds +const versions = require('../../versions.json') +const SKIP_VERSIONS = versions.slice(0, versions.indexOf('1.21.3')) + +async function main () { + + if (!Array.isArray(versions) || versions.length === 0) { + console.error('No versions found (no VERSION env, no versions.json, no mc/* directories).') + process.exit(1) + } + + console.log('Versions to build:', versions.join(', ')) + + process.chdir(join(__dirname, '../../')) + + const successes = [] + const failures = [] + + for (const v of versions) { + if (SKIP_VERSIONS.includes(v)) { + console.log(`Skipping old version ${v}...`) + continue + } + console.log('') + console.log('=== Building version:', v, '===') + const cmd = `./gradlew :mc:${v}:runServer --stacktrace` + try { + // stream output to the runner logs + cp.execSync(cmd, { stdio: 'inherit' }) + successes.push(v) + console.log(`✅ ${v} succeeded`) + } catch (err) { + failures.push(v) + console.error(`❌ ${v} failed (continuing to next version)`) + // continue to next version + } + } + + // Write outputs for downstream jobs, if GITHUB_OUTPUT available + const ghOut = process.env.GITHUB_OUTPUT + if (ghOut) { + try { + fs.appendFileSync(ghOut, `success_versions=${JSON.stringify(successes)}\n`) + fs.appendFileSync(ghOut, `failed_versions=${JSON.stringify(failures)}\n`) + } catch (e) { + console.warn('Could not write to GITHUB_OUTPUT:', e && e.message) + } + } else { + console.log('GITHUB_OUTPUT not found; printing summaries to stdout instead.') + console.log('success_versions=', JSON.stringify(successes)) + console.log('failed_versions=', JSON.stringify(failures)) + } + + console.log('') + console.log('Summary:') + console.log(' succeeded:', JSON.stringify(successes)) + console.log(' failed: ', JSON.stringify(failures)) + + if (failOnError && failures.length > 0) { + console.error('FAIL_ON_ERROR is true and some builds failed — exiting with non-zero code.') + process.exit(1) + } + + // otherwise exit 0 so the workflow continues (Copilot can triage failures) + process.exit(0) +} + +main() diff --git a/.github/workflows/copilot-setup-steps.yml b/.github/workflows/copilot-setup-steps.yml new file mode 100644 index 0000000..da96427 --- /dev/null +++ b/.github/workflows/copilot-setup-steps.yml @@ -0,0 +1,37 @@ +# https://docs.github.com/en/copilot/how-tos/use-copilot-agents/coding-agent/customize-the-agent-environment +on: + workflow_dispatch: + push: + paths: + - .github/workflows/copilot-setup-steps.yml + pull_request: + paths: + - .github/workflows/copilot-setup-steps.yml + +jobs: + copilot-setup-steps: + name: Build and generate data (single-step loop via Node) + runs-on: ubuntu-latest + timeout-minutes: 20 + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Validate Gradle wrapper + uses: gradle/actions/wrapper-validation@v4 + + - name: Set up JDK 21 + uses: actions/setup-java@v4 + with: + java-version: '21' + distribution: 'temurin' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + with: + add-job-summary-as-pr-comment: on-failure + + - name: Run Copilot setup script + run: node .github/commands/setupCopilot.js + shell: bash \ No newline at end of file diff --git a/package.json b/package.json index 553588a..7fb1c31 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "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.", "main": "index.js", "scripts": { - "fix": "standard --fix", + "fix": "standard --fix .github tools", "bump": "node tools/newVersion.js" }, "author": "",