Add version_persistent dependency guard and GH Actions test for ver…
#1866
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
| # Automatic code formatting | |
| name: "Code formatting" | |
| on: | |
| push: | |
| branches: | |
| - "**" | |
| env: | |
| python_version: "3.9" | |
| jobs: | |
| format-code: | |
| if: github.actor != 'mlc-automations' && github.repository_owner == 'mlcommons' | |
| 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: Lint MLC metas | |
| run: | | |
| pip install mlcflow | |
| mlc lint script --all | |
| git add -- '*/meta.yaml' '*/meta.yml' 2>/dev/null || true | |
| - 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: Format modified C++ files | |
| env: | |
| filter: ${{ github.event.before }} | |
| run: | | |
| for FILE in $(git diff --name-only $filter | grep -E '.*\.(cc|cpp|h|hpp)$') | |
| do | |
| # Check if the file still exists in the working tree | |
| if [ -f "$FILE" ]; then | |
| clang-format -i -style=file $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 |