From 586ced57c34a3bab3f99d1ac834d243d4611f180 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Tue, 16 Apr 2024 10:58:39 +0100 Subject: [PATCH 1/7] create separate receptorctl workflows with matrices 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 | 39 ++------------------ .github/workflows/receptorctl.yml | 47 ++++++++++++++++++++++++ .github/workflows/receptorctl_checks.yml | 34 +++++++++++++++++ 3 files changed, 84 insertions(+), 36 deletions(-) create mode 100644 .github/workflows/receptorctl.yml create mode 100644 .github/workflows/receptorctl_checks.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index bd8dc7fa4..6e211268a 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,10 @@ jobs: name: receptor path: /usr/local/bin/receptor receptorctl: - name: receptorctl 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 - - - name: Run receptorctl tests - run: make receptorctl-test + uses: ./.github/workflows/receptorctl.yml + lint-receptorctl: + uses: ./.github/workflows/receptorctl_checks.yml container: name: container runs-on: ubuntu-latest diff --git a/.github/workflows/receptorctl.yml b/.github/workflows/receptorctl.yml new file mode 100644 index 000000000..dce4ab7e2 --- /dev/null +++ b/.github/workflows/receptorctl.yml @@ -0,0 +1,47 @@ +--- +name: receptorctl + +"on": + workflow_call: + +jobs: + receptorctl: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - session: tests-3.8 + python-version: "3.8" + - session: tests-3.9 + python-version: "3.9" + - session: tests-3.10 + python-version: "3.10" + - session: tests-3.11 + python-version: "3.11" + + name: "Run receptorctl ${{ matrix.session }} session" + 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 + with: + python-versions: "${{ matrix.python-version }}" + + - name: "Run receptorctl nox ${{ matrix.session }} session" + run: | + nox -s "${{ matrix.session }}" + working-directory: ./receptorctl diff --git a/.github/workflows/receptorctl_checks.yml b/.github/workflows/receptorctl_checks.yml new file mode 100644 index 000000000..e8b1efb0b --- /dev/null +++ b/.github/workflows/receptorctl_checks.yml @@ -0,0 +1,34 @@ +--- +name: lint-receptorctl + +"on": + workflow_call: + +jobs: + lint-receptorctl: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: + - 3.11 + session: + - check_style + - check_format + + name: "Run receptorctl ${{ matrix.session }} session" + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Setup nox + uses: wntrblm/nox@2024.04.15 + with: + python-versions: "${{ matrix.python-version }}" + + - name: "Run receptorctl nox ${{ matrix.session }} session" + run: | + nox -s "${{ matrix.session }}" + working-directory: ./receptorctl From 963b8d669034f5b230b564e36d53c6db47af6ac4 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Tue, 16 Apr 2024 18:11:19 +0100 Subject: [PATCH 2/7] add version file session --- receptorctl/noxfile.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/receptorctl/noxfile.py b/receptorctl/noxfile.py index 3c45be4ac..dd2bc062b 100644 --- a/receptorctl/noxfile.py +++ b/receptorctl/noxfile.py @@ -3,6 +3,7 @@ from pathlib import Path import nox +import nox.command python_versions = ["3.8", "3.9", "3.10", "3.11"] @@ -28,12 +29,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( + "git", + "describe", + "--exact-match", + "--tags", + external=True, + stderr=open(os.devnull, "w"), + ) + except nox.command.CommandFailed: + official_version = None + + if not official_version: + print("Current commit not tagged. Using closest annotated tag instead.") + tag = session.run( + "git", "describe", "--tags", "--always", silent=True, external=True + ) + rev = session.run( + "git", "rev-parse", "--short", "HEAD", silent=True, external=True + ) + version = tag.split("-")[0] + "+" + rev + + f = open(".VERSION", "w") + f.write(version) + f.close() + + @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) From 1863a2bf21d556594fe42f6cf70cc2ad971fe983 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Thu, 18 Apr 2024 16:13:27 +0100 Subject: [PATCH 3/7] prefix receptorctl reusable workflows --- .github/workflows/pull_request.yml | 4 ++-- ...receptorctl_checks.yml => reusable_receptorctl_checks.yml} | 0 .../{receptorctl.yml => reusable_receptorctl_tests.yml} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename .github/workflows/{receptorctl_checks.yml => reusable_receptorctl_checks.yml} (100%) rename .github/workflows/{receptorctl.yml => reusable_receptorctl_tests.yml} (100%) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6e211268a..48484d939 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -87,9 +87,9 @@ jobs: path: /usr/local/bin/receptor receptorctl: needs: receptor - uses: ./.github/workflows/receptorctl.yml + uses: ./.github/workflows/reusable_receptorctl_tests.yml lint-receptorctl: - uses: ./.github/workflows/receptorctl_checks.yml + uses: ./.github/workflows/reusable_receptorctl_checks.yml container: name: container runs-on: ubuntu-latest diff --git a/.github/workflows/receptorctl_checks.yml b/.github/workflows/reusable_receptorctl_checks.yml similarity index 100% rename from .github/workflows/receptorctl_checks.yml rename to .github/workflows/reusable_receptorctl_checks.yml diff --git a/.github/workflows/receptorctl.yml b/.github/workflows/reusable_receptorctl_tests.yml similarity index 100% rename from .github/workflows/receptorctl.yml rename to .github/workflows/reusable_receptorctl_tests.yml From 239f1e35c0201fb2da94a2c78bf5e9d1c9a81e55 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Thu, 18 Apr 2024 16:27:26 +0100 Subject: [PATCH 4/7] improvements to receptorctl workflows MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) --- .../workflows/reusable_receptorctl_checks.yml | 24 +++++--- .../workflows/reusable_receptorctl_tests.yml | 55 +++++++++++-------- receptorctl/noxfile.py | 19 ++++--- 3 files changed, 57 insertions(+), 41 deletions(-) diff --git a/.github/workflows/reusable_receptorctl_checks.yml b/.github/workflows/reusable_receptorctl_checks.yml index e8b1efb0b..3cc33f354 100644 --- a/.github/workflows/reusable_receptorctl_checks.yml +++ b/.github/workflows/reusable_receptorctl_checks.yml @@ -16,19 +16,25 @@ jobs: - check_style - check_format - name: "Run receptorctl ${{ matrix.session }} session" + env: + NOXSESSION: ${{ matrix.session }} + + name: >- # can't use `env` in this context: + Run `receptorctl` ${{ matrix.session }} session + steps: - - name: Checkout - uses: actions/checkout@v4 + - name: Set up nox + uses: wntrblm/nox@2024.04.15 with: - fetch-depth: 0 + python-versions: ${{ matrix.python-version }} - - name: Setup nox - uses: wntrblm/nox@2024.04.15 + - name: Check out the source code from Git + uses: actions/checkout@v4 with: - python-versions: "${{ matrix.python-version }}" + sparse-checkout: receptorctl - - name: "Run receptorctl nox ${{ matrix.session }} session" + - name: >- + Run `receptorctl` ${{ env.NOXSESSION }} session run: | - nox -s "${{ matrix.session }}" + nox working-directory: ./receptorctl diff --git a/.github/workflows/reusable_receptorctl_tests.yml b/.github/workflows/reusable_receptorctl_tests.yml index dce4ab7e2..93c195604 100644 --- a/.github/workflows/reusable_receptorctl_tests.yml +++ b/.github/workflows/reusable_receptorctl_tests.yml @@ -10,38 +10,47 @@ jobs: strategy: fail-fast: false matrix: - include: - - session: tests-3.8 - python-version: "3.8" - - session: tests-3.9 - python-version: "3.9" - - session: tests-3.10 - python-version: "3.10" - - session: tests-3.11 - python-version: "3.11" - - name: "Run receptorctl ${{ matrix.session }} session" - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 + 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 + + env: + FORCE_COLOR: 1 + NOXSESSION: tests-${{ matrix.python-version }} + + name: >- # can't use `env` in this context: + Run `receptorctl` tests-${{ matrix.python-version }} session - - name: Download receptor + steps: + - name: Download the `receptor` binary uses: actions/download-artifact@v4 with: name: receptor path: /usr/local/bin/ - - name: Fix permissions on receptor binary + - name: Set executable bit on the `receptor` binary run: sudo chmod a+x /usr/local/bin/receptor - - name: Setup nox + - name: Set up nox uses: wntrblm/nox@2024.04.15 with: - python-versions: "${{ matrix.python-version }}" + python-versions: ${{ matrix.python-version }} - - name: "Run receptorctl nox ${{ matrix.session }} session" - run: | - nox -s "${{ matrix.session }}" + - 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 dd2bc062b..7dd734d13 100644 --- a/receptorctl/noxfile.py +++ b/receptorctl/noxfile.py @@ -1,4 +1,5 @@ import os +import subprocess from glob import iglob from pathlib import Path @@ -34,30 +35,30 @@ def version(session: nox.Session): Create a .VERSION file. """ try: - official_version = session.run( + official_version = session.run_install( "git", "describe", "--exact-match", "--tags", external=True, - stderr=open(os.devnull, "w"), + stderr=subprocess.DEVNULL, ) except nox.command.CommandFailed: official_version = None + print("Using the closest annotated tag instead of an exact match.") - if not official_version: - print("Current commit not tagged. Using closest annotated tag instead.") - tag = session.run( + if official_version: + version = official_version.strip() + else: + tag = session.run_install( "git", "describe", "--tags", "--always", silent=True, external=True ) - rev = session.run( + rev = session.run_install( "git", "rev-parse", "--short", "HEAD", silent=True, external=True ) version = tag.split("-")[0] + "+" + rev - f = open(".VERSION", "w") - f.write(version) - f.close() + Path(".VERSION").write_text(version) @nox.session(python=python_versions) From dfd42c5413011cc970ba3f9f879a71153ccd6c04 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Tue, 30 Apr 2024 09:50:49 +0100 Subject: [PATCH 5/7] Update .github/workflows/pull_request.yml 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 | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 48484d939..b1e72ff99 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -87,9 +87,34 @@ jobs: path: /usr/local/bin/receptor receptorctl: needs: receptor - uses: ./.github/workflows/reusable_receptorctl_tests.yml + 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 }} + lint-receptorctl: - uses: ./.github/workflows/reusable_receptorctl_checks.yml + 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 From eadbf74e77cb78e04f41e206e062f15d2a46d7b1 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Tue, 30 Apr 2024 09:57:07 +0100 Subject: [PATCH 6/7] replace receptorctl workflows with reusable nox --- .github/workflows/pull_request.yml | 5 +- ...receptorctl_tests.yml => reusable-nox.yml} | 47 ++++++++++--------- .../workflows/reusable_receptorctl_checks.yml | 40 ---------------- 3 files changed, 30 insertions(+), 62 deletions(-) rename .github/workflows/{reusable_receptorctl_tests.yml => reusable-nox.yml} (57%) delete mode 100644 .github/workflows/reusable_receptorctl_checks.yml diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index b1e72ff99..93f5f2d59 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -86,7 +86,8 @@ jobs: name: receptor path: /usr/local/bin/receptor receptorctl: - needs: receptor + name: Run receptorctl tests${{ '' }} # Nest jobs under the same sidebar category + #needs: receptor strategy: fail-fast: false matrix: @@ -103,8 +104,10 @@ jobs: with: python-version: ${{ matrix.python-version }} session: tests-${{ matrix.python-version }} + download-receptor: true lint-receptorctl: + name: Lint receptorctl${{ '' }} # Nest jobs under the same sidebar category strategy: fail-fast: false matrix: diff --git a/.github/workflows/reusable_receptorctl_tests.yml b/.github/workflows/reusable-nox.yml similarity index 57% rename from .github/workflows/reusable_receptorctl_tests.yml rename to .github/workflows/reusable-nox.yml index 93c195604..82f2b8e88 100644 --- a/.github/workflows/reusable_receptorctl_tests.yml +++ b/.github/workflows/reusable-nox.yml @@ -1,46 +1,50 @@ --- -name: receptorctl +name: Receptorctl nox sessions -"on": +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: - receptorctl: + nox: runs-on: ubuntu-latest - 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 - - env: - FORCE_COLOR: 1 - NOXSESSION: tests-${{ matrix.python-version }} name: >- # can't use `env` in this context: - Run `receptorctl` tests-${{ matrix.python-version }} session + 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: ${{ matrix.python-version }} + python-versions: ${{ inputs.python-version }} - name: Check out the source code from Git uses: actions/checkout@v4 @@ -51,6 +55,7 @@ jobs: - 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/.github/workflows/reusable_receptorctl_checks.yml b/.github/workflows/reusable_receptorctl_checks.yml deleted file mode 100644 index 3cc33f354..000000000 --- a/.github/workflows/reusable_receptorctl_checks.yml +++ /dev/null @@ -1,40 +0,0 @@ ---- -name: lint-receptorctl - -"on": - workflow_call: - -jobs: - lint-receptorctl: - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - python-version: - - 3.11 - session: - - check_style - - check_format - - env: - NOXSESSION: ${{ matrix.session }} - - name: >- # can't use `env` in this context: - Run `receptorctl` ${{ matrix.session }} session - - steps: - - name: Set up nox - uses: wntrblm/nox@2024.04.15 - with: - python-versions: ${{ matrix.python-version }} - - - name: Check out the source code from Git - uses: actions/checkout@v4 - with: - sparse-checkout: receptorctl - - - name: >- - Run `receptorctl` ${{ env.NOXSESSION }} session - run: | - nox - working-directory: ./receptorctl From 0399f35c331ebe8d9facb6b417ed697843aca6e0 Mon Sep 17 00:00:00 2001 From: Don Naro Date: Tue, 30 Apr 2024 13:37:29 +0100 Subject: [PATCH 7/7] uncomment receptor dependency --- .github/workflows/pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 93f5f2d59..397e15d1b 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -87,7 +87,7 @@ jobs: path: /usr/local/bin/receptor receptorctl: name: Run receptorctl tests${{ '' }} # Nest jobs under the same sidebar category - #needs: receptor + needs: receptor strategy: fail-fast: false matrix: