test: add prepare + two workflow_run print workflows

This commit is contained in:
csh
2026-07-15 09:22:57 +08:00
parent f406d829cd
commit dcb03831f3
3 changed files with 94 additions and 0 deletions
+54
View File
@@ -0,0 +1,54 @@
name: Prepare
on:
push:
branches:
- main
workflow_dispatch:
jobs:
prepare:
runs-on: ubuntu-latest
steps:
- name: 准备复用仓库(强制全量拉取 + 丢弃本地改动)
run: |
set -e
REPO_DIR=/tmp/reused-repo
REPO_URL="${{ github.server_url }}/${{ github.repository }}.git"
BRANCH="${{ github.ref_name }}"
echo "===== [$(date '+%F %T')] 开始准备仓库 ====="
echo "复用目录: $REPO_DIR"
echo "仓库地址: $REPO_URL"
echo "目标分支: $BRANCH"
if [ ! -d "$REPO_DIR/.git" ]; then
echo "首次使用,克隆仓库..."
git clone "$REPO_URL" "$REPO_DIR"
fi
cd "$REPO_DIR"
echo "----- 丢弃本地所有更改 -----"
git reset --hard
git clean -fdx
echo "----- 强制拉取最新(含 tag,删除已消失的远端 ref-----"
git remote set-url origin "$REPO_URL"
git fetch origin --prune --prune-tags --tags --force
echo "----- 强制对齐到远端分支 -----"
git checkout -B "$BRANCH" "origin/$BRANCH"
git reset --hard "origin/$BRANCH"
git clean -fdx
echo "----- 当前状态 -----"
git log -1 --oneline
echo "本地 tags:"
git tag
- name: 模拟准备耗时
run: |
echo "[$(date '+%F %T')] Prepare 开始 sleep 10s ..."
sleep 10
echo "[$(date '+%F %T')] Prepare 完成"
+20
View File
@@ -0,0 +1,20 @@
name: Print One
on:
workflow_run:
workflows: ["Prepare"]
types:
- completed
jobs:
print:
runs-on: ubuntu-latest
steps:
- name: 每 10 秒打印一次数字
run: |
echo "[$(date '+%F %T')] Print One 启动 (上游 Prepare 结论: ${{ github.event.workflow_run.conclusion }})"
for i in $(seq 1 5); do
echo "[$(date '+%F %T')] Print One -> $i"
sleep 10
done
echo "[$(date '+%F %T')] Print One 完成"
+20
View File
@@ -0,0 +1,20 @@
name: Print Two
on:
workflow_run:
workflows: ["Prepare"]
types:
- completed
jobs:
print:
runs-on: ubuntu-latest
steps:
- name: 每 10 秒打印一次数字
run: |
echo "[$(date '+%F %T')] Print Two 启动 (上游 Prepare 结论: ${{ github.event.workflow_run.conclusion }})"
for i in $(seq 1 5); do
echo "[$(date '+%F %T')] Print Two -> $i"
sleep 10
done
echo "[$(date '+%F %T')] Print Two 完成"