@@ -21,29 +21,43 @@ jobs:
2121 - name : Install dependencies
2222 run : pip install -r scripts/requirements.txt
2323
24- - name : Create new branch
24+ - name : Check if branch exists
2525 run : |
26- git checkout -b automate-json-update
27- git push -u origin automate-json-update
26+ branch_exists=$(git ls-remote --exit-code --heads origin automate-c-json-update || echo "")
27+ if [ -n "$branch_exists" ]; then
28+ git fetch origin automate-c-json-update
29+ git checkout automate-c-json-update
30+ else
31+ git checkout -b automate-c-json-update
32+ fi
2833
2934 - name : Run contest.py script
3035 run : python scripts/contest.py
3136
37+ - name : Check for changes
38+ id : git-diff
39+ run : |
40+ git fetch origin main
41+ changes=$(git diff --name-only main -- data/contests.json)
42+ echo "::set-output name=changes::$changes"
43+
3244 - name : Commit and push changes
33- uses : EndBug/add-and-commit@v9
34- with :
35- author_name : GitHub Action
36- 37- message : Update JSON file
38- push : true
45+ if : steps.git-diff.outputs.changes != ''
46+ run : |
47+ git config --local user.email "[email protected] " 48+ git config --local user.name "GitHub Action"
49+ git add data/contests.json
50+ git commit -m "Update JSON file"
51+ git push origin automate-c-json-update
3952
4053 - name : Create Pull Request
41- uses : peter-evans/create-pull-request@v3
42- with :
43- token : ${{ secrets.GITHUB_TOKEN }}
44- commit-message : Automated pull request for JSON file update
45- title : Automated Pull Request
46- branch : automate-json-update
47- base : main
48- body : |
49- This pull request updates the JSON file automatically.
54+ if : steps.git-diff.outputs.changes != ''
55+ env :
56+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
57+ run : |
58+ pr_branch="automate-c-json-update"
59+ pr_title="Automated Pull Request"
60+ pr_body="This pull request updates the JSON file automatically."
61+
62+ # Create the pull request
63+ hub pull-request -m "$pr_title" -b main -h "$pr_branch" -m "$pr_body"
0 commit comments