Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Automated Black Updates (#396)

Naveen M K25a4c6f12496
diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml
new file mode 100644
index 000000000..9178896a9
--- /dev/null
+++ b/.github/workflows/black.yml
@@ -0,0 +1,79 @@
+name: black
+on:
+ workflow_dispatch:
+ schedule:
+ - cron: "0 0 * * *"
+
+jobs:
+ format:
+ runs-on: windows-latest
+ steps:
+ - name: Checkout the repository
+ uses: actions/checkout@v2
+ with:
+ fetch-depth: 0
+
+ - name: Set up Python
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.8
+
+ - name: Install black
+ run: pip install black
+
+ - name: Black
+ run: |
+ black manim tests example_scenes
+
+ - name: Check for modified files
+ shell: bash
+ id: git-check
+ run: |
+ echo ::set-output name=modified::$(if git diff-index --quiet HEAD --; then echo "false"; else echo "true"; fi)
+ echo ::set-output name=filechange::$(git ls-files -m)
+
+ - name: Print Black Version if Failed
+ shell: bash
+ if: steps.git-check.outputs.modified == 'true'
+ run: |
+ blackVer=$(black --version)
+ blackVersion=$(python -c "print('${blackVer}'.split()[2])")
+ date=$(python -c "import time;print(time.localtime().tm_mday)")
+ pushBranch="black-${blackVersion}-${date}"
+ git config user.name "github-actions"
+ git config user.email "[email protected]"
+ git checkout -B "$pushBranch"
+ git add .
+ git commit -m "Running Black On Master"
+
+ - name: Push branch
+ if: steps.git-check.outputs.modified == 'true'
+ shell: bash
+ run: |
+ blackVer=$(black --version)
+ blackVersion=$(python -c "print('${blackVer}'.split()[2])")
+ date=$(python -c "import time;print(time.localtime().tm_mday)")
+ pushBranch="black-${blackVersion}-${date}"
+ git push -u origin "${pushBranch}" --force
+
+ - name: Make a PR
+ if: steps.git-check.outputs.modified == 'true'
+ env:
+ access_token: ${{ secrets.GITHUB_TOKEN }}
+ file_change: ${{ steps.git-check.outputs.filechange }}
+ run: |
+ $blackVer = black --version
+ $blackVersion = python -c "print('$($blackVer)'.split()[2])"
+ $date = python -c "import time;print(time.localtime().tm_mday)"
+ $pushBranch="black-$($blackVersion)-$($date)"
+ $postContents = @{title="Automated PR: Autoformat with black";
+ head="ManimCommunity:$($pushBranch)";
+ base="master";
+ body="This an automated pull requests. Files Changed are `n `n ```````n$($env:file_change)`n``````"
+ } | ConvertTo-Json -Compress
+ echo "$postContents"
+ Invoke-WebRequest `
+ -Method POST `
+ -Headers @{ "Accept" = "application/vnd.github.v3+json"; "Authorization"= "token $($env:access_token)"}`
+ -Uri https://api.github.com/repos/ManimCommunity/manim/pulls `
+ -Body "$($postContents)"