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

Feat: Add tox-run action and workflow #89

Merged
merged 1 commit into from
Jan 31, 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
56 changes: 56 additions & 0 deletions .github/actions/tox-run-action/action.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: "tox-run"
description: "Run tox on specific environments"

inputs:
tox-dir:
description: "Directory containing tox.ini file"
required: false
default: "."
py-version:
decription: "Version of python to use"
required: false
default: "3.12"
tox-envs:
description: "Tox envs to run on this py-version"
required: false
parallel:
description: "Whether to run jobs in parallel"
required: false
default: "auto"
pre-build-script:
description: "Optional pre-build script to trigger before verify run"
required: false
default: ""

runs:
using: "composite"
steps:
- id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ inputs.py-version }}
cache: pip
- name: Run pre-build-script
id: pre-build
if: ${{ hashFiles(inputs.pre-build-script) }}
run: ${{ inputs.pre-build-script }}
- name: Build package (if available)
id: build-package
if: ${{ hashFiles('pyproject.toml') != '' }}
run: >
pipx run --python '${{ steps.setup-python.outputs.python-path }}'
build
- id: run-tox
run: |
cd "${GITHUB_WORKSPACE}/${{ inputs.tox-dir }}" || exit 1

TOX_OPTIONS_LIST=""
if [[ -n ${{ inputs.tox-envs }} ]]; then
TOX_OPTIONS_LIST=" -e ${{ inputs.tox-envs }}"
fi

# $TOX_OPTIONS_LIST are intentionally not surrounded by quotes
# to correcly pass options to tox
# shellcheck disable=SC2086
tox --parallel ${{ inputs.parallel }} --parallel-live $TOX_OPTIONS_LIST
79 changes: 79 additions & 0 deletions .github/workflows/gerrit-compose-required-tox-verify.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
---
name: Compose Tox Verify

# yamllint disable-line rule:truthy
on:
workflow_call:
inputs:
GERRIT_BRANCH:
description: "Branch that change is against"
required: true
type: string
GERRIT_CHANGE_ID:
description: "The ID for the change"
required: true
type: string
GERRIT_PROJECT:
description: "Project in Gerrit"
required: true
type: string
GERRIT_REFSPEC:
description: "Gerrit refspec of change"
required: true
type: string
TARGET_REPO:
# yamllint disable-line rule:line-length
description: "The target GitHub repository needing the required workflow"
required: false
default: ${{ github.repository }}
type: string
TOX_DIR:
description: "Directory containing tox.ini file"
required: false
default: "."
type: string
TOX_ENVS:
description: "Map of versions and envs to run"
required: true
type: string
PARALLEL:
keanjapesan marked this conversation as resolved.
Show resolved Hide resolved
description: "Whether to run jobs in parallel"
required: false
type: string
PRE_BUILD_SCRIPT:
description: "Optional pre-build script to trigger before verify run"
required: false
default: ""
type: string

concurrency:
# yamllint disable-line rule:line-length
group: compose-tox-verify-${{ github.workflow }}-${{ github.event.inputs.GERRIT_CHANGE_ID || github.run_id }}
cancel-in-progress: true

jobs:
eb-oss marked this conversation as resolved.
Show resolved Hide resolved
run-tox:
runs-on: ubuntu-latest
strategy:
matrix:
version: ${{ fromJSON(inputs.TOX_ENVS).* }}

steps:
- name: Gerrit Checkout
# yamllint disable-line rule:line-length
uses: lfit/checkout-gerrit-change-action@57bf0435f739fbbc7ce4cc85c9c3b8a386c6f84b # v0.6
with:
gerrit-refspec: ${{ inputs.GERRIT_REFSPEC }}
gerrit-project: ${{ inputs.GERRIT_PROJECT }}
gerrit-url: ${{ vars.GERRIT_URL }}
delay: "0s"
repository: ${{ inputs.TARGET_REPO }}
ref: refs/heads/${{ inputs.GERRIT_BRANCH }}
- name: Running tox
uses: ./.github/actions/tox-run-action
with:
tox-dir: ${{ inputs.TOX_DIR }}
py-version: ${{ matrix.version }}
tox-envs: ${{ toJSON(matrix.version.*) }}
parallel: ${{ inputs.PARALLEL }}
pre-build-script: ${{ inputs.PRE_BUILD_SCRIPT }}
Loading