diff --git a/.gitea/workflows/contributor-check.yml b/.gitea/workflows/contributor-check.yml index c246b6de..8900c40c 100644 --- a/.gitea/workflows/contributor-check.yml +++ b/.gitea/workflows/contributor-check.yml @@ -22,6 +22,10 @@ jobs: set -euo pipefail BASE="${{ github.event.pull_request.base.sha }}" HEAD="${{ github.event.pull_request.head.sha }}" + # Ensure the base ref exists (Gitea checkout may not fetch it). + if ! git cat-file -e "$BASE" 2>/dev/null; then + git fetch --depth=100 origin main || true + fi changed="$(git diff --name-only "$BASE" "$HEAD")" printf '%s\n' "$changed" if printf '%s\n' "$changed" | grep -Eq '(^|/).*\.py$'; then @@ -37,11 +41,26 @@ jobs: - name: Check for unmapped contributor emails if: steps.changes.outputs.run == 'true' run: | - # Get the merge base between this PR and main - MERGE_BASE=$(git merge-base origin/main HEAD) + set -euo pipefail + BASE="${{ github.event.pull_request.base.sha }}" + HEAD="${{ github.event.pull_request.head.sha }}" + + # Ensure the base ref exists (Gitea checkout may not fetch it). + if ! git cat-file -e "$BASE" 2>/dev/null; then + git fetch --depth=100 origin main || true + fi + + # If we still can't resolve the base, fall back to merge-base. + if ! git cat-file -e "$BASE" 2>/dev/null; then + BASE=$(git merge-base origin/main HEAD 2>/dev/null || echo "") + if [ -z "$BASE" ]; then + echo "❌ Cannot determine merge base — cannot verify attribution." + exit 1 + fi + fi # Find any new author emails in this PR's commits - NEW_EMAILS=$(git log ${MERGE_BASE}..HEAD --format='%ae' --no-merges | sort -u) + NEW_EMAILS=$(git log "${BASE}..${HEAD}" --format='%ae' --no-merges | sort -u) if [ -z "$NEW_EMAILS" ]; then echo "No new commits to check." diff --git a/.gitea/workflows/tests.yml b/.gitea/workflows/tests.yml index c353b82c..39a322b3 100644 --- a/.gitea/workflows/tests.yml +++ b/.gitea/workflows/tests.yml @@ -44,8 +44,11 @@ jobs: git fetch --depth=100 origin main || true fi if ! git cat-file -e "$base" 2>/dev/null; then - echo "run=true" >> "$GITHUB_OUTPUT" - exit 0 + base=$(git merge-base origin/main HEAD 2>/dev/null || echo "") + if [ -z "$base" ]; then + echo "run=true" >> "$GITHUB_OUTPUT" + exit 0 + fi fi changed="$(git diff --name-only "$base" "$head")" printf '%s\n' "$changed" @@ -134,8 +137,11 @@ jobs: git fetch --depth=100 origin main || true fi if ! git cat-file -e "$base" 2>/dev/null; then - echo "run=true" >> "$GITHUB_OUTPUT" - exit 0 + base=$(git merge-base origin/main HEAD 2>/dev/null || echo "") + if [ -z "$base" ]; then + echo "run=true" >> "$GITHUB_OUTPUT" + exit 0 + fi fi changed="$(git diff --name-only "$base" "$head")" printf '%s\n' "$changed"