🐛 fix(ci): inline gitea workflow bootstrap

remove the pre-checkout dependency on .gitea/ci/prepare_repo.sh
from the root workflows and inline the bootstrap logic instead.

add a regression test for workflow bootstrap ordering and register
it in the tests README.
This commit is contained in:
csh
2026-05-19 09:50:24 +08:00
parent e0b1c3ab1b
commit 588b81dae4
5 changed files with 121 additions and 65 deletions
+49 -7
View File
@@ -23,13 +23,55 @@ jobs:
steps:
- name: 📥 准备仓库
env:
REPO_NAME: ${{ github.event.repository.name }}
TOKEN: ${{ secrets.WORKFLOW }}
TARGET_SHA: ${{ github.sha }}
TARGET_REF: ${{ github.ref }}
TARGET_REF_NAME: ${{ github.ref_name }}
run: bash .gitea/ci/prepare_repo.sh
run: |
set -euo pipefail
echo "========================================"
echo "📥 准备仓库到 WORKSPACE_DIR"
echo "========================================"
REPO_NAME="${{ github.event.repository.name }}"
REPO_DIR="${WORKSPACE_DIR}/${REPO_NAME}"
TOKEN="${{ secrets.WORKFLOW }}"
TARGET_SHA="${{ github.sha }}"
TARGET_REF="${{ github.ref }}"
TARGET_REF_NAME="${{ github.ref_name }}"
if [ -n "$TOKEN" ]; then
REPO_URL="https://oauth2:${TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
else
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
fi
if [ -d "$REPO_DIR" ]; then
if [ -d "$REPO_DIR/.git" ]; then
cd "$REPO_DIR"
git clean -fdx
git reset --hard
git fetch --all --tags --force --prune --prune-tags
else
rm -rf "$REPO_DIR"
fi
fi
if [ ! -d "$REPO_DIR/.git" ]; then
mkdir -p "$WORKSPACE_DIR"
git clone "$REPO_URL" "$REPO_DIR"
fi
if git -C "$REPO_DIR" cat-file -e "${TARGET_SHA}^{commit}" 2>/dev/null; then
git -C "$REPO_DIR" checkout -f "$TARGET_SHA"
else
if [ -n "$TARGET_REF" ]; then
git -C "$REPO_DIR" fetch origin "$TARGET_REF"
git -C "$REPO_DIR" checkout -f FETCH_HEAD
else
git -C "$REPO_DIR" checkout -f "$TARGET_REF_NAME"
fi
fi
git config --global --add safe.directory "$REPO_DIR"
echo "REPO_DIR=$REPO_DIR" >> "$GITHUB_ENV"
- name: 🧪 Lint commit message / PR title
run: |
cd "$REPO_DIR"
+49 -7
View File
@@ -30,13 +30,55 @@ jobs:
steps:
- name: 📥 准备仓库
env:
REPO_NAME: ${{ github.event.repository.name }}
TOKEN: ${{ secrets.WORKFLOW }}
TARGET_SHA: ${{ github.sha }}
TARGET_REF: ${{ github.ref }}
TARGET_REF_NAME: ${{ github.ref_name }}
run: bash .gitea/ci/prepare_repo.sh
run: |
set -euo pipefail
echo "========================================"
echo "📥 准备仓库到 WORKSPACE_DIR"
echo "========================================"
REPO_NAME="${{ github.event.repository.name }}"
REPO_DIR="${WORKSPACE_DIR}/${REPO_NAME}"
TOKEN="${{ secrets.WORKFLOW }}"
TARGET_SHA="${{ github.sha }}"
TARGET_REF="${{ github.ref }}"
TARGET_REF_NAME="${{ github.ref_name }}"
if [ -n "$TOKEN" ]; then
REPO_URL="https://oauth2:${TOKEN}@${GITHUB_SERVER_URL#https://}/${GITHUB_REPOSITORY}.git"
else
REPO_URL="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git"
fi
if [ -d "$REPO_DIR" ]; then
if [ -d "$REPO_DIR/.git" ]; then
cd "$REPO_DIR"
git clean -fdx
git reset --hard
git fetch --all --tags --force --prune --prune-tags
else
rm -rf "$REPO_DIR"
fi
fi
if [ ! -d "$REPO_DIR/.git" ]; then
mkdir -p "$WORKSPACE_DIR"
git clone "$REPO_URL" "$REPO_DIR"
fi
if git -C "$REPO_DIR" cat-file -e "${TARGET_SHA}^{commit}" 2>/dev/null; then
git -C "$REPO_DIR" checkout -f "$TARGET_SHA"
else
if [ -n "$TARGET_REF" ]; then
git -C "$REPO_DIR" fetch origin "$TARGET_REF"
git -C "$REPO_DIR" checkout -f FETCH_HEAD
else
git -C "$REPO_DIR" checkout -f "$TARGET_REF_NAME"
fi
fi
git config --global --add safe.directory "$REPO_DIR"
echo "REPO_DIR=$REPO_DIR" >> "$GITHUB_ENV"
- name: 🔧 安装测试依赖
run: |