Files
test/.gitea/workflows/prepare.yml
T
csh 4d02a87806
Prepare / prepare (push) Successful in 11s
Test Multi Jobs / first (push) Successful in 0s
Test Multi Jobs / second (push) Successful in 0s
test: let print workflows own their worktrees
2026-07-20 09:37:00 +08:00

76 lines
2.4 KiB
YAML

name: Prepare
on:
push:
branches:
- main
workflow_dispatch:
concurrency:
group: prepare-${{ github.repository }}
cancel-in-progress: false
env:
WORKSPACE_ROOT: "/data/workspace"
jobs:
prepare:
runs-on: standard-ubuntu-22
steps:
- name: 准备共享 bare 仓库
run: |
set -euo pipefail
REPO_NAME="${{ github.event.repository.name }}"
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
HEAD_SHA="${{ github.sha }}"
REPOSITORY_DIR="${WORKSPACE_ROOT}/${REPO_NAME}/repository.git"
case "$HEAD_SHA" in
''|*[!0-9a-fA-F]*)
echo "无效的触发提交 SHA: $HEAD_SHA" >&2
exit 1
;;
esac
echo "===== [$(date '+%F %T')] 开始准备共享仓库 ====="
echo "共享仓库: $REPOSITORY_DIR"
echo "仓库地址: $REPO_URL"
echo "触发提交: $HEAD_SHA"
mkdir -p "$(dirname "$REPOSITORY_DIR")"
if [ ! -d "$REPOSITORY_DIR" ]; then
echo "首次使用,初始化 bare 仓库..."
git init --bare "$REPOSITORY_DIR"
elif [ "$(git --git-dir="$REPOSITORY_DIR" rev-parse --is-bare-repository)" != "true" ]; then
echo "共享仓库目录不是 bare 仓库: $REPOSITORY_DIR" >&2
exit 1
fi
if git --git-dir="$REPOSITORY_DIR" remote get-url origin >/dev/null 2>&1; then
git --git-dir="$REPOSITORY_DIR" remote set-url origin "$REPO_URL"
else
git --git-dir="$REPOSITORY_DIR" remote add origin "$REPO_URL"
fi
echo "----- 从远端集中 fetch 一次 -----"
git --git-dir="$REPOSITORY_DIR" fetch \
--prune --prune-tags --tags --force origin \
'+refs/heads/*:refs/remotes/origin/*'
if ! git --git-dir="$REPOSITORY_DIR" cat-file -e "${HEAD_SHA}^{commit}"; then
echo "共享仓库中不存在触发提交: $HEAD_SHA" >&2
exit 1
fi
echo "----- 当前共享仓库状态 -----"
git --git-dir="$REPOSITORY_DIR" log -1 --oneline "$HEAD_SHA"
echo "===== Prepare 完成 ====="
- name: 模拟准备耗时
run: |
echo "[$(date '+%F %T')] Prepare 开始 sleep 10s ..."
sleep 10
echo "[$(date '+%F %T')] Prepare 完成"