From 3fd564a0dfcf62811b2169ef95dad1c9b96e90d0 Mon Sep 17 00:00:00 2001 From: Eric Ball Date: Wed, 10 Jan 2024 19:10:05 -0800 Subject: [PATCH] Feat: Add tox-run action and workflow Signed-off-by: Eric Ball --- .github/actions/tox-run-action/action.yaml | 56 +++++++++++++ .../gerrit-compose-required-tox-verify.yaml | 79 +++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 .github/actions/tox-run-action/action.yaml create mode 100644 .github/workflows/gerrit-compose-required-tox-verify.yaml diff --git a/.github/actions/tox-run-action/action.yaml b/.github/actions/tox-run-action/action.yaml new file mode 100644 index 0000000..916a31d --- /dev/null +++ b/.github/actions/tox-run-action/action.yaml @@ -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 diff --git a/.github/workflows/gerrit-compose-required-tox-verify.yaml b/.github/workflows/gerrit-compose-required-tox-verify.yaml new file mode 100644 index 0000000..05d9bc2 --- /dev/null +++ b/.github/workflows/gerrit-compose-required-tox-verify.yaml @@ -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 }}