Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create separate receptorctl workflows with matrices #1003

Merged
merged 7 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 30 additions & 35 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]

- name: Run receptorctl linters
run: make receptorctl-lint
receptor:
name: receptor (Go ${{ matrix.go-version }})
runs-on: ubuntu-latest
Expand Down Expand Up @@ -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/[email protected]
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
Expand Down
61 changes: 61 additions & 0 deletions .github/workflows/reusable-nox.yml
Original file line number Diff line number Diff line change
@@ -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/[email protected]
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
34 changes: 34 additions & 0 deletions receptorctl/noxfile.py
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -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)
oraNod marked this conversation as resolved.
Show resolved Hide resolved
session.install("-e", ".")
session.run("pytest", "-v", "tests", *session.posargs)

Expand Down
Loading