Skip to content

Collect Logs

Collect Logs #6

Workflow file for this run

name: Collect Logs
on:
workflow_run:
workflows: ["Run Tests"]
types:
- completed
workflow_dispatch:
jobs:
collect-results:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Latest Completed Run ID
id: get_latest_run_id
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
latest_completed_run_id=$(gh run list -L 10 --json databaseId,status,workflowName --jq '.[] | select(.status=="completed" and .workflowName=="Run Tests") | .databaseId' | head -n 1)
echo "LATEST_COMPLETED_RUN_ID=$latest_completed_run_id" >> $GITHUB_ENV
- name: Collect Logs
id: collect_logs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
mkdir -p results
echo "收集最新日志..."
gh run view $LATEST_COMPLETED_RUN_ID --log > results/log-$LATEST_COMPLETED_RUN_ID.txt
- name: Parse Logs
run: |
> x86_64_fixed_images.txt
> arm64_fixed_images.txt
for log_file in $(find results -type f -name "log-*.txt"); do
echo "处理日志文件: $log_file"
success=$(grep -Eo 'success=(true|false)' $log_file | tail -1 | cut -d= -f2)
image=$(grep -Eo 'image=[^ ]+' $log_file | tail -1 | cut -d= -f2)
arch=$(grep -Eo 'arch=[^ ]+' $log_file | tail -1 | cut -d= -f2)
echo "success=$success, image=$image, arch=$arch"
if [ "$success" = "true" ]; then
if [ "$arch" = "amd64" ]; then
echo "$image" >> x86_64_fixed_images.txt
elif [ "$arch" = "arm64" ]; then
echo "$image" >> arm64_fixed_images.txt
fi
fi
done
sort -u x86_64_fixed_images.txt -o x86_64_fixed_images.txt
sort -u arm64_fixed_images.txt -o arm64_fixed_images.txt
echo "最终结果:"
echo "成功的 x86_64 镜像:"
cat x86_64_fixed_images.txt
echo "成功的 arm64 镜像:"
cat arm64_fixed_images.txt
- name: Commit and Push Updated Results
run: |
# 配置 Git 用户信息
git config --global user.name "your-bot-name"
git config --global user.email "[email protected]"
# 确保处于 main 分支
git checkout main
# 添加文件
git add x86_64_fixed_images.txt arm64_fixed_images.txt
# 提交更改(如果有更改才会提交)
git commit -m "Update fixed images list"
# 推送到仓库
git push origin main
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}