Fixes to submission generation docs #491
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
# Automatic code formatting | |
name: "Code formatting" | |
on: | |
push: | |
branches: | |
- "**" | |
env: | |
python_version: "3.9" | |
jobs: | |
format-code: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Retrieve secrets from Keeper | |
id: ksecrets | |
uses: Keeper-Security/ksm-action@master | |
with: | |
keeper-secret-config: ${{ secrets.KSM_CONFIG }} | |
secrets: |- | |
v2h4jKiZlJywDSoKzRMnRw/field/Access Token > env:PAT # Fetch PAT and store in environment variable | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Python ${{ env.python_version }} | |
uses: actions/setup-python@v3 | |
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" ] && [ "$FILE" != "tools/submission/power/power_checker.py" ]; 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 | |
env: | |
PAT: ${{ env.PAT }} # Use PAT fetched from Keeper | |
run: | | |
HAS_CHANGES=$(git diff --staged --name-only) | |
if [ ${#HAS_CHANGES} -gt 0 ]; then | |
git config --global user.name mlcommons-bot | |
git config --global user.email "[email protected]" | |
# Commit changes | |
git commit -m '[Automated Commit] Format Codebase' | |
# Use the PAT to push changes | |
git push https://x-access-token:${PAT}@github.com/${{ github.repository }} HEAD:${{ github.ref_name }} | |
fi |