Skip to content

Commit

Permalink
Merge pull request #89 from MightyNerdEric/add-tox-action
Browse files Browse the repository at this point in the history
Feat: Add tox-run action and workflow
  • Loading branch information
Eric Ball authored Jan 31, 2024
2 parents a8d19b8 + 3fd564a commit dde691a
Show file tree
Hide file tree
Showing 2 changed files with 135 additions and 0 deletions.
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:
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:
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 }}

0 comments on commit dde691a

Please sign in to comment.