Create New Note for Daily LeetCode Problem #1
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: Create New Note for Daily LeetCode Problem | |
on: | |
workflow_dispatch: # Allows for manual triggering | |
jobs: | |
create-note: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v2 | |
- name: Fetch daily LeetCode problem details and create note | |
env: | |
GITHUB_USERNAME: ${{ github.actor }} | |
run: | | |
# Fetch problem details | |
curl -X POST -H 'Content-Type: application/json' \ | |
-d '{"query":"query questionOfToday { activeDailyCodingChallengeQuestion { date link question { questionId title titleSlug difficulty } } }","operationName":"questionOfToday"}' \ | |
https://leetcode.com/graphql -o response.json | |
# Parse problem details | |
PROBLEM_ID=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.questionId' response.json) | |
TITLE=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.title' response.json) | |
TITLE_SLUG=$(jq -r '.data.activeDailyCodingChallengeQuestion.question.titleSlug' response.json) | |
LINK="https://leetcode.com/problems/${TITLE_SLUG}" | |
# Create problem directory and note | |
PROBLEM_DIR="problems/${PROBLEM_ID}" | |
NOTE_FILE="${PROBLEM_DIR}/${GITHUB_USERNAME}.md" | |
mkdir -p "${PROBLEM_DIR}" | |
# Customize template and write to new file | |
sed "s|<NUMBER>|${PROBLEM_ID}|g; s|<TITLE>|${TITLE}|g; s|<LINK TO DESCRIPTION>|${LINK}|g" problems/template.md > "${NOTE_FILE}" | |
- name: Commit and push changes | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
commit_message: "Creating a template for ${{ github.actor }}'s solution to problem ${PROBLEM_ID}" | |
branch: main | |
file_pattern: problems/*/*.md |