From 1a0062f9c3c11c18971f69819599a7ff1d0c5046 Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Mon, 15 Aug 2022 23:28:34 +0100 Subject: [PATCH 1/4] Add github actions for CI - When a new PR is submitted, autoformat code with autopep8 and remove commented out code - After reformatting, commit back to the pull request - When reformatted code has been committed, lint it with pycodestyle On github side we will - Require all changes to be submitted as PRs - Require all CI checks to pass before merging PRs This change partially-fixes #1 and fixes #10 --- .editorconfig | 8 +++++++ .github/workflows/lint.yml | 47 ++++++++++++++++++++++++++++++++++++++ setup.cfg | 4 ++++ 3 files changed, 59 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/workflows/lint.yml create mode 100644 setup.cfg diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..9141329 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,8 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +charset = utf-8 +indent_style = space +indent_size = 4 diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..3915f7b --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,47 @@ +name: Lint & reformat + +on: + pull_request: + branches: ["master"] + + workflow_dispatch: + +jobs: + reformat: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + cache-dependency-path: | + **/requirements*.txt + - name: Install pip packages + run: python3 -m pip install --upgrade autopep8 pycodestyle eradicate + - name: Run autopep8 + run: autopep8 --in-place -aa -r . + - name: Remove commented out code + run: eradicate --in-place ./**/*.py + - name: Push back to repo + uses: actions-go/push@v1 + with: + author-email: github-actions[bot]@users.noreply.github.com + author-name: Reformat action + create-commit: true + commit-message: "Reformatted code and removed commented-out code" + lint: + runs-on: ubuntu-latest + needs: reformat + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-python@v4 + with: + python-version: '3.9' + cache: 'pip' + cache-dependency-path: | + **/requirements*.txt + - name: Install pip packages + run: python3 -m pip install --upgrade pycodestyle + - name: Run pycodestyle + run: pycodestyle --show-source --show-pep8 ./**/*.py diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..a6958b8 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,4 @@ +[pycodestyle] +max-line-length = 120 +statistics = True + From beb039238f07359d7fbf74b3fb5ad62b1db87e50 Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Mon, 15 Aug 2022 23:57:46 +0100 Subject: [PATCH 2/4] Add a requirements.txt file to test/ - This will be needed for CI later - This is required for the python setup stage of my github action (act didn't catch that locally) --- test/requirements.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/requirements.txt diff --git a/test/requirements.txt b/test/requirements.txt new file mode 100644 index 0000000..e69de29 From a564adf7e9358160b4651662ca8afa3a2c0b7efa Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Tue, 16 Aug 2022 00:05:34 +0100 Subject: [PATCH 3/4] Replace the push back to repo action - The one I was using previously did not support pull requests --- .github/workflows/lint.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 3915f7b..08c9444 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,12 +24,7 @@ jobs: - name: Remove commented out code run: eradicate --in-place ./**/*.py - name: Push back to repo - uses: actions-go/push@v1 - with: - author-email: github-actions[bot]@users.noreply.github.com - author-name: Reformat action - create-commit: true - commit-message: "Reformatted code and removed commented-out code" + uses: anyone-developer/anyone-push-back-repo@1.1.2 lint: runs-on: ubuntu-latest needs: reformat From 2a7329d33bd1fe733f27e9b394a6e495a07d71c3 Mon Sep 17 00:00:00 2001 From: Skyler Grey Date: Tue, 16 Aug 2022 00:13:00 +0100 Subject: [PATCH 4/4] Do not run the linter directly after reformatting - If we do, the linter will still have the old environment, so it will be ineffective --- .github/workflows/lint.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 08c9444..796d099 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -9,8 +9,12 @@ on: jobs: reformat: runs-on: ubuntu-latest + outputs: + reformatting-required: ${{ steps.push-back-to-repo.outputs.modified }} steps: - uses: actions/checkout@v3 + with: + token : ${{ secrets.PAT }} - uses: actions/setup-python@v4 with: python-version: '3.9' @@ -24,10 +28,12 @@ jobs: - name: Remove commented out code run: eradicate --in-place ./**/*.py - name: Push back to repo + id: push-back-to-repo uses: anyone-developer/anyone-push-back-repo@1.1.2 lint: runs-on: ubuntu-latest needs: reformat + if: needs.reformat.reformatting-required == 0 steps: - uses: actions/checkout@v3 - uses: actions/setup-python@v4