Files
plex-playlist/.gitea/workflows/cicd-checks.yaml
copilotcoder 48063ac6e4
All checks were successful
CICD Start / Sanity and Base Decision (pull_request) Successful in 24s
fix(ci): install frontend deps before prettier hook
2026-06-17 08:37:14 -04:00

424 lines
16 KiB
YAML

name: CICD Checks
on:
workflow_dispatch:
inputs:
head_sha:
description: Commit SHA to process
required: false
source_workflow:
description: Upstream workflow name
required: false
trace_id:
description: Correlation id propagated across CICD dispatch chain
required: false
env:
GITEA_REGISTRY: kankali.darkhelm.lan:3001
GITEA_REGISTRY_IP: 10.18.75.2
GITEA_REGISTRY_HOST: kankali.darkhelm.lan
concurrency:
group: checks-${{ github.sha }}
cancel-in-progress: true
jobs:
setup:
name: Setup Checks Context
# Use the same stable runner label as the check matrix jobs.
runs-on: ubuntu-act
timeout-minutes: 8
outputs:
head_sha: ${{ steps.meta.outputs.head_sha }}
steps:
- name: Identify runner
run: |
echo "=== Runner Identity ==="
echo "runner_name=${RUNNER_NAME:-}"
echo "runner_name_hint=${GITEA_RUNNER_NAME:-${ACT_RUNNER_NAME:-${RUNNER_NAME:-unknown}}}"
echo "runner_hostname_env=${HOSTNAME:-unknown}"
echo "runner_uname_n=$(uname -n 2>/dev/null || echo unknown)"
echo "runner_etc_hostname=$(cat /etc/hostname 2>/dev/null || echo unknown)"
echo "runner_os=${RUNNER_OS:-unknown}"
echo "runner_arch=${RUNNER_ARCH:-unknown}"
echo "timestamp_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
- name: Audit trigger context
env:
EVENT_NAME: ${{ github.event_name }}
SOURCE_WORKFLOW: ${{ github.event.inputs.source_workflow }}
HEAD_SHA_INPUT: ${{ github.event.inputs.head_sha }}
HEAD_SHA_FALLBACK: ${{ github.sha }}
REF: ${{ github.ref }}
REF_NAME: ${{ github.ref_name }}
HEAD_REF: ${{ github.head_ref }}
TRACE_ID_INPUT: ${{ github.event.inputs.trace_id }}
run: |
RESOLVED_HEAD_SHA="${HEAD_SHA_INPUT:-${HEAD_SHA_FALLBACK}}"
TRACE_ID="${TRACE_ID_INPUT:-cicd-checks-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${RESOLVED_HEAD_SHA:0:8}}"
echo "=== Dispatch Audit: CICD Checks ==="
echo "event_name=${EVENT_NAME}"
echo "source_workflow=${SOURCE_WORKFLOW}"
echo "head_sha_input=${HEAD_SHA_INPUT}"
echo "head_sha=${RESOLVED_HEAD_SHA}"
echo "ref=${REF}"
echo "ref_name=${REF_NAME}"
echo "head_ref=${HEAD_REF}"
echo "trace_id=${TRACE_ID}"
- name: Resolve head SHA
id: meta
env:
HEAD_SHA_INPUT: ${{ github.event.inputs.head_sha }}
HEAD_SHA_FALLBACK: ${{ github.sha }}
run: |
RESOLVED_HEAD_SHA="${HEAD_SHA_INPUT:-${HEAD_SHA_FALLBACK}}"
echo "head_sha=${RESOLVED_HEAD_SHA}" >> "$GITHUB_OUTPUT"
- &failure_diagnostics_step
name: Failure diagnostics
if: failure()
run: |
echo "=== Failure Diagnostics ==="
date -u '+timestamp_utc=%Y-%m-%dT%H:%M:%SZ'
echo "runner_name=${RUNNER_NAME:-unknown}"
echo "runner_hostname=${HOSTNAME:-unknown}"
uname -a || true
cat /etc/os-release 2>/dev/null || true
df -h || true
free -h || true
ps aux --sort=-%mem | head -n 30 || true
if command -v docker >/dev/null 2>&1; then
echo "=== Docker Diagnostics ==="
docker version || true
docker info || true
docker ps -a || true
docker images --digests | head -n 50 || true
else
echo "docker not available on this runner"
fi
echo "=== Kernel Tail ==="
dmesg | tail -n 120 || true
run-check:
name: ${{ matrix.name }}
# Run checks across the full act runner pool for maximum parallelism.
runs-on: ubuntu-act
timeout-minutes: 20
needs: setup
strategy:
fail-fast: false
max-parallel: 6
matrix:
include:
- name: Trailing Whitespace Check
hook: trailing-whitespace
- name: YAML Syntax Check
hook: check-yaml
- name: End of File Check
hook: end-of-file-fixer
- name: TOML Syntax Check
hook: check-toml
- name: Mixed Line Ending Check
hook: mixed-line-ending
- name: TOML Formatting Check
hook: pretty-format-toml
- name: Ruff Linting
hook: ruff
- name: Ruff Format Check
hook: ruff-format
- name: Pyright Type Check
hook: pyright
- name: Pydoclint Docstring Check
hook: pydoclint
- name: No Docstring Types Check
hook: no-docstring-types
- name: ESLint Check
hook: eslint
- name: Prettier Format Check
hook: prettier
- name: TSDoc Lint Check
hook: tsdoc-lint
- name: TypeScript Type Check
hook: typescript-check
steps:
- name: Runner assignment audit
run: |
echo "=== Runner Assignment Audit ==="
echo "runner_name=${RUNNER_NAME:-}"
echo "runner_name_hint=${GITEA_RUNNER_NAME:-${ACT_RUNNER_NAME:-${RUNNER_NAME:-unknown}}}"
echo "runner_hostname_env=${HOSTNAME:-unknown}"
echo "runner_uname_n=$(uname -n 2>/dev/null || echo unknown)"
echo "runner_etc_hostname=$(cat /etc/hostname 2>/dev/null || echo unknown)"
echo "runner_os=${RUNNER_OS:-unknown}"
echo "runner_arch=${RUNNER_ARCH:-unknown}"
echo "timestamp_utc=$(date -u +%Y-%m-%dT%H:%M:%SZ)"
- name: Configure registry host resolution
run: |
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
fi
- name: Ensure CICD image is available
env:
HEAD_SHA: ${{ needs.setup.outputs.head_sha }}
run: |
IMAGE="${GITEA_REGISTRY}/darkhelm.org/plex-playlist-cicd:${HEAD_SHA}"
if docker image inspect "${IMAGE}" >/dev/null 2>&1; then
echo "Using cached CICD image: ${IMAGE}"
else
echo "${{ secrets.PACKAGE_ACCESS_TOKEN }}" | docker login "http://${GITEA_REGISTRY}" -u "${{ github.actor }}" --password-stdin
pulled=false
for i in 1 2 3; do
echo "Pull attempt ${i}/3 for ${IMAGE}"
if docker pull "${IMAGE}"; then
pulled=true
break
fi
if [ "${i}" -lt 3 ]; then
sleep_seconds=$((5 * i))
echo "Pull failed; retrying in ${sleep_seconds}s"
sleep "${sleep_seconds}"
fi
done
if [ "${pulled}" != "true" ]; then
echo "❌ Failed to pull CICD image after 3 attempts: ${IMAGE}"
exit 1
fi
fi
- name: Validate CICD image provenance
env:
HEAD_SHA: ${{ needs.setup.outputs.head_sha }}
run: |
IMAGE="${GITEA_REGISTRY}/darkhelm.org/plex-playlist-cicd:${HEAD_SHA}"
SOURCE_SHA=$(docker run --rm --entrypoint /bin/sh "${IMAGE}" -c 'cat /workspace/.cicd-source-sha 2>/dev/null || true')
echo "requested_head_sha=${HEAD_SHA}"
echo "image=${IMAGE}"
echo "embedded_source_sha=${SOURCE_SHA:-missing}"
if [ -z "${SOURCE_SHA}" ]; then
echo "❌ Missing /workspace/.cicd-source-sha in ${IMAGE}"
exit 1
fi
case "${SOURCE_SHA}" in
${HEAD_SHA}*)
;;
*)
echo "❌ Source SHA mismatch: requested=${HEAD_SHA} actual=${SOURCE_SHA}"
exit 1
;;
esac
- name: Run pre-commit hook
env:
HEAD_SHA: ${{ needs.setup.outputs.head_sha }}
HOOK: ${{ matrix.hook }}
run: |
set -o pipefail
echo "=== Pre-commit Hook Start ==="
echo "hook=${HOOK}"
echo "head_sha=${HEAD_SHA}"
if [ "${HOOK}" = "prettier" ]; then
echo "=== Host Workspace Debug (prettier) ==="
echo "host_head_sha=${HEAD_SHA}"
git rev-parse --short HEAD || true
if [ -d frontend ]; then
(cd frontend && corepack yarn prettier --version && corepack yarn prettier --check src/main.test.ts src/main.ts src/test-setup.ts src/validation.test.ts src/validation.ts) || true
(cd frontend && sha256sum src/main.test.ts src/main.ts src/test-setup.ts src/validation.test.ts src/validation.ts) || true
else
echo "host_frontend_dir_missing=frontend"
fi
fi
LOG_FILE="$(mktemp)"
docker run --rm -e CI=true --entrypoint /bin/sh "${GITEA_REGISTRY}/darkhelm.org/plex-playlist-cicd:${HEAD_SHA}" -c "
export HOME=/tmp/cicd-home && mkdir -p \"$HOME\" &&
echo 'running_hook=${HOOK}' &&
echo 'container_shells=' && ls -l /bin/sh /bin/bash 2>/dev/null || true &&
echo 'tool_paths=' && command -v git /workspace/backend/.venv/bin/pre-commit python3 python 2>/dev/null || true &&
/workspace/backend/.venv/bin/pre-commit --version &&
cd /workspace &&
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo 'No git repository found in /workspace; bootstrapping for pre-commit' &&
git config --global user.email 'ci@cicd' &&
git config --global user.name 'CICD' &&
git init /workspace &&
git -C /workspace config core.autocrlf false &&
git -C /workspace config core.eol lf &&
git -C /workspace add -A
fi &&
case "${HOOK}" in
eslint|prettier|tsdoc-lint|typescript-check)
echo 'JS hook detected; preparing frontend dependencies' &&
if [ ! -d /workspace/frontend ]; then
echo '❌ Missing /workspace/frontend for JS hook execution' &&
exit 1
fi &&
cd /workspace/frontend &&
install_ok=false &&
for i in 1 2 3; do
echo 'yarn install attempt' "\$i"'/3' &&
if timeout 1200 corepack yarn install --immutable --mode=skip-build; then
install_ok=true
break
fi
if [ "\$i" -lt 3 ]; then
echo 'yarn install failed; cleaning and retrying in 20s' &&
rm -rf node_modules .yarn/install-state.gz .yarn/cache &&
corepack yarn cache clean --all 2>/dev/null || true &&
sleep 20
fi
done &&
if [ "\$install_ok" != 'true' ]; then
echo '❌ Unable to prepare frontend dependencies for JS pre-commit hooks' &&
exit 1
fi &&
if [ "${HOOK}" = "prettier" ]; then
echo '=== Container Workspace Debug (prettier) ===' &&
corepack yarn prettier --version || true &&
sha256sum src/main.test.ts src/main.ts src/test-setup.ts src/validation.test.ts src/validation.ts || true &&
corepack yarn prettier --check src/main.test.ts src/main.ts src/test-setup.ts src/validation.test.ts src/validation.ts || true
fi &&
cd /workspace
;;
esac &&
/workspace/backend/.venv/bin/pre-commit run ${HOOK} --all-files --show-diff-on-failure
" 2>&1 | tee "${LOG_FILE}"
HOOK_STATUS=${PIPESTATUS[0]}
if [ "${HOOK_STATUS}" -ne 0 ]; then
echo "❌ Pre-commit hook failed: ${HOOK} (exit=${HOOK_STATUS})"
echo "--- Last 200 lines of hook output ---"
tail -n 200 "${LOG_FILE}" || true
if [ "${HOOK}" = "pydoclint" ]; then
echo "=== Additional pydoclint diagnostics ==="
docker run --rm -e CI=true --entrypoint /bin/sh "${GITEA_REGISTRY}/darkhelm.org/plex-playlist-cicd:${HEAD_SHA}" -c "
set -e
cd /workspace/backend
echo 'python_version=' && python3 --version
echo 'uv_version=' && uv --version
echo 'pydoclint_version=' && uv run pydoclint --version
echo 'backend_py_count=' && find src -name '*.py' | wc -l
echo 'running_direct_pydoclint='
uv run pydoclint --config=pyproject.toml src/
" || true
fi
exit "${HOOK_STATUS}"
fi
echo "=== Pre-commit Hook End (success) ==="
- *failure_diagnostics_step
dispatch-tests:
name: Dispatch CICD Tests
# Keep dispatch on the same runner pool as setup/check jobs.
runs-on: ubuntu-act
timeout-minutes: 15
needs: [setup, run-check]
steps:
- name: Dispatch tests workflow
env:
ACTIONS_TRIGGER_TOKEN: ${{ secrets.ACTIONS_TRIGGER_TOKEN }}
PACKAGE_ACCESS_TOKEN: ${{ secrets.PACKAGE_ACCESS_TOKEN }}
HEAD_SHA: ${{ needs.setup.outputs.head_sha }}
REPO_FULL: ${{ github.repository }}
HEAD_REF: ${{ github.head_ref }}
REF_NAME: ${{ github.ref_name }}
TRACE_ID_INPUT: ${{ github.event.inputs.trace_id }}
run: |
set -e
DISPATCH_TOKEN="${ACTIONS_TRIGGER_TOKEN:-${PACKAGE_ACCESS_TOKEN:-}}"
if [ -z "${DISPATCH_TOKEN}" ]; then
echo "❌ Missing dispatch token. Set ACTIONS_TRIGGER_TOKEN (repo write scope) or ensure PACKAGE_ACCESS_TOKEN has Actions workflow-dispatch permissions."
exit 1
fi
if ! grep -q "${GITEA_REGISTRY_HOST}" /etc/hosts; then
echo "${GITEA_REGISTRY_IP} ${GITEA_REGISTRY_HOST}" >> /etc/hosts
fi
REPO_OWNER="${REPO_FULL%/*}"
REPO_NAME="${REPO_FULL#*/}"
TARGET_REF="${HEAD_REF:-${REF_NAME}}"
TRACE_ID="${TRACE_ID_INPUT:-cicd-checks-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${HEAD_SHA:0:8}}"
echo "trace_id=${TRACE_ID}"
echo "target_ref=${TARGET_REF}"
CANDIDATE_API_BASES=()
if [ -n "${GITHUB_SERVER_URL:-}" ]; then
CANDIDATE_API_BASES+=("${GITHUB_SERVER_URL%/}/api/v1")
fi
CANDIDATE_API_BASES+=("http://${GITEA_REGISTRY_IP}:3001/api/v1")
CANDIDATE_API_BASES+=("http://${GITEA_REGISTRY_HOST}:3001/api/v1")
ensure_curl() {
if command -v curl >/dev/null 2>&1; then
return 0
fi
if command -v apt-get >/dev/null 2>&1; then
export DEBIAN_FRONTEND=noninteractive
apt-get update -qq
apt-get install -y -qq curl ca-certificates
fi
command -v curl >/dev/null 2>&1
}
ensure_curl || { echo "❌ curl unavailable for dispatch"; exit 1; }
HELPER_PATH="/tmp/dispatch-workflow.sh"
fetch_dispatch_helper() {
local helper_ref="$1"
local api_base
for api_base in "${CANDIDATE_API_BASES[@]}"; do
helper_url="${api_base}/repos/${REPO_OWNER}/${REPO_NAME}/raw/scripts/dispatch-workflow.sh?ref=${helper_ref}"
if curl -fsS --connect-timeout 5 --max-time 20 \
-H "Authorization: token ${DISPATCH_TOKEN}" \
-H "User-Agent: plex-playlist-cicd-checks" \
-o "${HELPER_PATH}" \
"${helper_url}"; then
chmod +x "${HELPER_PATH}"
return 0
fi
done
return 1
}
if ! fetch_dispatch_helper "${TARGET_REF}" && ! fetch_dispatch_helper "${HEAD_SHA}"; then
echo "❌ Failed to fetch scripts/dispatch-workflow.sh from repository"
exit 1
fi
DISPATCH_ARGS=(
--token "${DISPATCH_TOKEN}"
--repo "${REPO_FULL}"
--workflow "cicd-tests.yaml"
--ref "${TARGET_REF}"
--head-sha "${HEAD_SHA}"
--source-workflow "CICD Checks"
--trace-id "${TRACE_ID}"
)
for API_BASE in "${CANDIDATE_API_BASES[@]}"; do
DISPATCH_ARGS+=(--api-base "${API_BASE}")
done
"${HELPER_PATH}" "${DISPATCH_ARGS[@]}"
- *failure_diagnostics_step