From f0af9b58ded10bf76a1324226bbfd991e5a70b85 Mon Sep 17 00:00:00 2001 From: Alina Buzachis Date: Tue, 2 May 2023 19:00:20 +0200 Subject: [PATCH] Run black on main only Signed-off-by: Alina Buzachis --- .github/workflows/all_green_check.yml | 9 ++--- .github/workflows/black.yml | 58 ++++++++++++++++++++++----- .github/workflows/changelog.yml | 8 ---- tox.ini | 25 ------------ 4 files changed, 51 insertions(+), 49 deletions(-) delete mode 100644 .github/workflows/changelog.yml diff --git a/.github/workflows/all_green_check.yml b/.github/workflows/all_green_check.yml index f477281545b..b6f858ab943 100644 --- a/.github/workflows/all_green_check.yml +++ b/.github/workflows/all_green_check.yml @@ -20,10 +20,8 @@ on: # yamllint disable-line rule:truthy - '*' jobs: - changelog: - uses: ./.github/workflows/changelog.yml # use the callable changelog job to run tests - linters: - uses: ./.github/workflows/linters.yml # use the callable linters job to run tests + changelog-and-linters: + uses: ./.github/workflows/changelog_and_linters.yml # use the callable linters job to run tests sanity: uses: ./.github/workflows/sanity.yml # use the callable sanity job to run tests units: @@ -38,8 +36,7 @@ jobs: steps: - run: >- python -c "assert set([ - '${{ needs.changelog.result }}', + '${{ needs.changelog-and-linters.result }}', '${{ needs.sanity.result }}', - '${{ needs.linters.result }}', '${{ needs.units.result }}' ]) == {'success'}" diff --git a/.github/workflows/black.yml b/.github/workflows/black.yml index e4a6fd3c654..a79e3beba1c 100644 --- a/.github/workflows/black.yml +++ b/.github/workflows/black.yml @@ -1,17 +1,55 @@ --- -name: black - -concurrency: - group: '${{ github.workflow }} @ ${{ github.sha }}' - cancel-in-progress: true +name: 'Python formatting linter (Black)' on: - push: + workflow_dispatch: + pull_request: branches: - main - - 'stable-*' - pull_request_target: + +permissions: + contents: read + pull-requests: read + +# This allows a subsequently queued workflow run to interrupt previous runs +concurrency: + group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' + cancel-in-progress: true jobs: - format: - uses: abikouo/github_actions/.github/workflows/black.yml@automate_changes_a + check-black: + runs-on: ${{ fromJSON('["ubuntu-latest", "self-hosted"]')[github.repository == 'github/docs-internal'] }} + steps: + - name: Checkout the collection repository + uses: actions/checkout@v3 + with: + path: ${{ env.source_directory }} + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: "0" + + - name: Set up Python + uses: actions/setup-python@v3 + with: + python-version: ${{ inputs.python }} + + - name: Read collection metadata from galaxy.yml + id: identify + uses: ansible-network/github_actions/.github/actions/identify_collection@main + with: + source_path: ${{ env.source_directory }} + + - name: Build and install the collection + uses: ansible-network/github_actions/.github/actions/build_install_collection@main + with: + install_python_dependencies: false + source_path: ${{ env.source_directory }} + collection_path: ${{ steps.identify.outputs.collection_path }} + tar_file: ${{ steps.identify.outputs.tar_file }} + + - name: Install black + run: pip install black + + - name: Run black + run: | + black -v --check --diff . + working-directory: ${{ steps.identify.outputs.collection_path }} diff --git a/.github/workflows/changelog.yml b/.github/workflows/changelog.yml deleted file mode 100644 index 156ed40da81..00000000000 --- a/.github/workflows/changelog.yml +++ /dev/null @@ -1,8 +0,0 @@ ---- -name: changelog - -on: [workflow_call] # allow this workflow to be called from other workflows - -jobs: - changelog: - uses: ansible-network/github_actions/.github/workflows/changelog.yml@main diff --git a/tox.ini b/tox.ini index 13fba5e6b0b..0f1e2c719de 100644 --- a/tox.ini +++ b/tox.ini @@ -27,28 +27,3 @@ deps = flake8>=3.3.0,<5.0.0 flake8-html commands = -flake8 --select C90 --max-complexity 10 --format=html --htmldir={posargs:complexity} plugins - -[testenv:black_check] -deps = - black >=23.0, <24.0 - -commands = - black -v --check --diff {toxinidir}/plugins {toxinidir}/tests - -[testenv:black] -deps = - {[testenv:black_check]deps} - -commands = - black -v {posargs:{toxinidir}/plugins {toxinidir}/tests} - -[testenv:linters] -deps = - yamllint - flake8 - {[testenv:black_check]deps} - -commands = - {[testenv:black_check]commands} - yamllint -s {toxinidir} - flake8 {toxinidir}