format-command #246
This file contains 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] | |
jobs: | |
format: | |
runs-on: ubuntu-latest | |
steps: | |
# Generate token from GenericMappingTools bot | |
- uses: actions/create-github-app-token@v1.11.1 | |
id: generate-token | |
with: | |
app-id: ${{ secrets.APP_ID }} | |
private-key: ${{ secrets.APP_PRIVATE_KEY }} | |
# Checkout the pull request branch | |
- uses: actions/checkout@v4.2.2 | |
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 }} | |
# Setup Python environment | |
- uses: actions/setup-python@v5.3.0 | |
with: | |
python-version: '3.13' | |
# Install formatting tools | |
- name: Install formatting tools | |
run: | | |
python -m pip install ruff pre-commit | |
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: | | |
make format | |
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 |