Create Python.yml #18
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: π¬π§ On Push | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| inputs: | |
| banter_mode: | |
| description: 'Select banter style' | |
| required: true | |
| default: 'random' | |
| type: choice | |
| options: | |
| - random | |
| - british | |
| - pirate | |
| - cockney | |
| permissions: | |
| contents: write | |
| env: | |
| GIT_USER: "British Banter Bot π¬π§" | |
| GIT_EMAIL: "banter@example.com" | |
| jobs: | |
| on-push: | |
| name: Update README & Generate Banter | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v6 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "${{ env.GIT_USER }}" | |
| git config user.email "${{ env.GIT_EMAIL }}" | |
| - name: Count Python files and lines | |
| id: stats | |
| run: | | |
| PY_FILES=$(find . -name "*.py" -type f | wc -l) | |
| TOTAL_LINES=$(find . -name "*.py" -type f -exec cat {} + | wc -l) | |
| echo "py_files=$PY_FILES" >> $GITHUB_OUTPUT | |
| echo "total_lines=$TOTAL_LINES" >> $GITHUB_OUTPUT | |
| - name: Update README.md | |
| run: | | |
| STATS="π Total lines of code: ${{ steps.stats.outputs.total_lines }}\nπ Number of Python files: ${{ steps.stats.outputs.py_files }}" | |
| DATE="π Last updated: $(date -u +"%Y-%m-%d %H:%M UTC")" | |
| sed -i "/<!-- STATS:START -->/,/<!-- STATS:END -->/c\\<!-- STATS:START -->\n$STATS\n<!-- STATS:END -->" README.md | |
| sed -i "/<!-- UPDATED:START -->/,/<!-- UPDATED:END -->/c\\<!-- UPDATED:START -->\n$DATE\n<!-- UPDATED:END -->" README.md | |
| - name: Generate Banter & Commit | |
| run: | | |
| MODE="${{ github.event.inputs.banter_mode || 'random' }}" | |
| BRITISH=( | |
| "fix: squashed that bug like a proper legend ππ οΈπ₯" | |
| "feat: added a cheeky new feature, sorted innit bruv π§β¨π" | |
| "chore: tidied up the config, all neat now π₯π§π§Ή" | |
| "docs: wrote it all down like a true gent πππ§" | |
| "refactor: cleaned up the mess, proper tidy π§ππ§" | |
| ) | |
| PIRATE=( | |
| "fix: arrr, slayed that bug like a fearless buccaneer π΄ββ οΈβοΈπ" | |
| "feat: shiver me timbers, added treasure of a feature π΄ββ οΈπβ¨" | |
| "chore: swab the deck, cleaned up this code proper like π§Ήβπ΄ββ οΈ" | |
| "docs: wrote it down like a captain's log, it is ππ΄ββ οΈβ" | |
| "refactor: plundered and pillaged the codebase, savvy πΊοΈπβ¨" | |
| ) | |
| COCKNEY=( | |
| "fix: blimey, fixed that bug innit, ain't it sweet πͺπ’β¨" | |
| "feat: cor strike a light, got a new feature for ya πβ¨π" | |
| "chore: tidy up the gaff, clean as a whistle now mate π§Ήβ¨π©" | |
| "docs: wrote it all down proper, like a London geezer ππ©β¨" | |
| "refactor: rearranged the crib, all spick and span bruv π―πͺπ©" | |
| ) | |
| if [ "$MODE" = "random" ]; then | |
| MODES=("british" "pirate" "cockney") | |
| MODE=${MODES[$((RANDOM % 3))]} | |
| fi | |
| case "$MODE" in | |
| pirate) POOL=("${PIRATE[@]}") ;; | |
| cockney) POOL=("${COCKNEY[@]}") ;; | |
| *) POOL=("${BRITISH[@]}") ;; | |
| esac | |
| MSG="${POOL[$((RANDOM % ${#POOL[@]}))]}" | |
| git add README.md | |
| if git diff --cached --quiet; then | |
| echo "No README changes to commit" | |
| exit 0 | |
| fi | |
| git commit -m "$MSG" | |
| git push --force-with-lease origin main |