Skip to content

Sync with upstream repository #1414

Sync with upstream repository

Sync with upstream repository #1414

# See https://github.com/ad-m/github-push-action/issues/193#issuecomment-2041278988 for the related discussion.
#这段代码在git merge命令中使用了-Xtheirs选项,这会在冲突发生时优先使用上游的更改。
#请根据你的具体需求调整这一解决方案。如果你想要保留自己仓库的更改,可以使用-Xours选项,但这可能会导致你失去上游的某些更新。
#在自动化脚本处理这种情况时,务必明确你希望优先保留哪边的更改。
#https://github.com/ad-m/github-push-action/issues/193#issuecomment-2046070139
name: Sync with upstream repository
on:
workflow_dispatch:
schedule:
- cron: '0 */6 * * *' # Every 6 hours, can be adjusted as needed
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Setup git
run: |
git config user.name "Pascal Zimmermann"
git config user.email "pascal.zimmermann@theiotstudio.com"
- name: Add remote upstream
run: git remote add upstream git://git.lyx.org/lyx
- name: Fetch changes from upstream
run: git fetch upstream
- name: Merge changes from upstream
run: git merge upstream/master --allow-unrelated-histories -Xtheirs --no-edit > log.txt # Ensure the upstream branch is correct
- name: Check if push is necessary
id: verify-changed-files
run: |
if [ $(wc -l log.txt | sed 's/ log.txt//g') -gt 2 ]; then
echo "files_changed=true" >> "$GITHUB_OUTPUT";
else
echo "files_changed=false" >> "$GITHUB_OUTPUT";
fi
rm -rf log.txt
- name: Push changes
uses: ad-m/github-push-action@master
if: steps.verify-changed-files.outputs.files_changed == 'true'
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: master # Ensure branch name matches the branch you want to sync with