🐛 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:
@@ -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: |
|
||||
|
||||
Reference in New Issue
Block a user