-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e01846f
commit 54a0256
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
name: Mirror Gitee Upstream Master | ||
|
||
on: | ||
schedule: | ||
- cron: '0 2 * * *' # 每天凌晨2点执行 | ||
workflow_dispatch: # 允许手动触发 | ||
|
||
jobs: | ||
sync: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout master only | ||
uses: actions/checkout@v3 | ||
with: | ||
persist-credentials: false | ||
ref: master | ||
|
||
- name: Set up Git | ||
run: | | ||
git config --global user.name "GitHub Action" | ||
git config --global user.email "[email protected]" | ||
git remote set-url origin https://x-access-token:${{ secrets.PAT_TOKEN }}@github.com/${{ github.repository }}.git | ||
- name: Add upstream repository | ||
run: git remote add upstream https://gitee.com/openharmony/sensors_miscdevice.git | ||
|
||
- name: Fetch upstream master | ||
run: git fetch upstream master | ||
|
||
- name: Reset master branch to upstream | ||
run: | | ||
git checkout master | ||
git reset --hard upstream/master | ||
# Restore GitHub Actions directory to prevent deletion | ||
git checkout origin/master -- .github/ | ||
git add .github/ | ||
git commit -m "Preserve GitHub Actions files" | ||
git push origin master --force | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.PAT_TOKEN }} | ||
|
||
- name: Clean up non-master branches | ||
run: | | ||
# Delete all local branches except master | ||
git branch | grep -v "master" | grep -v '\*' | xargs -r git branch -D | ||
# Delete all remote branches except master and upstream/master | ||
git branch -r | grep -v "origin/master" | grep -v "upstream/master" | sed 's/origin\///' | xargs -r -I {} git push origin --delete {} |