format-command #259
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
| # Format the codes using slash command | |
| # | |
| # This workflow is triggered in a PR if the slash command `/format` is used. | |
| # | |
| name: format-command | |
| on: | |
| repository_dispatch: | |
| types: [format-command] | |
| permissions: {} | |
| jobs: | |
| format: | |
| permissions: | |
| contents: write # for Git to git push | |
| runs-on: ubuntu-latest | |
| steps: | |
| # Generate token from GenericMappingTools bot | |
| - uses: actions/create-github-app-token@v2.2.1 | |
| id: generate-token | |
| with: | |
| app-id: ${{ secrets.APP_ID }} | |
| private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
| # Checkout the pull request branch | |
| - uses: actions/checkout@v6.0.1 | |
| with: | |
| token: ${{ steps.generate-token.outputs.token }} | |
| repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }} | |
| ref: ${{ github.event.client_payload.pull_request.head.ref }} | |
| persist-credentials: true | |
| # Setup Python environment | |
| - name: Set up Python and install dependencies | |
| uses: actions/setup-python@v6.1.0 | |
| with: | |
| python-version: '3.14' | |
| pip-install: ruff prek | |
| - name: List installed packages | |
| run: python -m pip list | |
| # Run "make format" and commit the change to the PR branch | |
| - name: Commit to the PR branch if any changes | |
| run: | | |
| # Use '|| true' to ensure the workflow doesn't stop when `make format` fails | |
| make format || true | |
| if [[ $(git ls-files -m) ]]; then | |
| git config --global user.name 'actions-bot' | |
| git config --global user.email '58130806+actions-bot@users.noreply.github.com' | |
| git commit -am "[format-command] fixes" | |
| git push | |
| fi |