Skip to content

Commit 68d0e17

Browse files
CI: Add workflow to fetch Advent of Code puzzles
CI: - Set up a workflow to automatically fetch Advent of Code puzzles daily at 5pm UTC during December and allow manual dispatch. Resolves #4
1 parent a5f742b commit 68d0e17

File tree

3 files changed

+102
-2
lines changed

3 files changed

+102
-2
lines changed

Diff for: .github/workflows/fetch-puzzle.yml

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
name: Fetch Puzzle
2+
3+
on:
4+
schedule:
5+
# Run at 17:00 UTC (5pm) from December 1-25
6+
- cron: '0 17 1-25 12 *'
7+
workflow_dispatch:
8+
inputs:
9+
year:
10+
description: 'Year of puzzle'
11+
required: true
12+
type: string
13+
day:
14+
description: 'Day of puzzle'
15+
required: true
16+
type: string
17+
18+
permissions:
19+
contents: write
20+
issues: write
21+
22+
env:
23+
AOC_SESSION: ${{ secrets.AOC_SESSION }}
24+
25+
jobs:
26+
fetch-puzzle:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
32+
- name: Set up Python with uv
33+
uses: astral-sh/setup-uv@v4
34+
with:
35+
python-version: '3.12'
36+
37+
- name: Install dependencies
38+
run: uv sync
39+
40+
- name: Download puzzle
41+
id: download
42+
run: |
43+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
44+
YEAR="${{ github.event.inputs.year }}"
45+
DAY="${{ github.event.inputs.day }}"
46+
else
47+
YEAR=$(date +%Y)
48+
DAY=$(date +%-d)
49+
fi
50+
echo "Downloading puzzle for Year: $YEAR, Day: $DAY"
51+
PART=$(uv run python advent_of_code.py download "$YEAR" "$DAY")
52+
echo "part=$PART" >> "$GITHUB_OUTPUT"
53+
echo "year=$YEAR" >> "$GITHUB_OUTPUT"
54+
echo "day=$DAY" >> "$GITHUB_OUTPUT"
55+
56+
- name: Commit puzzle
57+
run: |
58+
git config --global user.name 'github-actions[bot]'
59+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
60+
git add puzzles/
61+
if git diff --staged --quiet; then
62+
echo "No changes to commit"
63+
else
64+
git commit -m "Add puzzle for Year ${{ steps.download.outputs.year }} Day ${{ steps.download.outputs.day }}"
65+
git push
66+
fi
67+
68+
- name: Trigger create puzzle issue workflow
69+
run: |
70+
gh workflow run create-puzzle-issue.yml \
71+
-f year=${{ steps.download.outputs.year }} \
72+
-f day=${{ steps.download.outputs.day }} \
73+
-f part=${{ steps.download.outputs.part }}
74+
env:
75+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Diff for: pyproject.toml

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ dependencies = [
99
"httpx>=0.28.1",
1010
"markdownify>=0.14.1",
1111
"typer>=0.15.1",
12-
"types-beautifulsoup4>=4.12.3",
12+
"types-beautifulsoup4>=4.12.0",
1313
]
1414

1515
[dependency-groups]
@@ -41,8 +41,10 @@ warn_unreachable = true
4141
[tool.ruff]
4242
target-version = "py312"
4343
line-length = 100
44+
45+
[tool.ruff.lint]
4446
select = ["ALL"]
45-
ignore = ["D203", "D212"]
47+
ignore = ["D203", "D212", "COM812", "ISC001"]
4648

4749
[tool.ruff.format]
4850
quote-style = "double"

Diff for: uv.lock

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)