Skip to content

Commit c2eb6f2

Browse files
Add workflow to submit Advent of Code solutions
Add a GitHub Actions workflow to automatically submit Advent of Code solutions, update the README with results, and download the next part of the puzzle. New Features: - Automatically download the next part of the puzzle after successfully submitting the current part. Enhancements: - Update the README file with the latest Advent of Code results. CI: - Set up a new GitHub Actions workflow to submit Advent of Code puzzle solutions. Resolves #5
1 parent a5f742b commit c2eb6f2

File tree

3 files changed

+117
-1
lines changed

3 files changed

+117
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: Submit Advent of Code Solution
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
paths:
8+
- 'puzzles/year_*/day_*/answer_part*.txt'
9+
workflow_dispatch:
10+
11+
permissions:
12+
contents: write
13+
issues: write
14+
repository-dispatch: write
15+
16+
env:
17+
AOC_SESSION: ${{ secrets.AOC_SESSION }}
18+
GH_TOKEN: ${{ secrets.USER_TOKEN }}
19+
20+
jobs:
21+
submit:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Set up uv
27+
uses: astral-sh/setup-uv@v4
28+
29+
- name: Install dependencies
30+
run: uv sync
31+
32+
- name: Get changed files
33+
id: changed-files
34+
uses: tj-actions/changed-files@v42
35+
with:
36+
files: puzzles/year_*/day_*/answer_part*.txt
37+
38+
- name: Extract year, day and part from filename
39+
id: extract-info
40+
run: |
41+
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
42+
echo "No file changes to process"
43+
exit 0
44+
fi
45+
46+
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
47+
if [[ $file =~ puzzles/year_([0-9]+)/day_([0-9]+)/answer_part([12]).txt ]]; then
48+
echo "year=${BASH_REMATCH[1]}" >> $GITHUB_OUTPUT
49+
echo "day=${BASH_REMATCH[2]}" >> $GITHUB_OUTPUT
50+
echo "part=${BASH_REMATCH[3]}" >> $GITHUB_OUTPUT
51+
fi
52+
done
53+
54+
- name: Submit solution
55+
id: submit
56+
if: steps.extract-info.outputs.year != ''
57+
continue-on-error: true
58+
run: |
59+
output=$(uv run advent_of_code.py submit ${{ steps.extract-info.outputs.year }} ${{ steps.extract-info.outputs.day }} ${{ steps.extract-info.outputs.part }})
60+
echo "submission_result=$output" >> $GITHUB_OUTPUT
61+
62+
- name: Update results in README
63+
if: steps.extract-info.outputs.year != ''
64+
run: uv run advent_of_code.py update-results ${{ steps.extract-info.outputs.year }}
65+
66+
- name: Download part 2 if part 1 was correct
67+
id: download-part2
68+
if: steps.extract-info.outputs.part == '1' && steps.submit.outcome == 'success'
69+
run: |
70+
file_path=$(uv run advent_of_code.py download ${{ steps.extract-info.outputs.year }} ${{ steps.extract-info.outputs.day }})
71+
echo "file_path=$file_path" >> $GITHUB_OUTPUT
72+
73+
- name: Configure Git
74+
run: |
75+
git config --global user.name 'github-actions[bot]'
76+
git config --global user.email 'github-actions[bot]@users.noreply.github.com'
77+
78+
- name: Commit and push changes
79+
run: |
80+
git add puzzles/year_${{ steps.extract-info.outputs.year }}/day_${{ steps.extract-info.outputs.day }}
81+
git add README.md
82+
git commit -m "Update puzzle files for year ${{ steps.extract-info.outputs.year }} day ${{ steps.extract-info.outputs.day }}"
83+
git push
84+
85+
- name: Trigger create-puzzle-issue workflow
86+
if: steps.download-part2.outputs.file_path != ''
87+
uses: peter-evans/repository-dispatch@v2
88+
with:
89+
token: ${{ env.GH_TOKEN }}
90+
event-type: create-puzzle-issue
91+
client-payload: '{"year": "${{ steps.extract-info.outputs.year }}", "day": "${{ steps.extract-info.outputs.day }}", "part": "2"}'

pyproject.toml

+3-1
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,6 +41,8 @@ warn_unreachable = true
4141
[tool.ruff]
4242
target-version = "py312"
4343
line-length = 100
44+
45+
[tool.ruff.lint]
4446
select = ["ALL"]
4547
ignore = ["D203", "D212"]
4648

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)