From de6c5a67769c5c08ab350c1fcbad15adfa003451 Mon Sep 17 00:00:00 2001 From: real-yfprojects Date: Tue, 28 Feb 2023 13:32:01 +0100 Subject: [PATCH] Generate test matrix dynamically for extras. * .github/workflows/ci.yml --- .github/workflows/ci.yml | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index aa21651..d78daf0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,11 +23,41 @@ jobs: - name: Run linters run: make lint + generate_test_matrix: + runs-on: ubuntu-latest + outputs: + matrix: ${{ steps.set-matrix.outputs.matrix }} + steps: + - name: Checkout + uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 + + - name: setup python + uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0 + with: + python-version: "3.11" + + - name: Extract extras from `pyproject.toml` + id: set-matrix + shell: python + run: | + import tomllib + import os + import json + with open('pyproject.toml', 'rb') as f: + manifest = tomllib.load(f) + yaml = { 'include' : [{ 'extras' : extra} for extra in [''] + list(manifest['tool']['poetry']['extras'])]} + out = json.dumps(yaml) + print(out) + with open(os.environ['GITHUB_OUTPUT'], 'a') as f: + f.write('matrix=' + out) + test: + name: test ${{ matrix.extras && 'with' || '' }} ${{ matrix.extras }} runs-on: ubuntu-latest + needs: generate_test_matrix strategy: - matrix: - extras: ["packaging", "yaml", "packaging yaml"] + matrix: ${{ fromJson(needs.generate_test_matrix.outputs.matrix) }} + fail-fast: false steps: - name: Checkout uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0 @@ -36,7 +66,7 @@ jobs: id: setup uses: ./.github/actions/setup with: - install-options: --without lint --extras ${{matrix.extras}} + install-options: --without lint ${{ matrix.extras && format('--extras "{0}"', matrix.extras) || '' }} - name: Run Tests run: make test