|
| 1 | +name: Fetch Puzzle |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run at 17:00 UTC (5pm) from December 1-25 |
| 6 | + - cron: '0 17 1-25 12 *' |
| 7 | + workflow_dispatch: |
| 8 | + inputs: |
| 9 | + year: |
| 10 | + description: 'Year of puzzle' |
| 11 | + required: true |
| 12 | + type: string |
| 13 | + day: |
| 14 | + description: 'Day of puzzle' |
| 15 | + required: true |
| 16 | + type: string |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: write |
| 20 | + issues: write |
| 21 | + |
| 22 | +env: |
| 23 | + AOC_SESSION: ${{ secrets.AOC_SESSION }} |
| 24 | + |
| 25 | +jobs: |
| 26 | + fetch-puzzle: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + steps: |
| 29 | + - name: Checkout repository |
| 30 | + uses: actions/checkout@v4 |
| 31 | + |
| 32 | + - name: Set up Python with uv |
| 33 | + uses: astral-sh/setup-uv@v4 |
| 34 | + with: |
| 35 | + python-version: '3.12' |
| 36 | + |
| 37 | + - name: Install dependencies |
| 38 | + run: uv sync |
| 39 | + |
| 40 | + - name: Download puzzle |
| 41 | + id: download |
| 42 | + run: | |
| 43 | + if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then |
| 44 | + YEAR="${{ github.event.inputs.year }}" |
| 45 | + DAY="${{ github.event.inputs.day }}" |
| 46 | + else |
| 47 | + YEAR=$(date +%Y) |
| 48 | + DAY=$(date +%-d) |
| 49 | + fi |
| 50 | + echo "Downloading puzzle for Year: $YEAR, Day: $DAY" |
| 51 | + PART=$(uv run python advent_of_code.py download "$YEAR" "$DAY") |
| 52 | + echo "part=$PART" >> "$GITHUB_OUTPUT" |
| 53 | + echo "year=$YEAR" >> "$GITHUB_OUTPUT" |
| 54 | + echo "day=$DAY" >> "$GITHUB_OUTPUT" |
| 55 | +
|
| 56 | + - name: Commit puzzle |
| 57 | + run: | |
| 58 | + git config --global user.name 'github-actions[bot]' |
| 59 | + git config --global user.email 'github-actions[bot]@users.noreply.github.com' |
| 60 | + git add puzzles/ |
| 61 | + if git diff --staged --quiet; then |
| 62 | + echo "No changes to commit" |
| 63 | + else |
| 64 | + git commit -m "Add puzzle for Year ${{ steps.download.outputs.year }} Day ${{ steps.download.outputs.day }}" |
| 65 | + git push |
| 66 | + fi |
| 67 | +
|
| 68 | + - name: Trigger create puzzle issue workflow |
| 69 | + run: | |
| 70 | + gh workflow run create-puzzle-issue.yml \ |
| 71 | + -f year=${{ steps.download.outputs.year }} \ |
| 72 | + -f day=${{ steps.download.outputs.day }} \ |
| 73 | + -f part=${{ steps.download.outputs.part }} |
| 74 | + env: |
| 75 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments