Skip to content

Commit

Permalink
CI: Add workflow to fetch Advent of Code puzzles
Browse files Browse the repository at this point in the history
CI:
- Set up a workflow to automatically fetch Advent of Code puzzles daily at 5pm UTC during December and allow manual dispatch.

Resolves #4
  • Loading branch information
sourcery-ai[bot] committed Dec 24, 2024
1 parent a5f742b commit 68d0e17
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 2 deletions.
75 changes: 75 additions & 0 deletions .github/workflows/fetch-puzzle.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Fetch Puzzle

on:
schedule:
# Run at 17:00 UTC (5pm) from December 1-25
- cron: '0 17 1-25 12 *'
workflow_dispatch:
inputs:
year:
description: 'Year of puzzle'
required: true
type: string
day:
description: 'Day of puzzle'
required: true
type: string

permissions:
contents: write
issues: write

env:
AOC_SESSION: ${{ secrets.AOC_SESSION }}

jobs:
fetch-puzzle:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python with uv
uses: astral-sh/setup-uv@v4
with:
python-version: '3.12'

- name: Install dependencies
run: uv sync

- name: Download puzzle
id: download
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
YEAR="${{ github.event.inputs.year }}"
DAY="${{ github.event.inputs.day }}"
else
YEAR=$(date +%Y)
DAY=$(date +%-d)
fi
echo "Downloading puzzle for Year: $YEAR, Day: $DAY"
PART=$(uv run python advent_of_code.py download "$YEAR" "$DAY")
echo "part=$PART" >> "$GITHUB_OUTPUT"
echo "year=$YEAR" >> "$GITHUB_OUTPUT"
echo "day=$DAY" >> "$GITHUB_OUTPUT"
- name: Commit puzzle
run: |
git config --global user.name 'github-actions[bot]'
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
git add puzzles/
if git diff --staged --quiet; then
echo "No changes to commit"
else
git commit -m "Add puzzle for Year ${{ steps.download.outputs.year }} Day ${{ steps.download.outputs.day }}"
git push
fi
- name: Trigger create puzzle issue workflow
run: |
gh workflow run create-puzzle-issue.yml \
-f year=${{ steps.download.outputs.year }} \
-f day=${{ steps.download.outputs.day }} \
-f part=${{ steps.download.outputs.part }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"httpx>=0.28.1",
"markdownify>=0.14.1",
"typer>=0.15.1",
"types-beautifulsoup4>=4.12.3",
"types-beautifulsoup4>=4.12.0",
]

[dependency-groups]
Expand Down Expand Up @@ -41,8 +41,10 @@ warn_unreachable = true
[tool.ruff]
target-version = "py312"
line-length = 100

[tool.ruff.lint]
select = ["ALL"]
ignore = ["D203", "D212"]
ignore = ["D203", "D212", "COM812", "ISC001"]

[tool.ruff.format]
quote-style = "double"
Expand Down
23 changes: 23 additions & 0 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 68d0e17

Please sign in to comment.