From 0e0c54b272a2e31bd5f5ab34b5e53de42bb8e1a1 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 21 May 2026 19:16:23 +0000 Subject: [PATCH] test: make TestRunEvent integration suite runnable locally (#987) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `TestRunEvent*` integration tests are skipped in CI (`make test` runs `-short`), which hid several breakages that make them fail when run locally: - `runTest` built the runner `Config` without `ContainerMaxLifetime`, so the job container ran `/bin/sleep 0` and exited immediately — every step failed with "container is not running". Set it to 1h. - The root `.gitignore`'s unscoped `.env` and `dist` rules shadowed fixtures under `testdata/`. Anchored `dist` → `/dist` (the goreleaser output) and un-ignored `testdata/secrets/.env`. - Added the missing `testdata/secrets/.env` fixture for `TestRunEventSecrets`. - The `node24` local action referenced a `dist/index.js` bundle that was never committed (and was gitignored). Made the fixture self-contained (dependency-free ESM, `main: index.js`) so it runs without an `ncc` build. If you'd rather keep the `@actions/core`-based action and commit the built bundle instead, happy to switch. Network-dependent subtests (remote `uses:`/composite actions) are out of scope. --- This PR was written with the help of Claude Opus 4.7 --------- Co-authored-by: Nicolas Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/runner/pulls/987 Reviewed-by: Nicolas Co-authored-by: silverwind Co-committed-by: silverwind --- .gitignore | 3 ++- act/runner/runner_test.go | 2 ++ act/runner/testdata/actions/node24/action.yml | 2 +- act/runner/testdata/actions/node24/index.js | 21 +++++++++++-------- .../testdata/actions/node24/package.json | 20 ++---------------- act/runner/testdata/secrets/.env | 2 ++ 6 files changed, 21 insertions(+), 29 deletions(-) create mode 100644 act/runner/testdata/secrets/.env diff --git a/.gitignore b/.gitignore index b7de5a70..14621da8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ /gitea-runner .env +!/act/runner/testdata/secrets/.env .runner coverage.txt /config.yaml @@ -10,4 +11,4 @@ coverage.txt .vscode __debug_bin # gorelease binary folder -dist +/dist diff --git a/act/runner/runner_test.go b/act/runner/runner_test.go index b61a16cb..53cac993 100644 --- a/act/runner/runner_test.go +++ b/act/runner/runner_test.go @@ -15,6 +15,7 @@ import ( "runtime" "strings" "testing" + "time" "gitea.com/gitea/runner/act/common" "gitea.com/gitea/runner/act/model" @@ -192,6 +193,7 @@ func (j *TestJobFileInfo) runTest(ctx context.Context, t *testing.T, cfg *Config Inputs: cfg.Inputs, GitHubInstance: "github.com", ContainerArchitecture: cfg.ContainerArchitecture, + ContainerMaxLifetime: time.Hour, Matrix: cfg.Matrix, ActionCache: cfg.ActionCache, } diff --git a/act/runner/testdata/actions/node24/action.yml b/act/runner/testdata/actions/node24/action.yml index 522b1faf..68e88844 100644 --- a/act/runner/testdata/actions/node24/action.yml +++ b/act/runner/testdata/actions/node24/action.yml @@ -10,4 +10,4 @@ outputs: description: 'The time we greeted you' runs: using: 'node24' - main: 'dist/index.js' + main: 'index.js' diff --git a/act/runner/testdata/actions/node24/index.js b/act/runner/testdata/actions/node24/index.js index 5aa4a837..730fa993 100644 --- a/act/runner/testdata/actions/node24/index.js +++ b/act/runner/testdata/actions/node24/index.js @@ -1,11 +1,14 @@ -import {getInput, setOutput, setFailed} from '@actions/core'; -import {context} from '@actions/github'; +import {appendFileSync, readFileSync} from 'node:fs'; -try { - const nameToGreet = getInput('who-to-greet'); - console.log(`Hello ${nameToGreet}!`); - setOutput('time', (new Date()).toTimeString()); - console.log(`The event payload: ${JSON.stringify(context.payload, undefined, 2)}`); -} catch (error) { - setFailed(error.message); +const nameToGreet = process.env['INPUT_WHO-TO-GREET'] || 'World'; +console.log(`Hello ${nameToGreet}!`); + +if (process.env.GITHUB_OUTPUT) { + appendFileSync(process.env.GITHUB_OUTPUT, `time=${new Date().toTimeString()}\n`); } + +let payload = {}; +if (process.env.GITHUB_EVENT_PATH) { + payload = JSON.parse(readFileSync(process.env.GITHUB_EVENT_PATH, 'utf8')); +} +console.log(`The event payload: ${JSON.stringify(payload, undefined, 2)}`); diff --git a/act/runner/testdata/actions/node24/package.json b/act/runner/testdata/actions/node24/package.json index 8603ec31..3dbda4aa 100644 --- a/act/runner/testdata/actions/node24/package.json +++ b/act/runner/testdata/actions/node24/package.json @@ -1,21 +1,5 @@ { "name": "node24", - "version": "1.0.0", - "description": "", - "main": "index.js", - "type": "module", - "scripts": { - "build": "ncc build index.js" - }, - "license": "ISC", - "dependencies": { - "@actions/core": "^3.0.1", - "@actions/github": "^9.1.1" - }, - "devDependencies": { - "@vercel/ncc": "^0.38.4" - }, - "engines": { - "node": ">=24" - } + "private": true, + "type": "module" } diff --git a/act/runner/testdata/secrets/.env b/act/runner/testdata/secrets/.env new file mode 100644 index 00000000..3b66cf2a --- /dev/null +++ b/act/runner/testdata/secrets/.env @@ -0,0 +1,2 @@ +HELLO=WORLD +MULTILINE_ENV="foo\nbar\nbaz"