build(deps): bump actions/checkout from 4 to 6 (#2) #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Template Cleanup | |
| on: | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: write | |
| jobs: | |
| cleanup: | |
| # Skip on the template repo itself | |
| if: github.repository != 'axiomantic/template-python' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Sentinel guard | |
| id: guard | |
| run: | | |
| if [ ! -f .github/template-cleanup-marker ]; then | |
| echo "Marker missing; cleanup already ran. Exiting." | |
| echo "skip=true" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Compute new names | |
| if: steps.guard.outputs.skip != 'true' | |
| id: names | |
| run: | | |
| REPO_KEBAB="${GITHUB_REPOSITORY#*/}" | |
| REPO_SNAKE="${REPO_KEBAB//-/_}" | |
| echo "kebab=$REPO_KEBAB" >> "$GITHUB_OUTPUT" | |
| echo "snake=$REPO_SNAKE" >> "$GITHUB_OUTPUT" | |
| - name: Find/replace placeholders | |
| if: steps.guard.outputs.skip != 'true' | |
| env: | |
| KEBAB: ${{ steps.names.outputs.kebab }} | |
| SNAKE: ${{ steps.names.outputs.snake }} | |
| run: | | |
| set -euo pipefail | |
| # Rename source dir/file | |
| if [ -d src/project_name ]; then | |
| git mv src/project_name "src/${SNAKE}" | |
| fi | |
| if [ -f project_name.nimble ]; then | |
| git mv project_name.nimble "${SNAKE}.nimble" | |
| fi | |
| # Replace placeholders in tracked text files (python3 — portable across GNU/BSD sed) | |
| python3 - <<'PY' | |
| import os, pathlib, subprocess | |
| snake = os.environ["SNAKE"] | |
| kebab = os.environ["KEBAB"] | |
| tracked = subprocess.check_output( | |
| ["git", "ls-files", "-z"] | |
| ).split(b"\0") | |
| for raw in tracked: | |
| if not raw: | |
| continue | |
| p = pathlib.Path(raw.decode()) | |
| if not p.is_file(): | |
| continue | |
| try: | |
| text = p.read_text(encoding="utf-8") | |
| except (UnicodeDecodeError, OSError): | |
| continue # skip binary or unreadable files | |
| new = text.replace("project_name", snake).replace("project-name", kebab) | |
| if new != text: | |
| p.write_text(new, encoding="utf-8") | |
| PY | |
| # Remove the marker (idempotency) | |
| git rm -f .github/template-cleanup-marker | |
| - name: Commit and push | |
| if: steps.guard.outputs.skip != 'true' | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
| git add -A | |
| git commit -m "chore: template cleanup [skip ci]" | |
| git push |