diff --git a/.github/workflows/.tests.yaml b/.github/workflows/.tests.yaml new file mode 100644 index 00000000000..fa7859e585d --- /dev/null +++ b/.github/workflows/.tests.yaml @@ -0,0 +1,111 @@ +# Reusable workflow consumed by tests.yaml; used to share a single matrix across jobs. +name: .tests + +on: + workflow_call: + inputs: + os-name: + required: true + type: string + os-image: + required: true + type: string + python-version: + required: true + type: string + run-mypy: + required: true + type: boolean + run-pytest: + required: true + type: boolean + run-pytest-export: + required: true + type: boolean + +defaults: + run: + shell: bash + +jobs: + mypy: + name: mypy + runs-on: ${{ inputs.os-image }} + if: inputs.run-mypy + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/bootstrap-poetry + with: + python-version: ${{ inputs.python-version }} + + - run: poetry install --sync + + - run: poetry env info + + - run: poetry show + + - uses: actions/cache@v4 + with: + path: .mypy_cache + key: mypy-${{ inputs.os-image }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'poetry.lock') }} + restore-keys: | + mypy-${{ inputs.os-image }}-${{ env.pythonLocation }}- + mypy-${{ inputs.os-image }}- + + - run: poetry run mypy + + pytest: + name: pytest + runs-on: ${{ inputs.os-image }} + if: inputs.run-pytest + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/bootstrap-poetry + with: + python-version: ${{ inputs.python-version }} + + - run: poetry install --sync --with github-actions + + - run: poetry env info + + - run: poetry show + + - run: poetry run pytest --integration -v + env: + POETRY_TEST_INTEGRATION_GIT_USERNAME: ${{ github.actor }} + POETRY_TEST_INTEGRATION_GIT_PASSWORD: ${{ github.token }} + + - run: git diff --exit-code --stat HEAD + + pytest-export: + name: pytest (poetry-plugin-export) + runs-on: ${{ inputs.os-image }} + if: inputs.run-pytest-export + steps: + - uses: actions/checkout@v4 + + - uses: ./.github/actions/bootstrap-poetry + with: + python-version: ${{ inputs.python-version }} + + - run: poetry install --sync --with github-actions + + - run: poetry env info + + - run: poetry show + + - id: poetry-plugin-export + run: echo version=$(poetry run pip list --format json | jq -r '.[] | select(.name == "poetry-plugin-export").version') >> $GITHUB_OUTPUT + + - uses: actions/checkout@v4 + with: + path: poetry-plugin-export + repository: python-poetry/poetry-plugin-export + ref: refs/tags/${{ steps.poetry-plugin-export.outputs.version }} + + - run: poetry run -C .. pytest -v + working-directory: ./poetry-plugin-export + + - run: git -C poetry-plugin-export diff --exit-code --stat HEAD diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index 61970b546e9..8e002af7e1d 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -31,6 +31,7 @@ jobs: filters: | workflow: &workflow - '.github/workflows/tests.yaml' + - '.github/workflows/.tests.yaml' project: &project - *workflow - 'poetry.lock' @@ -77,54 +78,11 @@ jobs: - run: git diff --exit-code --stat HEAD tests/repositories/fixtures/pypi.org - mypy: - name: mypy [${{ matrix.os.name }} / Python ${{ matrix.python-version }}] - runs-on: ${{ matrix.os.image }} - if: needs.changes.outputs.mypy == 'true' + tests-matrix: + name: ${{ matrix.os.name }} (Python ${{ matrix.python-version }}) needs: - - changes - lockfile - strategy: - matrix: - os: - - name: Ubuntu - image: ubuntu-22.04 - - name: macOS - image: macos-12 - - name: Windows - image: windows-2022 - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - fail-fast: false - steps: - - uses: actions/checkout@v4 - - - uses: ./.github/actions/bootstrap-poetry - with: - python-version: ${{ matrix.python-version }} - - - run: poetry install --sync - - - run: poetry env info - - - run: poetry show - - - uses: actions/cache@v4 - with: - path: .mypy_cache - key: mypy-${{ matrix.os.image }}-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'poetry.lock') }} - restore-keys: | - mypy-${{ inputs.os-image }}-${{ env.pythonLocation }}- - mypy-${{ inputs.os-image }}- - - - run: poetry run mypy - - pytest: - name: pytest [${{ matrix.os.name }} / Python ${{ matrix.python-version }}] - runs-on: ${{ matrix.os.image }} - if: needs.changes.outputs.pytest == 'true' - needs: - changes - - lockfile strategy: matrix: os: @@ -136,70 +94,16 @@ jobs: image: windows-2022 python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] fail-fast: false - steps: - - uses: actions/checkout@v4 - - - uses: ./.github/actions/bootstrap-poetry - with: - python-version: ${{ matrix.python-version }} - - - run: poetry install --sync --with github-actions - - - run: poetry env info - - - run: poetry show - - - run: poetry run pytest --integration -v - env: - POETRY_TEST_INTEGRATION_GIT_USERNAME: ${{ github.actor }} - POETRY_TEST_INTEGRATION_GIT_PASSWORD: ${{ github.token }} - - - run: git diff --exit-code --stat HEAD - - pytest-export: - name: pytest (poetry-plugin-export) [${{ matrix.os.name }} / Python ${{ matrix.python-version }}] - runs-on: ${{ matrix.os.image }} - if: needs.changes.outputs.pytest-export == 'true' - needs: - - changes - - lockfile - strategy: - matrix: - os: - - name: Ubuntu - image: ubuntu-22.04 - - name: macOS - image: macos-12 - - name: Windows - image: windows-2022 - python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] - fail-fast: false - steps: - - uses: actions/checkout@v4 - - - uses: ./.github/actions/bootstrap-poetry - with: - python-version: ${{ matrix.python-version }} - - - run: poetry install --sync --with github-actions - - - run: poetry env info - - - run: poetry show - - - id: poetry-plugin-export - run: echo version=$(poetry run pip list --format json | jq -r '.[] | select(.name == "poetry-plugin-export").version') >> $GITHUB_OUTPUT - - - uses: actions/checkout@v4 - with: - path: poetry-plugin-export - repository: python-poetry/poetry-plugin-export - ref: refs/tags/${{ steps.poetry-plugin-export.outputs.version }} - - - run: poetry run -C .. pytest -v - working-directory: ./poetry-plugin-export - - - run: git -C poetry-plugin-export diff --exit-code --stat HEAD + # Use this matrix with multiple jobs defined in a reusable workflow: + uses: ./.github/workflows/.tests.yaml + with: + os-name: ${{ matrix.os.name }} + os-image: ${{ matrix.os.image }} + python-version: ${{ matrix.python-version }} + run-mypy: ${{ needs.changes.outputs.mypy == 'true' }} + run-pytest: ${{ needs.changes.outputs.pytest == 'true' }} + run-pytest-export: ${{ needs.changes.outputs.pytest-export == 'true' }} + secrets: inherit status: name: Status @@ -208,8 +112,6 @@ jobs: needs: - lockfile - fixtures-pypi - - mypy - - pytest - - pytest-export + - tests-matrix steps: - run: ${{ (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) && 'false' || 'true' }}