Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/cla.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
path-to-signatures: 'cla-bot/v1/cla.json'
# branch should not be protected
branch: 'main'
allowlist: user1,bot*
allowlist: user1,mlc-automations,bot*
remote-organization-name: mlcommons
remote-repository-name: systems

Expand Down
60 changes: 60 additions & 0 deletions .github/workflows/format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Automatic code formatting
name: "Code formatting"
on:
push:
branches:
- "**"

env:
python_version: "3.9"

jobs:
format-code:
if: github.actor != 'mlc-automations'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Generate GitHub App token
id: app-token
uses: actions/create-github-app-token@v1
with:
app-id: ${{ secrets.MLC_AUTOMATIONS_APP_ID }}
private-key: ${{ secrets.MLC_AUTOMATIONS_PRIVATE_KEY }}

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Set up Python ${{ env.python_version }}
uses: actions/setup-python@v5
with:
python-version: ${{ env.python_version }}

- name: Format modified Python files
env:
filter: ${{ github.event.before }}
run: |
python3 -m pip install autopep8
for FILE in $(git diff --name-only $filter | grep -E '.*\.py$')
do
# Check if the file still exists in the working tree
if [ -f "$FILE" ]; then
autopep8 --in-place -a "$FILE"
git add "$FILE"
fi
done

- name: Commit and push changes
run: |
HAS_CHANGES=$(git diff --staged --name-only)
if [ ${#HAS_CHANGES} -gt 0 ]; then
# Use the GitHub actor's name and email
git config --global user.name mlc-automations
git config --global user.email "3246381+mlc-automations@users.noreply.github.com"
# Commit changes
git commit -m '[Automated Commit] Format Codebase'
git push
fi
Loading
Loading