|
| 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"}' |
0 commit comments