Skip to content

review computer grahics 2025/11/23 #162

review computer grahics 2025/11/23

review computer grahics 2025/11/23 #162

Workflow file for this run

name: Sync Posts To Repo Blog
on:
workflow_dispatch:
push:
branches:
- master
jobs:
build:
name: Generate Target Posts
runs-on: ubuntu-22.04 # rsync --mkpath 在 ubuntu-22.04 才有这个参数,故选择这个稳定版本
steps:
# 检出 Git 仓库
- name: Checkout repository
uses: actions/checkout@v3
# 安装 jq 工具
- name: Install jq
run: sudo apt-get install jq
# 构建,根据 map.json 拷贝文件,路径都是都对项目根目录的路径
- name: Copy files to directory public
run: |
# 启用错误处理
set -e
# 处理 rsync 错误
function handle_error
{
echo "Rsync failed with exit code $1."
exit 1
}
# 执行 rsync 命令
cat .github/workflows/file-mapping.json | jq -r 'to_entries[] | "rsync --mkpath \(.key) \(.value)"' | while read -r command; do
echo "Executing: $command"
eval "$command"
if [ $? -ne 0 ]; then
handle_error $?
fi
done
echo "Files copied successfully."
# 上传构建产物
- name: Upload artifacts
# 链接 https://github.com/actions/upload-artifact/
uses: actions/upload-artifact@v4
with:
name: _posts
path: public
include-hidden-files: true
if-no-files-found: error
# 设置为两个串行作业,个人认为这两个作业没必要完全绑成一个作业,为了不相互干扰和影响
sync:
name: Sync Directory Posts
runs-on: ubuntu-latest
needs: build # 表示依赖于 build 作业完成
steps:
# 下载构建产物
- name: Download artifact
# 链接 https://github.com/actions/download-artifact
uses: actions/download-artifact@v4
with:
name: _posts
path: public
# 创建 repo blog 的目录
- name: Create directory for repo blog
run: |
mkdir -p blog
# 签出 blog 的 master 分支
- name: Checkout repo blog
uses: actions/[email protected]
with:
repository: DavidingPlus/blog
ref: master
path: blog
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
# 进行同步
- name: Sync posts to source/_posts
run: |
rm -rf blog/source/_posts/*
cp -r public/* blog/source/_posts/
cd blog/
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add source/_posts/
git commit -m "Sync posts from repo https://github.com/DavidingPlus/study-notes"
git push -u origin master