Files
test/.gitea/workflows/print2.yml
T
csh 94d2d5b042
Test Multi Jobs / first (push) Successful in 1s
Test Multi Jobs / second (push) Successful in 1s
Prepare / prepare (push) Successful in 11s
test: share bare repository across print workflows
2026-07-20 09:25:36 +08:00

66 lines
2.1 KiB
YAML

name: Print Two
on:
workflow_run:
workflows: ["Prepare"]
types:
- completed
concurrency:
group: print2-${{ github.repository }}
cancel-in-progress: false
env:
WORKSPACE_ROOT: "/data/workspace"
jobs:
print:
runs-on: standard-ubuntu-22
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: 将 Print Two Worktree 对齐到上游提交
run: |
set -euo pipefail
REPO_NAME="${{ github.event.repository.name }}"
HEAD_SHA="${{ github.event.workflow_run.head_sha }}"
WORKTREE_DIR="${WORKSPACE_ROOT}/${REPO_NAME}/worktrees/print2"
case "$HEAD_SHA" in
''|*[!0-9a-fA-F]*)
echo "无效的上游提交 SHA: $HEAD_SHA" >&2
exit 1
;;
esac
if [ ! -f "$WORKTREE_DIR/.git" ]; then
echo "Prepare 未创建 Print Two Worktree: $WORKTREE_DIR" >&2
exit 1
fi
if ! git -C "$WORKTREE_DIR" cat-file -e "${HEAD_SHA}^{commit}"; then
echo "Worktree 共享仓库中不存在上游提交: $HEAD_SHA" >&2
exit 1
fi
git -C "$WORKTREE_DIR" checkout --detach --force "$HEAD_SHA"
git -C "$WORKTREE_DIR" reset --hard "$HEAD_SHA"
git -C "$WORKTREE_DIR" clean -ffdx
ACTUAL_SHA=$(git -C "$WORKTREE_DIR" rev-parse HEAD)
if [ "$ACTUAL_SHA" != "$HEAD_SHA" ]; then
echo "Worktree 提交不匹配: 期望 $HEAD_SHA,实际 $ACTUAL_SHA" >&2
exit 1
fi
echo "Print Two 使用仓库: $WORKTREE_DIR"
git -C "$WORKTREE_DIR" log -1 --oneline
- name: 每 10 秒打印一次数字
run: |
WORKTREE_DIR="${WORKSPACE_ROOT}/${{ github.event.repository.name }}/worktrees/print2"
echo "[$(date '+%F %T')] Print Two 启动 (仓库提交: $(git -C "$WORKTREE_DIR" rev-parse --short HEAD))"
for i in $(seq 1 5); do
echo "[$(date '+%F %T')] Print Two -> $i"
sleep 10
done
echo "[$(date '+%F %T')] Print Two 完成"