|
| 1 | +# Daily refresh of the Hacktoberfest 2026 open-PR cleanup tracker. |
| 2 | +# Ticks off any tracked pull request that has since been merged/closed, and |
| 3 | +# rewrites the "Automated statistics" section (open issue/PR counts + the top |
| 4 | +# three `awaiting reviews` directories). The job fails on purpose once |
| 5 | +# Hacktoberfest 2026 has begun (>= 2026-10-01), which is the signal to retire it. |
| 6 | +name: hacktoberfest_prep |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + paths: |
| 11 | + - ".github/workflows/hacktoberfest_prep.yml" |
| 12 | + - "scripts/hacktoberfest_prep_update.py" |
| 13 | + pull_request: |
| 14 | + paths: |
| 15 | + - ".github/workflows/hacktoberfest_prep.yml" |
| 16 | + - "scripts/hacktoberfest_prep_update.py" |
| 17 | + schedule: |
| 18 | + - cron: "50 11 * * *" # 11:50 UTC every day |
| 19 | + workflow_dispatch: # allow a manual run while testing |
| 20 | + |
| 21 | +permissions: |
| 22 | + contents: write |
| 23 | + pull-requests: write |
| 24 | + |
| 25 | +jobs: |
| 26 | + hacktoberfest-prep: |
| 27 | + # No point running on forks — this pushes to the repo's own docs file. |
| 28 | + if: github.repository == 'TheAlgorithms/Python' |
| 29 | + runs-on: ubuntu-latest |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v7 |
| 32 | + with: |
| 33 | + persist-credentials: false |
| 34 | + - uses: actions/setup-python@v7 |
| 35 | + with: |
| 36 | + python-version-file: .python-version |
| 37 | + allow-prereleases: true |
| 38 | + - name: Install dependencies |
| 39 | + run: python -m pip install --upgrade "httpx2>=2.0.1" |
| 40 | + - name: Update the tracker |
| 41 | + id: update |
| 42 | + env: |
| 43 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 44 | + GITHUB_REPOSITORY: ${{ github.repository }} |
| 45 | + # Don't let the intentional post-Oct-1 failure stop the commit step; |
| 46 | + # capture the exit code and re-raise it after pushing any changes. |
| 47 | + run: | |
| 48 | + set +e |
| 49 | + python scripts/hacktoberfest_prep_update.py |
| 50 | + echo "exit_code=$?" >> "$GITHUB_OUTPUT" |
| 51 | + # Dry run on push / pull_request: show the diff the script produced but |
| 52 | + # do NOT commit or push. This lets a PR prove the tracker still gathers |
| 53 | + # its data and rewrites docs/hacktober_2026_prep.md correctly without |
| 54 | + # leaving a permanent commit. Only the schedule/manual runs persist. |
| 55 | + - name: Show changes (dry run) |
| 56 | + if: github.event_name == 'push' || github.event_name == 'pull_request' |
| 57 | + run: | |
| 58 | + echo "Dry run (${{ github.event_name }}): showing git diff, not committing." |
| 59 | + git --no-pager diff -- docs/hacktober_2026_prep.md |
| 60 | + if git diff --quiet -- docs/hacktober_2026_prep.md; then |
| 61 | + echo "No changes to docs/hacktober_2026_prep.md." |
| 62 | + fi |
| 63 | + # `master` is a protected branch: direct pushes are rejected with |
| 64 | + # `GH006: Protected branch update failed ... Changes must be made through |
| 65 | + # a pull request`. So instead of committing straight to master, persist |
| 66 | + # the refreshed tracker on a single rolling branch and open — or, since |
| 67 | + # re-pushing the branch updates the existing PR in place, leave open — one |
| 68 | + # pull request. Uses the bundled `gh` CLI rather than a third-party |
| 69 | + # action (see zizmor's "superfluous actions" audit). |
| 70 | + - name: Open or update the tracker pull request |
| 71 | + if: github.event_name != 'push' && github.event_name != 'pull_request' |
| 72 | + env: |
| 73 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 74 | + BRANCH: chore/hacktoberfest-2026-prep-refresh |
| 75 | + run: | |
| 76 | + set -euo pipefail |
| 77 | + if git diff --quiet -- docs/hacktober_2026_prep.md; then |
| 78 | + echo "No changes to docs/hacktober_2026_prep.md; nothing to persist." |
| 79 | + exit 0 |
| 80 | + fi |
| 81 | + git config --global user.name "$GITHUB_ACTOR" |
| 82 | + git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" |
| 83 | + # `actions/checkout` runs with `persist-credentials: false`, so git has |
| 84 | + # no token to authenticate the push below (it fails with |
| 85 | + # `fatal: could not read Username for 'https://github.com'`). Wire the |
| 86 | + # bundled `gh` in as git's credential helper so `git push` reuses |
| 87 | + # GH_TOKEN — no third-party action and no token baked into the remote URL. |
| 88 | + gh auth setup-git |
| 89 | + git switch -c "$BRANCH" |
| 90 | + git add docs/hacktober_2026_prep.md |
| 91 | + git commit -m "chore: refresh Hacktoberfest 2026 prep tracker" |
| 92 | + # Force-push so the rolling branch always carries just the latest |
| 93 | + # snapshot on top of master; this also updates any open PR in place. |
| 94 | + git push --force origin "$BRANCH" |
| 95 | + if [ -z "$(gh pr list --head "$BRANCH" --state open --json number --jq '.[].number')" ]; then |
| 96 | + gh pr create \ |
| 97 | + --base master \ |
| 98 | + --head "$BRANCH" \ |
| 99 | + --title "chore: refresh Hacktoberfest 2026 prep tracker" \ |
| 100 | + --body "Automated daily refresh of the Hacktoberfest 2026 open-PR cleanup tracker (\`docs/hacktober_2026_prep.md\`): ticks off any tracked pull request that has since been merged/closed and rewrites the **Automated statistics** section. |
| 101 | +
|
| 102 | + This PR is updated in place by the \`hacktoberfest_prep\` workflow, so it always reflects the latest scheduled run. Merge it whenever you want to capture the current snapshot." |
| 103 | + else |
| 104 | + echo "Open tracker PR already exists; force-push updated it in place." |
| 105 | + fi |
| 106 | + - name: Propagate the script's exit code |
| 107 | + env: |
| 108 | + UPDATE_EXIT_CODE: ${{ steps.update.outputs.exit_code }} |
| 109 | + run: exit ${UPDATE_EXIT_CODE} |
0 commit comments