From 6905ab65af5a1ac7102768e64e56308194ec1cf2 Mon Sep 17 00:00:00 2001 From: Jesse <74103710+95256155o@users.noreply.github.com> Date: Thu, 23 May 2024 03:37:56 -0400 Subject: [PATCH 1/6] Create sync.yml --- .github/workflows/sync.yml | 40 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 .github/workflows/sync.yml diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml new file mode 100644 index 000000000..90d544b19 --- /dev/null +++ b/.github/workflows/sync.yml @@ -0,0 +1,40 @@ +name: Sync Fork + +on: + schedule: + - cron: '0 0 * * *' # 每天运行一次 + workflow_dispatch: # 手动触发工作流 + +jobs: + sync: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + repository: 'zhayujie/chatgpt-on-wechat' # 上游仓库 + ref: 'master' # 分支名 + + - name: Backup sync.yml + run: | + cp .github/workflows/sync.yml /tmp/sync.yml + + - name: Sync with upstream + run: | + git remote add upstream https://github.com/zhayujie/chatgpt-on-wechat.git + git fetch upstream + git checkout master + git rebase upstream/master + + - name: Restore sync.yml + run: | + cp /tmp/sync.yml .github/workflows/sync.yml + - name: Push changes + run: | + git config user.name "${{ github.actor }}" + git config user.email "${{ github.actor }}@users.noreply.github.com" + git add .github/workflows/sync.yml + git commit -m "Restore sync.yml" + git push origin main --force + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From c1f5b66601133768381605999cc07f4e1cf4f08b Mon Sep 17 00:00:00 2001 From: Jesse <74103710+95256155o@users.noreply.github.com> Date: Thu, 23 May 2024 03:40:27 -0400 Subject: [PATCH 2/6] Update sync.yml --- .github/workflows/sync.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 90d544b19..57b27ebf7 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -17,6 +17,7 @@ jobs: - name: Backup sync.yml run: | + mkdir -p /tmp/${{ github.repository }} cp .github/workflows/sync.yml /tmp/sync.yml - name: Sync with upstream @@ -28,7 +29,7 @@ jobs: - name: Restore sync.yml run: | - cp /tmp/sync.yml .github/workflows/sync.yml + cp /tmp/${{ github.repository }}/sync.yml .github/workflows/sync.yml - name: Push changes run: | git config user.name "${{ github.actor }}" From ecab4ed47ddfe3d480a7aa5b1ce0c6829560a4cd Mon Sep 17 00:00:00 2001 From: Jesse <74103710+95256155o@users.noreply.github.com> Date: Thu, 23 May 2024 03:42:52 -0400 Subject: [PATCH 3/6] Update sync.yml --- .github/workflows/sync.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 57b27ebf7..a58d650cb 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -8,34 +8,36 @@ on: jobs: sync: runs-on: ubuntu-latest + steps: - name: Checkout uses: actions/checkout@v2 with: repository: 'zhayujie/chatgpt-on-wechat' # 上游仓库 ref: 'master' # 分支名 - + - name: Backup sync.yml run: | mkdir -p /tmp/${{ github.repository }} - cp .github/workflows/sync.yml /tmp/sync.yml - + cp .github/workflows/sync.yml /tmp/${{ github.repository }}/sync.yml + - name: Sync with upstream run: | git remote add upstream https://github.com/zhayujie/chatgpt-on-wechat.git git fetch upstream git checkout master git rebase upstream/master - + - name: Restore sync.yml run: | - cp /tmp/${{ github.repository }}/sync.yml .github/workflows/sync.yml + cp /tmp/${{ github.repository }}/sync.yml .github/workflows/sync.yml + - name: Push changes run: | git config user.name "${{ github.actor }}" git config user.email "${{ github.actor }}@users.noreply.github.com" git add .github/workflows/sync.yml git commit -m "Restore sync.yml" - git push origin main --force + git push origin master --force env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 93a0d9f720e0563ee79242823d7fee71524a678b Mon Sep 17 00:00:00 2001 From: Jesse <74103710+95256155o@users.noreply.github.com> Date: Thu, 23 May 2024 03:44:57 -0400 Subject: [PATCH 4/6] Update sync.yml --- .github/workflows/sync.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index a58d650cb..e2bf191d0 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -17,6 +17,7 @@ jobs: ref: 'master' # 分支名 - name: Backup sync.yml + if: exists('.github/workflows/sync.yml') run: | mkdir -p /tmp/${{ github.repository }} cp .github/workflows/sync.yml /tmp/${{ github.repository }}/sync.yml @@ -29,6 +30,7 @@ jobs: git rebase upstream/master - name: Restore sync.yml + if: exists('/tmp/${{ github.repository }}/sync.yml') run: | cp /tmp/${{ github.repository }}/sync.yml .github/workflows/sync.yml From ee7c39cb60f3c5b8723527fc9caf493171f4c7fa Mon Sep 17 00:00:00 2001 From: Jesse <74103710+95256155o@users.noreply.github.com> Date: Thu, 23 May 2024 03:45:47 -0400 Subject: [PATCH 5/6] Update sync.yml --- .github/workflows/sync.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index e2bf191d0..22b7946df 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -17,10 +17,11 @@ jobs: ref: 'master' # 分支名 - name: Backup sync.yml - if: exists('.github/workflows/sync.yml') run: | - mkdir -p /tmp/${{ github.repository }} - cp .github/workflows/sync.yml /tmp/${{ github.repository }}/sync.yml + if [ -f .github/workflows/sync.yml ]; then + mkdir -p /tmp/${{ github.repository }} + cp .github/workflows/sync.yml /tmp/${{ github.repository }}/sync.yml + fi - name: Sync with upstream run: | @@ -30,9 +31,10 @@ jobs: git rebase upstream/master - name: Restore sync.yml - if: exists('/tmp/${{ github.repository }}/sync.yml') run: | - cp /tmp/${{ github.repository }}/sync.yml .github/workflows/sync.yml + if [ -f /tmp/${{ github.repository }}/sync.yml ]; then + cp /tmp/${{ github.repository }}/sync.yml .github/workflows/sync.yml + fi - name: Push changes run: | From 73494102f26fd3dfcb0ae227a34a4614045b5d0f Mon Sep 17 00:00:00 2001 From: Jesse <74103710+95256155o@users.noreply.github.com> Date: Thu, 23 May 2024 03:47:00 -0400 Subject: [PATCH 6/6] Update sync.yml --- .github/workflows/sync.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sync.yml b/.github/workflows/sync.yml index 22b7946df..4eaf9474f 100644 --- a/.github/workflows/sync.yml +++ b/.github/workflows/sync.yml @@ -40,8 +40,10 @@ jobs: run: | git config user.name "${{ github.actor }}" git config user.email "${{ github.actor }}@users.noreply.github.com" - git add .github/workflows/sync.yml - git commit -m "Restore sync.yml" - git push origin master --force + if [ -f .github/workflows/sync.yml ]; then + git add .github/workflows/sync.yml + git commit -m "Restore sync.yml" + git push origin master --force + fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}