From 68d0e1770bacbad2fec13e881b51c963ee9e0632 Mon Sep 17 00:00:00 2001 From: "sourcery-ai[bot]" Date: Tue, 24 Dec 2024 23:48:21 +0000 Subject: [PATCH] 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 --- .github/workflows/fetch-puzzle.yml | 75 ++++++++++++++++++++++++++++++ pyproject.toml | 6 ++- uv.lock | 23 +++++++++ 3 files changed, 102 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/fetch-puzzle.yml diff --git a/.github/workflows/fetch-puzzle.yml b/.github/workflows/fetch-puzzle.yml new file mode 100644 index 0000000..9e3546b --- /dev/null +++ b/.github/workflows/fetch-puzzle.yml @@ -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 }} diff --git a/pyproject.toml b/pyproject.toml index b8da22a..eae594c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -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" diff --git a/uv.lock b/uv.lock index e83d582..ef92626 100644 --- a/uv.lock +++ b/uv.lock @@ -303,6 +303,7 @@ dependencies = [ { name = "httpx" }, { name = "markdownify" }, { name = "typer" }, + { name = "types-beautifulsoup4" }, ] [package.dev-dependencies] @@ -318,6 +319,7 @@ requires-dist = [ { name = "httpx", specifier = ">=0.28.1" }, { name = "markdownify", specifier = ">=0.14.1" }, { name = "typer", specifier = ">=0.15.1" }, + { name = "types-beautifulsoup4", specifier = ">=4.12.0" }, ] [package.metadata.requires-dev] @@ -342,6 +344,27 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/d0/cc/0a838ba5ca64dc832aa43f727bd586309846b0ffb2ce52422543e6075e8a/typer-0.15.1-py3-none-any.whl", hash = "sha256:7994fb7b8155b64d3402518560648446072864beefd44aa2dc36972a5972e847", size = 44908 }, ] +[[package]] +name = "types-beautifulsoup4" +version = "4.12.0.20241020" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "types-html5lib" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/45/ae/5a7571c649cdd9f3c07d16790467a4fe1191f12a3ad7eecd1097cb8b1d9f/types-beautifulsoup4-4.12.0.20241020.tar.gz", hash = "sha256:158370d08d0cd448bd11b132a50ff5279237a5d4b5837beba074de152a513059", size = 11682 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/7c/43/0f96cdf27d7da7dea729af3476b7be997205765209651a42a4e1895bab72/types_beautifulsoup4-4.12.0.20241020-py3-none-any.whl", hash = "sha256:c95e66ce15a4f5f0835f7fbc5cd886321ae8294f977c495424eaf4225307fd30", size = 12170 }, +] + +[[package]] +name = "types-html5lib" +version = "1.1.11.20241018" +source = { registry = "https://pypi.org/simple" } +sdist = { url = "https://files.pythonhosted.org/packages/b6/9d/f6fbcc8246f5e46845b4f989c4e17e6fb3ce572f7065b185e515bf8a3be7/types-html5lib-1.1.11.20241018.tar.gz", hash = "sha256:98042555ff78d9e3a51c77c918b1041acbb7eb6c405408d8a9e150ff5beccafa", size = 11370 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/ba/7c/f862b1dc31268ef10fe95b43dcdf216ba21a592fafa2d124445cd6b92e93/types_html5lib-1.1.11.20241018-py3-none-any.whl", hash = "sha256:3f1e064d9ed2c289001ae6392c84c93833abb0816165c6ff0abfc304a779f403", size = 17292 }, +] + [[package]] name = "typing-extensions" version = "4.12.2"