-
Notifications
You must be signed in to change notification settings - Fork 1
73 lines (64 loc) · 2.65 KB
/
Copy pathfetch-problem.yml
File metadata and controls
73 lines (64 loc) · 2.65 KB
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
64
65
66
67
68
69
70
71
72
73
name: Fetch LeetCode Problem
on:
workflow_dispatch:
inputs:
problem_url:
description: "LeetCode problem URL (leave empty for today's daily challenge)"
required: false
type: string
default: ""
force_refetch:
description: "Force re-fetch if problem.md exists"
required: false
type: boolean
default: false
jobs:
fetch:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
pip3 install html2text pyyaml
- name: Fetch problem
id: fetch
uses: ./.github/actions/fetch-leetcode-problem
with:
problem_url: ${{ inputs.problem_url }}
force_refetch: ${{ inputs.force_refetch }}
- name: Check if premium
if: steps.fetch.outputs.is_premium == 'true'
run: |
echo "::error::Cannot fetch premium problem: ${{ steps.fetch.outputs.title }}"
exit 1
- name: Commit problem.md
if: steps.fetch.outputs.was_fetched == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "problems/${{ steps.fetch.outputs.dir_name }}/problem.md"
git commit -m "feat: add problem metadata for ${{ steps.fetch.outputs.number }}. ${{ steps.fetch.outputs.title }}"
git push
- name: Summary
run: |
echo "## Problem Fetched Successfully" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "- **Number:** ${{ steps.fetch.outputs.number }}" >> "$GITHUB_STEP_SUMMARY"
echo "- **Title:** ${{ steps.fetch.outputs.title }}" >> "$GITHUB_STEP_SUMMARY"
echo "- **Difficulty:** ${{ steps.fetch.outputs.difficulty }}" >> "$GITHUB_STEP_SUMMARY"
echo "- **Topics:** ${{ steps.fetch.outputs.topics }}" >> "$GITHUB_STEP_SUMMARY"
echo "- **Link:** [${{ steps.fetch.outputs.slug }}](https://leetcode.com/problems/${{ steps.fetch.outputs.slug }}/)" >> "$GITHUB_STEP_SUMMARY"
echo "- **File:** \`problems/${{ steps.fetch.outputs.dir_name }}/problem.md\`" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
if [ "${{ steps.fetch.outputs.already_exists }}" == "true" ]; then
echo "ℹ️ **Note:** Problem.md already existed. No API call was made." >> "$GITHUB_STEP_SUMMARY"
fi