remove images in hello-algo #125
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Sync Posts To Repo Blog | |
on: | |
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/[email protected] | |
with: | |
name: _posts | |
path: public | |
# 设置为两个串行作业,个人认为这两个作业没必要完全绑成一个作业,为了不相互干扰和影响 | |
sync: | |
name: Sync Directory Posts | |
runs-on: ubuntu-latest | |
needs: build # 表示依赖于 build 作业完成 | |
steps: | |
# 下载构建产物 | |
- name: Download artifact | |
# 链接 https://github.com/actions/download-artifact | |
uses: actions/[email protected] | |
with: | |
name: _posts | |
path: dist | |
# 创建 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 dist/* 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 | |
# 触发 blog 的 CI | |
# 本来是通过 blog 的 _posts 分支进行中转的,但是 github 不允许连续两次触发 push 的 action,为了防止死循环,因此需要走手动 Trigger 的流程。现在直接一步到位,因此这一步骤注释。 | |
# - name: Trigger action in branch master | |
# # 链接 https://github.com/convictional/trigger-workflow-and-wait | |
# uses: convictional/[email protected] | |
# with: | |
# owner: DavidingPlus | |
# repo: blog | |
# github_user: DavidingPlus | |
# workflow_file_name: build.yml | |
# ref: master | |
# github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} |