Daily Contest Script #286
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
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" |