起因

更新文章时发现Coding的SERVER HOOK功能已经失效了,查看日志发现返回Unable to retry this workflow run because it was created over a month ago
配置详情
由于我这样配置,GITHUB只能使用1个月以内的流程,参考官方说明

原文

国内Git仓库同步到Github仓库

修改

  1. https://api.github.com/repos/用户名/仓库名/dispatches
  2. Accept: application/vnd.github.everest-preview+json
  3. Authorization: token 申请的秘钥
  4. {“event_type”: “updateBlog”,”client_payload”: {“text”: “crack”}}

图

YML配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
name: git-mirror-crack

on:
repository_dispatch:
types:
- updateBlog
jobs:
git-mirrors:
runs-on: ubuntu-latest
steps:
- uses: wearerequired/git-mirror-action@v1
env:
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }}
SSH_KNOWN_HOSTS: ${{ secrets.SSH_KNOWN_HOSTS }}
with:
source-repo: "git@e.coding.net:thsware/workspace/${{ github.event.client_payload.text }}.git"
destination-repo: "git@github.com:ooo-o-ooo/${{ github.event.client_payload.text }}.git"

解释一下,${{ github.event.client_payload.text }} 获取到的是传入的参数,也就是自定义模板中的crack,目的是让GITHUB知道要同步哪个仓库,后续CODING平台新建SERVER HOOK时,只需要修改crack的内容即可。types 参数是触发事件,updateBlogsync 是自定义的。和event_type对应。

本来想直接使用repository_dispatchtypes,但是获取不到types的值。所以只能使用client_payload.text。 能获取到值的可以告知一下。谢谢。

参考文章:

  1. https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs#about-re-running-workflows-and-jobs
  2. https://goobar.dev/manually-trigger-a-github-actions-workflow/
  3. https://stackoverflow.com/questions/68147899/whats-is-the-difference-between-repository-dispatch-and-workflow-dispatch-in-git