From fd331c98b61533d8acef15ccfc1af791d886b549 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Wed, 1 May 2024 14:28:49 +0100 Subject: [PATCH] Create separate receptorctl workflows with matrices (#1003) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) --- .github/workflows/pull_request.yml | 65 ++++++++++++++---------------- .github/workflows/reusable-nox.yml | 61 ++++++++++++++++++++++++++++ receptorctl/noxfile.py | 34 ++++++++++++++++ 3 files changed, 125 insertions(+), 35 deletions(-) create mode 100644 .github/workflows/reusable-nox.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bd8dc7fa4..397e15d1b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -21,20 +21,6 @@ jobs: uses: golangci/golangci-lint-action@v5 with: version: v1.56 - lint-receptorctl: - name: lint-receptorctl - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Setup nox - uses: wntrblm/nox@2024.04.15 - - - name: Run receptorctl linters - run: make receptorctl-lint receptor: name: receptor (Go ${{ matrix.go-version }}) runs-on: ubuntu-latest @@ -100,29 +86,38 @@ jobs: name: receptor path: /usr/local/bin/receptor receptorctl: - name: receptorctl + name: Run receptorctl tests${{ '' }} # Nest jobs under the same sidebar category needs: receptor - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Download receptor - uses: actions/download-artifact@v4 - with: - name: receptor - path: /usr/local/bin/ - - - name: Fix permissions on receptor binary - run: sudo chmod a+x /usr/local/bin/receptor - - - name: Setup nox - uses: wntrblm/nox@2024.04.15 + strategy: + fail-fast: false + matrix: + python-version: + # NOTE: The highest and the lowest versions come + # NOTE: first as their statuses are most likely to + # NOTE: signal problems early: + - 3.11 + - 3.8 + - >- + 3.10 + - 3.9 + uses: ./.github/workflows/reusable-nox.yml + with: + python-version: ${{ matrix.python-version }} + session: tests-${{ matrix.python-version }} + download-receptor: true - - name: Run receptorctl tests - run: make receptorctl-test + lint-receptorctl: + name: Lint receptorctl${{ '' }} # Nest jobs under the same sidebar category + strategy: + fail-fast: false + matrix: + session: + - check_style + - check_format + uses: ./.github/workflows/reusable-nox.yml + with: + python-version: 3.11 + session: ${{ matrix.session }} container: name: container runs-on: ubuntu-latest diff --git a/.github/workflows/reusable-nox.yml b/.github/workflows/reusable-nox.yml new file mode 100644 index 000000000..82f2b8e88 --- /dev/null +++ b/.github/workflows/reusable-nox.yml @@ -0,0 +1,61 @@ +--- +name: Receptorctl nox sessions + +on: + workflow_call: + inputs: + python-version: + type: string + description: The Python version to use. + required: true + session: + type: string + description: The nox session to run. + required: true + download-receptor: + type: boolean + description: Whether to perform go binary download. + required: false + default: false + +env: + FORCE_COLOR: 1 + NOXSESSION: ${{ inputs.session }} + +jobs: + nox: + runs-on: ubuntu-latest + + name: >- # can't use `env` in this context: + Run `receptorctl` ${{ inputs.session }} session + + steps: + - name: Download the `receptor` binary + if: fromJSON(inputs.download-receptor) + uses: actions/download-artifact@v4 + with: + name: receptor + path: /usr/local/bin/ + + - name: Set executable bit on the `receptor` binary + if: fromJSON(inputs.download-receptor) + run: sudo chmod a+x /usr/local/bin/receptor + + - name: Set up nox + uses: wntrblm/nox@2024.04.15 + with: + python-versions: ${{ inputs.python-version }} + + - name: Check out the source code from Git + uses: actions/checkout@v4 + with: + fetch-depth: 0 # Needed for the automation in Nox to find the last tag + sparse-checkout: receptorctl + + - name: Provision nox environment for ${{ env.NOXSESSION }} + run: nox --install-only + working-directory: ./receptorctl + + - name: Run `receptorctl` nox ${{ env.NOXSESSION }} session + run: nox --no-install + working-directory: ./receptorctl diff --git a/receptorctl/noxfile.py b/receptorctl/noxfile.py index 3c45be4ac..7dd734d13 100644 --- a/receptorctl/noxfile.py +++ b/receptorctl/noxfile.py @@ -1,8 +1,10 @@ import os +import subprocess from glob import iglob from pathlib import Path import nox +import nox.command python_versions = ["3.8", "3.9", "3.10", "3.11"] @@ -28,12 +30,44 @@ def install(session: nox.Session, *args, req: str, **kwargs): session.install("-r", requirements_directory / f"{req}.in", *args, **kwargs) +def version(session: nox.Session): + """ + Create a .VERSION file. + """ + try: + official_version = session.run_install( + "git", + "describe", + "--exact-match", + "--tags", + external=True, + stderr=subprocess.DEVNULL, + ) + except nox.command.CommandFailed: + official_version = None + print("Using the closest annotated tag instead of an exact match.") + + if official_version: + version = official_version.strip() + else: + tag = session.run_install( + "git", "describe", "--tags", "--always", silent=True, external=True + ) + rev = session.run_install( + "git", "rev-parse", "--short", "HEAD", silent=True, external=True + ) + version = tag.split("-")[0] + "+" + rev + + Path(".VERSION").write_text(version) + + @nox.session(python=python_versions) def tests(session: nox.Session): """ Run receptorctl tests """ install(session, req="tests") + version(session) session.install("-e", ".") session.run("pytest", "-v", "tests", *session.posargs)