diff --git a/.github/workflows/submit-advent-of-code.yml b/.github/workflows/submit-advent-of-code.yml new file mode 100644 index 0000000..20a4ee9 --- /dev/null +++ b/.github/workflows/submit-advent-of-code.yml @@ -0,0 +1,91 @@ +name: Submit Advent of Code Solution + +on: + push: + branches: + - main + paths: + - 'puzzles/year_*/day_*/answer_part*.txt' + workflow_dispatch: + +permissions: + contents: write + issues: write + repository-dispatch: write + +env: + AOC_SESSION: ${{ secrets.AOC_SESSION }} + GH_TOKEN: ${{ secrets.USER_TOKEN }} + +jobs: + submit: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Set up uv + uses: astral-sh/setup-uv@v4 + + - name: Install dependencies + run: uv sync + + - name: Get changed files + id: changed-files + uses: tj-actions/changed-files@v42 + with: + files: puzzles/year_*/day_*/answer_part*.txt + + - name: Extract year, day and part from filename + id: extract-info + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then + echo "No file changes to process" + exit 0 + fi + + for file in ${{ steps.changed-files.outputs.all_changed_files }}; do + if [[ $file =~ puzzles/year_([0-9]+)/day_([0-9]+)/answer_part([12]).txt ]]; then + echo "year=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT + echo "day=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT + echo "part=${BASH_REMATCH[3]}" >> $GITHUB_OUTPUT + fi + done + + - name: Submit solution + id: submit + if: steps.extract-info.outputs.year != '' + continue-on-error: true + run: | + output=$(uv run advent_of_code.py submit ${{ steps.extract-info.outputs.year }} ${{ steps.extract-info.outputs.day }} ${{ steps.extract-info.outputs.part }}) + echo "submission_result=$output" >> $GITHUB_OUTPUT + + - name: Update results in README + if: steps.extract-info.outputs.year != '' + run: uv run advent_of_code.py update-results ${{ steps.extract-info.outputs.year }} + + - name: Download part 2 if part 1 was correct + id: download-part2 + if: steps.extract-info.outputs.part == '1' && steps.submit.outcome == 'success' + run: | + file_path=$(uv run advent_of_code.py download ${{ steps.extract-info.outputs.year }} ${{ steps.extract-info.outputs.day }}) + echo "file_path=$file_path" >> $GITHUB_OUTPUT + + - name: Configure Git + run: | + git config --global user.name 'github-actions[bot]' + git config --global user.email 'github-actions[bot]@users.noreply.github.com' + + - name: Commit and push changes + run: | + git add puzzles/year_${{ steps.extract-info.outputs.year }}/day_${{ steps.extract-info.outputs.day }} + git add README.md + git commit -m "Update puzzle files for year ${{ steps.extract-info.outputs.year }} day ${{ steps.extract-info.outputs.day }}" + git push + + - name: Trigger create-puzzle-issue workflow + if: steps.download-part2.outputs.file_path != '' + uses: peter-evans/repository-dispatch@v2 + with: + token: ${{ env.GH_TOKEN }} + event-type: create-puzzle-issue + client-payload: '{"year": "${{ steps.extract-info.outputs.year }}", "day": "${{ steps.extract-info.outputs.day }}", "part": "2"}' diff --git a/pyproject.toml b/pyproject.toml index b8da22a..2e4e759 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,6 +41,8 @@ warn_unreachable = true [tool.ruff] target-version = "py312" line-length = 100 + +[tool.ruff.lint] select = ["ALL"] ignore = ["D203", "D212"] 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"