Просмотр исходного кода

Github action: autoblack and isort

Automatically runs black/isort on any pull request or push to master.
Nathan Beals 5 лет назад
Родитель
Сommit
7a602439b8
1 измененных файлов с 12 добавлено и 70 удалено
  1. 12 70
      .github/workflows/commit-format.yml

+ 12 - 70
.github/workflows/commit-format.yml

@@ -5,91 +5,33 @@ name: Commit Format and Import Sort
 # Controls when the action will run. 
 on:
   # Triggers the workflow on push or pull request events but only for the master branch
-  push:
-    branches: [ master ]
   pull_request:
     branches: [ master ]
-
-  # Allows you to run this workflow manually from the Actions tab
-  workflow_dispatch:
+  push:
+    branches: [ master ]
 
 # A workflow run is made up of one or more jobs that can run sequentially or in parallel
 jobs:
-  # This workflow contains a single job called "build"
-  build:
-    # The type of runner that the job will run on
+  check:
     runs-on: ubuntu-latest
-
-    # Steps represent a sequence of tasks that will be executed as part of the job
     steps:
-      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
       - uses: actions/checkout@v2
-        # with: # https://github.com/stefanzweifel/git-auto-commit-action#checkout-the-correct-branch
-            # ref: ${{ github.head_ref }}
-      
+        with:  # https://github.com/stefanzweifel/git-auto-commit-action#checkout-the-correct-branch
+            ref: ${{ github.head_ref }}
       - uses: actions/setup-python@v2
-        with:
-          python-version: '3.x' # Version range or exact version of a Python version to use, using SemVer's version range syntax
-          architecture: 'x64' # optional x64 or x86. Defaults to x64 if not specified
-          
-      - uses: Gr1N/setup-poetry@v4
-      
-      - run: poetry install
-        
-#       - run: poetry --version
-        
-      # - run: ls -la
-
-      - run: poetry run black --check .
-        
-      - name: Format if check failed
+      - run: pip install black isort
+      - run: black --check .
+      - run: isort --check .
+      - name: Commit isort changes to pull request
         if: failure()
         run: |
-          printenv | grep GITHUB
           git config --global user.name 'ndbeals'
           git config --global user.email 'ndbeals@users.noreply.github.com'          
           git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
-          git remote -v
-          git branch
-          git status
-          poetry run black .
-          git status
+          isort .
+          black .
           echo ready to commit
-          git add .
-          git commit -m "Code reformatted with psf/black"
-          echo ready to push
-          git push
-          # git push --force origin
-        
-      - name: Isort
-        run: poetry run isort --check .
-
-      - name: Isort if check failed
-        if: failure()
-        run: | 
-          printenv | grep GITHUB
-          git config --global user.name 'ndbeals'
-          git config --global user.email 'ndbeals@users.noreply.github.com'          
-          git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/$GITHUB_REPOSITORY
-          git remote -v
-          git branch
-          git status
-          poetry run isort --check .
+          git commit -am "Code formatted with black, imports sorted with isort"
           git status
-          echo ready to commit
-          git add .
-          git commit -m "Imports sorted with isort"
           echo ready to push
           git push
-          # git push --force origin
-      
-      
-#       # Runs a single command using the runners shell
-#       - name: Run a one-line script
-#         run: echo Hello, world!
-
-#       # Runs a set of commands using the runners shell
-#       - name: Run a multi-line script
-#         run: |
-#           echo Add other actions to build,
-#           echo test, and deploy your project.