From 02743a916612d81e78c98e077a73b96bb3bb8f37 Mon Sep 17 00:00:00 2001 From: Joris Roovers Date: Tue, 7 Mar 2023 11:30:15 +0100 Subject: GHA: Minor tweaks (#458) - Renamed checks.yml to ci.yml - Add concurrency control to ci to auto-cancel outdated ci runs - Publish releases to pypi instead of test.pypi.org --- .github/workflows/checks.yml | 135 ---------------------------------- .github/workflows/ci.yml | 139 +++++++++++++++++++++++++++++++++++ .github/workflows/github-release.yml | 2 +- 3 files changed, 140 insertions(+), 136 deletions(-) delete mode 100644 .github/workflows/checks.yml create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml deleted file mode 100644 index 1d0554a..0000000 --- a/.github/workflows/checks.yml +++ /dev/null @@ -1,135 +0,0 @@ -name: Tests and Checks - -# Only run CI on pushes to main and pull requests -# We don't run CI on other branches, but those should be merged into main via a PR anyways which will trigger CI before the merge. -on: - push: - branches: - - main - pull_request: - branches: - - main - -jobs: - checks: - runs-on: "ubuntu-latest" - strategy: - matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.9] - os: ["macos-latest", "ubuntu-latest", "windows-latest"] - steps: - - uses: actions/checkout@v3.3.0 - with: - ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit - fetch-depth: 0 # checkout all history, needed for hatch versioning - - - name: Setup python - uses: actions/setup-python@v4.5.0 - with: - python-version: ${{ matrix.python-version }} - - - name: Install Hatch - run: python -m pip install hatch==1.6.3 - - - name: Unit Tests - run: hatch run test:unit-tests - - - name: Code formatting (black) - run: hatch run test:format - - - name: Code linting (ruff) - run: hatch run test:lint - - - name: Install local gitlint for integration tests - run: | - hatch run qa:install-local - - - name: Integration tests (default -> GITLINT_USE_SH_LIB=1) - run: | - hatch run qa:integration-tests - if: matrix.os != 'windows-latest' - - - name: Integration tests (GITLINT_USE_SH_LIB=1) - run: | - hatch run qa:integration-tests - env: - GITLINT_USE_SH_LIB: 1 - if: matrix.os != 'windows-latest' - - - name: Integration tests (GITLINT_QA_USE_SH_LIB=0) - run: | - hatch run qa:integration-tests -k "not(test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit)" qa - env: - GITLINT_QA_USE_SH_LIB: 0 - if: matrix.os != 'windows-latest' - - - name: Integration tests (Windows) - run: | - hatch run qa:integration-tests -k "not (test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit or test_lint_staged_stdin or test_stdin_file or test_stdin_pipe_empty)" qa - if: matrix.os == 'windows-latest' - - - name: Build test (gitlint) - run: | - hatch build - hatch clean - - - name: Build test (gitlint-core) - run: | - hatch build - hatch clean - working-directory: ./gitlint-core - - - name: Docs build (mkdocs) - run: hatch run docs:build - - # Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations. - # PRs get squashed and get a proper commit message during merge. - - name: gitlint --debug - run: hatch run dev:gitlint --debug - continue-on-error: ${{ github.event_name == 'pull_request' }} # Don't enforce gitlint in PRs - - - name: Code Coverage (coveralls) - uses: coverallsapp/github-action@master - with: - path-to-lcov: ".coverage.lcov" - github-token: ${{ secrets.GITHUB_TOKEN }} - git-commit: ${{ github.event.pull_request.head.sha }} - flag-name: gitlint-${{ matrix.os }}-${{ matrix.python-version }} - parallel: true - - upload_coveralls: - needs: checks - runs-on: ubuntu-latest - steps: - - name: Upload coverage to coveralls - uses: coverallsapp/github-action@master - with: - path-to-lcov: ".coverage.lcov" - github-token: ${{ secrets.GITHUB_TOKEN }} - parallel-finished: true - - check: # This job does nothing and is only used for the branch protection - if: always() # Ref: https://github.com/marketplace/actions/alls-green#why - - needs: - - upload_coveralls - - checks - - runs-on: ubuntu-latest - - steps: - - name: Decide whether the needed jobs succeeded or failed - uses: re-actors/alls-green@release/v1 - with: - jobs: ${{ toJSON(needs) }} - - # When on main, auto publish dev build - auto-publish-dev: - needs: - - check - if: github.ref == 'refs/heads/main' - uses: ./.github/workflows/publish-release.yml - secrets: inherit # pass all secrets (required to access secrets in a called workflow) - with: - pypi_target: "pypi.org" - repo_release_ref: "main" \ No newline at end of file diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..139c56a --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,139 @@ +name: Tests and Checks + +# Only run CI on pushes to main and pull requests +# We don't run CI on other branches, but those should be merged into main via a PR anyways which will trigger CI before the merge. +on: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ci-${{ github.ref }}-1 + cancel-in-progress: true + +jobs: + checks: + runs-on: "ubuntu-latest" + strategy: + matrix: + python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", pypy-3.9] + os: ["macos-latest", "ubuntu-latest", "windows-latest"] + steps: + - uses: actions/checkout@v3.3.0 + with: + ref: ${{ github.event.pull_request.head.sha }} # Checkout pull request HEAD commit instead of merge commit + fetch-depth: 0 # checkout all history, needed for hatch versioning + + - name: Setup python + uses: actions/setup-python@v4.5.0 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Hatch + run: python -m pip install hatch==1.6.3 + + - name: Unit Tests + run: hatch run test:unit-tests + + - name: Code formatting (black) + run: hatch run test:format + + - name: Code linting (ruff) + run: hatch run test:lint + + - name: Install local gitlint for integration tests + run: | + hatch run qa:install-local + + - name: Integration tests (default -> GITLINT_USE_SH_LIB=1) + run: | + hatch run qa:integration-tests + if: matrix.os != 'windows-latest' + + - name: Integration tests (GITLINT_USE_SH_LIB=1) + run: | + hatch run qa:integration-tests + env: + GITLINT_USE_SH_LIB: 1 + if: matrix.os != 'windows-latest' + + - name: Integration tests (GITLINT_QA_USE_SH_LIB=0) + run: | + hatch run qa:integration-tests -k "not(test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit)" qa + env: + GITLINT_QA_USE_SH_LIB: 0 + if: matrix.os != 'windows-latest' + + - name: Integration tests (Windows) + run: | + hatch run qa:integration-tests -k "not (test_commit_hook_continue or test_commit_hook_abort or test_commit_hook_edit or test_lint_staged_stdin or test_stdin_file or test_stdin_pipe_empty)" qa + if: matrix.os == 'windows-latest' + + - name: Build test (gitlint) + run: | + hatch build + hatch clean + + - name: Build test (gitlint-core) + run: | + hatch build + hatch clean + working-directory: ./gitlint-core + + - name: Docs build (mkdocs) + run: hatch run docs:build + + # Run gitlint. Skip during PR runs, since PR commit messages are transient and usually full of gitlint violations. + # PRs get squashed and get a proper commit message during merge. + - name: gitlint --debug + run: hatch run dev:gitlint --debug + continue-on-error: ${{ github.event_name == 'pull_request' }} # Don't enforce gitlint in PRs + + - name: Code Coverage (coveralls) + uses: coverallsapp/github-action@master + with: + path-to-lcov: ".coverage.lcov" + github-token: ${{ secrets.GITHUB_TOKEN }} + git-commit: ${{ github.event.pull_request.head.sha }} + flag-name: gitlint-${{ matrix.os }}-${{ matrix.python-version }} + parallel: true + + upload_coveralls: + needs: checks + runs-on: ubuntu-latest + steps: + - name: Upload coverage to coveralls + uses: coverallsapp/github-action@master + with: + path-to-lcov: ".coverage.lcov" + github-token: ${{ secrets.GITHUB_TOKEN }} + parallel-finished: true + + check: # This job does nothing and is only used for the branch protection + if: always() # Ref: https://github.com/marketplace/actions/alls-green#why + + needs: + - upload_coveralls + - checks + + runs-on: ubuntu-latest + + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + + # When on main, auto publish dev build + auto-publish-dev: + needs: + - check + if: github.ref == 'refs/heads/main' + uses: ./.github/workflows/publish-release.yml + secrets: inherit # pass all secrets (required to access secrets in a called workflow) + with: + pypi_target: "pypi.org" + repo_release_ref: "main" \ No newline at end of file diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index 0c86ec8..e5e40c9 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -10,5 +10,5 @@ jobs: uses: ./.github/workflows/publish-release.yml secrets: inherit # pass all secrets (required to access secrets in a called workflow) with: - pypi_target: "test.pypi.org" + pypi_target: "pypi.org" repo_release_ref: ${{ github.ref_name }} -- cgit v1.2.3