-
Notifications
You must be signed in to change notification settings - Fork 11
61 lines (55 loc) · 1.85 KB
/
sync.yml
File metadata and controls
61 lines (55 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
name: Sync Fork
on:
schedule:
- cron: "0 1,13 * * *"
workflow_dispatch:
jobs:
repo-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
fetch-depth: 0 # Ensure all history is fetched
- name: Sync From Source
uses: repo-sync/github-sync@v2
with:
source_repo: "https://github.com/QuBenhao/LeetCode.git"
source_branch: "master"
destination_branch: "master"
github_token: ${{ secrets.TOKEN }}
# Step to check for changes
- name: Check for changes
id: check_changes
uses: actions/github-script@v5
with:
script: |
const result = await github.rest.repos.compareCommits({
owner: context.repo.owner,
repo: context.repo.repo,
base: "master",
head: "HEAD",
});
if (result.data.files.length > 0) {
core.setOutput("changes", "true");
} else {
core.setOutput("changes", "false");
}
- name: Reset master branch
if: steps.check_changes.outputs.changes == 'true'
run: |
git fetch origin master:master
git reset --hard master
# Conditional step to create a pull request only if there are changes
- name: Create Pull Request
if: steps.check_changes.outputs.changes == 'true'
uses: peter-evans/create-pull-request@v6
with:
token: ${{ secrets.TOKEN }}
commit-message: |
feat: update from master
auto generated
author: "benhao <[email protected]>"
branch: "master"
title: "Merge from master"
body: "This is an auto-generated PR to sync changes from the master branch to demo_master."