#!/usr/bin/env bash # # test-ci-workflow.sh checks the properties of .gitea/workflows/ci.yml that # gate pull requests. It runs without Go modules so CI configuration can be # validated even when the module proxy is unavailable; the equivalent Go test # in internal/ci/workflow_test.go parses the same file as YAML. set -euo pipefail root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" workflow="$root/.gitea/workflows/ci.yml" if [ ! -f "$workflow" ]; then echo "missing workflow: $workflow" >&2 exit 1 fi failures=0 require_line() { if ! grep -qF "$1" "$workflow"; then echo "workflow is missing: $1" >&2 failures=$((failures + 1)) fi } require_line 'on:' require_line ' pull_request:' require_line ' push:' require_line 'branches: [main]' require_line 'run: ./scripts/check.sh' require_line 'run: ./scripts/check-deps.sh' require_line 'go-version-file: go.mod' # The workflow must be a single action so "all checks passed" has one meaning. jobs="$(awk '/^jobs:/{j=1;next} j && /^ [a-z0-9_-]+:$/{n++} END{print n+0}' "$workflow")" if [ "$jobs" -ne 1 ]; then echo "workflow must define exactly one job, found $jobs" >&2 failures=$((failures + 1)) fi if [ "$failures" -ne 0 ]; then exit 1 fi echo 'ok: the pull request workflow runs the repository checks'