Sync Repository #20
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 Repository | |
on: | |
schedule: | |
# 每周一下午6点(UTC时间)执行,对应中国东八区凌晨2点 | |
- cron: "0 18 * * *" | |
workflow_dispatch: | |
inputs: | |
targetRepo: | |
description: "Target repository" | |
required: true | |
default: "jagger235711/HB" | |
targetBranch1: | |
description: "Target branch 1" | |
required: true | |
default: "Routines" | |
upstreamRepo1: | |
description: "Upstream repository 1" | |
required: true | |
default: "UniverseString/Hearthstone-myRoutines" | |
upstreamBranch1: | |
description: "Upstream branch 1" | |
required: true | |
default: "master" | |
gitUserName: | |
description: "Git user name" | |
required: true | |
default: "mergeBot" | |
gitUserEmail: | |
description: "Git user email" | |
required: true | |
default: "[email protected]" | |
env: | |
DEFAULT_TARGET_REPO: "jagger235711/HB" | |
DEFAULT_TARGET_BRANCH1: "Routines" | |
DEFAULT_UPSTREAM_REPO1: "UniverseString/Hearthstone-myRoutines" | |
DEFAULT_UPSTREAM_BRANCH1: "master" | |
DEFAULT_GIT_USER_NAME: "mergeBot" | |
DEFAULT_GIT_USER_EMAIL: "[email protected]" | |
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN_EE }} # 使用单个 Token | |
jobs: | |
sync-branch1: | |
runs-on: ubuntu-latest | |
env: | |
TZ: Asia/Shanghai | |
steps: | |
- name: Checkout target repository for branch 1 | |
uses: actions/checkout@v3 | |
with: | |
repository: ${{ github.event.inputs.targetRepo || env.DEFAULT_TARGET_REPO }} | |
ref: ${{ github.event.inputs.targetBranch1 || env.DEFAULT_TARGET_BRANCH1 }} | |
token: ${{ secrets.REPO_ACCESS_TOKEN }} # 使用单个 Token | |
- name: Setup Git | |
run: | | |
git config --global user.name "${{ github.event.inputs.gitUserName || env.DEFAULT_GIT_USER_NAME }}" | |
git config --global user.email "${{ github.event.inputs.gitUserEmail || env.DEFAULT_GIT_USER_EMAIL }}" | |
- name: Verify timezone | |
run: date | |
- name: Add and merge changes from upstream repository 1 to branch 1 | |
run: | | |
git remote add upstream1 https://x-access-token:${REPO_ACCESS_TOKEN}@gitee.com/${{ github.event.inputs.upstreamRepo1 || env.DEFAULT_UPSTREAM_REPO1 }}.git | |
git fetch upstream1 | |
git checkout ${{ github.event.inputs.targetBranch1 || env.DEFAULT_TARGET_BRANCH1 }} | |
git reset --hard upstream1/${{ github.event.inputs.upstreamBranch1 || env.DEFAULT_UPSTREAM_BRANCH1 }} | |
git push origin ${{ github.event.inputs.targetBranch1 || env.DEFAULT_TARGET_BRANCH1 }} --force |