enhance: align job execution closer to GitHub Actions (#1421)

Closes many small gaps between how workflows run on GitHub and on the runner, each checked against GitHub's runner and live runs.

- `action.yml` expressions are checked against the contexts GitHub allows per field, and input defaults are evaluated with those contexts only
- Reusable workflows take inputs from `workflow_call` only, evaluate outputs once after all called jobs finish, stop at 10 nested workflows and resolve relative `./` paths in remote workflows against that workflow's repository
- A called job failing under `continue-on-error` no longer fails the caller, and same-repository calls use their own clone cache
- Job timeouts cancel the job with GitHub's message, step timeouts fail the step with GitHub's message, and invalid `timeout-minutes` values behave like on GitHub
- `runner.timeout` expiry names the setting and server cancellation is logged
- Matrix and strategy evaluation errors fail the job
- `exec` records skipped jobs and sets `github.run_attempt`, `workflow_ref` and `workflow_sha`
- `runs-on` expressions keep their types
- Step summaries upload as each step ends
- Docker actions join the job network, and the job container no longer gets a network alias from the job name
- Container, network and volume names are unique per job invocation
- Cached images are matched against the daemon's platform and Dockerfile actions build for the requested platform
- `runner.arch` maps 32-bit ARM and x86 names like GitHub
- Pinned action SHAs are verified and git replace objects are ignored
- `hashFiles` uses GitHub's current bundle
- Registration trims labels and writes `.runner` as `0600`
- The container entrypoint quotes its arguments and reads the registration token from the environment or a file
- The systemd example uses `KillMode=mixed` so running jobs can finish on stop
- The cache server releases its database between eviction batches
- Shared rules come from actionslib v1.7.0, added in https://gitea.com/gitea/actionslib/pulls/34

_Written by Claude (Opus 5.5)._

Reviewed-on: https://gitea.com/gitea/runner/pulls/1421
Reviewed-by: bircni <bircni@icloud.com>
Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
silverwind
2026-11-22 10:11:23 +00:00
committed by bircni
parent ff4f626871
commit e71a5028b0
59 changed files with 2783 additions and 3388 deletions

View File

@@ -1,53 +1,26 @@
#!/usr/bin/env bash
if [[ ! -d /data ]]; then
mkdir -p /data
fi
mkdir -p /data
cd /data || exit 1
cd /data
CONFIG_ARG=""
if [[ ! -z "${CONFIG_FILE}" ]]; then
CONFIG_ARG="--config ${CONFIG_FILE}"
fi
RUNNER_STATE_FILE=${RUNNER_STATE_FILE:-$(gitea-runner ${CONFIG_ARG} config runner-file)}
LABEL_ARGS=""
if [[ ! -z "${GITEA_RUNNER_LABELS}" ]]; then
LABEL_ARGS="--labels ${GITEA_RUNNER_LABELS}"
fi
EXTRA_ARGS="${LABEL_ARGS}"
if [[ ! -z "${GITEA_RUNNER_EPHEMERAL}" ]]; then
EXTRA_ARGS="${EXTRA_ARGS} --ephemeral"
fi
# Also pass the labels to the daemon, so that an already registered runner
# picks up changes to GITEA_RUNNER_LABELS instead of keeping the labels it
# was first registered with.
RUN_ARGS="${LABEL_ARGS}"
if [[ ! -z "${GITEA_RUNNER_ONCE}" ]]; then
RUN_ARGS="${RUN_ARGS} --once"
fi
# In case no token is set, it's possible to read the token from a file, i.e. a Docker Secret
if [[ -z "${GITEA_RUNNER_REGISTRATION_TOKEN}" ]] && [[ -f "${GITEA_RUNNER_REGISTRATION_TOKEN_FILE}" ]]; then
GITEA_RUNNER_REGISTRATION_TOKEN=$(cat "${GITEA_RUNNER_REGISTRATION_TOKEN_FILE}")
fi
runner_args=(--config "$CONFIG_FILE")
RUNNER_STATE_FILE=${RUNNER_STATE_FILE:-$(gitea-runner "${runner_args[@]}" config runner-file)}
# Use the same ENV variable names as https://github.com/vegardit/docker-gitea-act-runner
test -f "$RUNNER_STATE_FILE" || echo "$RUNNER_STATE_FILE is missing or not a regular file"
if [[ ! -s "$RUNNER_STATE_FILE" ]]; then
register_args=("${runner_args[@]}" --instance "$GITEA_INSTANCE_URL" --name "$GITEA_RUNNER_NAME" --labels "$GITEA_RUNNER_LABELS"
--no-interactive ${GITEA_RUNNER_EPHEMERAL:+--ephemeral})
if [[ -z $GITEA_RUNNER_REGISTRATION_TOKEN && -f $GITEA_RUNNER_REGISTRATION_TOKEN_FILE ]]; then
register_args+=(--token-file "$GITEA_RUNNER_REGISTRATION_TOKEN_FILE")
fi
for ((try = 1; ; try++)); do # waits for Gitea like the daemon does, a container may have no restart policy
gitea-runner register \
--instance "${GITEA_INSTANCE_URL}" \
--token "${GITEA_RUNNER_REGISTRATION_TOKEN}" \
--name "${GITEA_RUNNER_NAME:-`hostname`}" \
${CONFIG_ARG} ${EXTRA_ARGS} --no-interactive 2>&1 | tee /tmp/reg.log
if grep -q 'Runner registered successfully' /tmp/reg.log; then
if gitea-runner register "${register_args[@]}" 2>&1; then
echo "SUCCESS"
break
fi
if [[ ${GITEA_MAX_REG_ATTEMPTS:-0} -gt 0 ]] && [[ $try -ge $GITEA_MAX_REG_ATTEMPTS ]]; then
if [[ ${GITEA_MAX_REG_ATTEMPTS:-0} -gt 0 && $try -ge $GITEA_MAX_REG_ATTEMPTS ]]; then
echo "Registration failed after ${try} attempts"
exit 1
fi
@@ -56,7 +29,6 @@ if [[ ! -s "$RUNNER_STATE_FILE" ]]; then
done
fi
# Prevent reading the token from the gitea-runner process
unset GITEA_RUNNER_REGISTRATION_TOKEN
unset GITEA_RUNNER_REGISTRATION_TOKEN_FILE
unset GITEA_RUNNER_REGISTRATION_TOKEN GITEA_RUNNER_REGISTRATION_TOKEN_FILE
exec gitea-runner daemon ${CONFIG_ARG} ${RUN_ARGS}
exec gitea-runner daemon "${runner_args[@]}" ${GITEA_RUNNER_ONCE:+--once}