Update README with LeetCode Daily Challenge #3
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: Update README with LeetCode Daily Challenge | |
on: | |
schedule: | |
- cron: '1 0 * * *' # Runs daily at 00:01 UTC | |
workflow_dispatch: # Allows for manual triggering | |
jobs: | |
update-readme: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Set up Python | |
uses: actions/setup-python@v2 | |
with: | |
python-version: '3.x' | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install requests beautifulsoup4 | |
- name: Run update_readme.py | |
id: update_readme | |
run: python update_readme.py | |
- name: Create GitHub issue on failure | |
if: failure() | |
uses: actions/github-script@v6 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const issueTitle = "Update README with LeetCode Daily Challenge Failed"; | |
const issueBody = ` | |
The GitHub Action to update README with LeetCode Daily Challenge has failed. | |
Please check the workflow logs for more details. | |
`; | |
const existingIssues = await github.rest.issues.listForRepo({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
state: 'open', | |
labels: 'bug', | |
}); | |
const issueExists = existingIssues.data.find(issue => issue.title === issueTitle); | |
if (!issueExists) { | |
await github.rest.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: issueTitle, | |
body: issueBody, | |
labels: ['bug'], | |
}); | |
} else { | |
console.log(`An issue with the title "${issueTitle}" already exists.`); | |
} |