-
-
Notifications
You must be signed in to change notification settings - Fork 19
63 lines (52 loc) · 2.02 KB
/
daily-contest-script.yml
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
62
63
name: Daily Contest Script
on:
schedule:
- cron: '0 0 * * *' # Schedule the workflow to run at 00:00 UTC daily
workflow_dispatch:
jobs:
run_contest_script:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.10'
- name: Install dependencies
run: pip install -r scripts/requirements.txt
- name: Check if branch exists
run: |
branch_exists=$(git ls-remote --exit-code --heads origin automate-c-json-update || echo "")
if [ -n "$branch_exists" ]; then
git fetch origin automate-c-json-update
git checkout automate-c-json-update
else
git checkout -b automate-c-json-update
fi
- name: Run contest.py script
run: python scripts/contest.py
- name: Check for changes
id: git-diff
run: |
git fetch origin main
changes=$(git diff --name-only main -- data/contests.json)
echo "::set-output name=changes::$changes"
- name: Commit and push changes
if: steps.git-diff.outputs.changes != ''
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add data/contests.json
git commit -m "Update JSON file"
git push origin automate-c-json-update
- name: Create Pull Request
if: steps.git-diff.outputs.changes != ''
run: |
pr_branch="automate-c-json-update"
pr_title="Automated Pull Request"
pr_body="This pull request updates the JSON file automatically."
# Create the pull request using the GitHub API
curl -X POST -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
-d "{\"title\":\"$pr_title\",\"body\":\"$pr_body\",\"head\":\"$pr_branch\",\"base\":\"main\"}" \
"https://api.github.com/repos/$GITHUB_REPOSITORY/pulls"