|
| 1 | +on: |
| 2 | + workflow_call: |
| 3 | + inputs: |
| 4 | + enable-test: |
| 5 | + description: 'Enable test' |
| 6 | + default: true |
| 7 | + required: false |
| 8 | + type: boolean |
| 9 | + |
| 10 | + artifact-name: |
| 11 | + description: 'Artifact name' |
| 12 | + default: 'coverage-reports' |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + |
| 16 | + outputs: |
| 17 | + has-coverage-reports: |
| 18 | + description: 'This test has coverage reports or not' |
| 19 | + value: ${{ jobs.check.outputs.has-coverage-reports }} |
| 20 | + |
| 21 | +jobs: |
| 22 | + matrix_prep: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + outputs: |
| 25 | + matrix: ${{ steps.read-file.outputs.content }} |
| 26 | + steps: |
| 27 | + - name: Checkout |
| 28 | + uses: actions/checkout@v3 |
| 29 | + |
| 30 | + - name: Read YAML file |
| 31 | + id: read-file |
| 32 | + uses: ./.github/actions/read-yaml |
| 33 | + with: |
| 34 | + path: .github/settings/test_matrix.yml |
| 35 | + filter: '.matrix' |
| 36 | + |
| 37 | + build: |
| 38 | + needs: matrix_prep |
| 39 | + strategy: |
| 40 | + fail-fast: false |
| 41 | + matrix: ${{ fromJson(needs.matrix_prep.outputs.matrix) }} |
| 42 | + |
| 43 | + runs-on: ${{ matrix.os }} |
| 44 | + name: ${{ format('build ({0}, {1})', matrix.os, matrix.python-version) }} |
| 45 | + steps: |
| 46 | + - name: Checkout |
| 47 | + uses: actions/checkout@v3 |
| 48 | + |
| 49 | + - name: Set up Python ${{ matrix.python-version }} |
| 50 | + id: setup-python |
| 51 | + uses: actions/setup-python@v4 |
| 52 | + with: |
| 53 | + python-version: ${{ matrix.python-version }} |
| 54 | + |
| 55 | + - name: Set up Poetry ${{ matrix.poetry-version }} |
| 56 | + id: setup-poetry |
| 57 | + uses: ./.github/actions/setup-poetry |
| 58 | + with: |
| 59 | + cache-path: ${{ matrix.poetry-cache-paths }} |
| 60 | + cache-key: ${{ format(matrix.poetry-cache-key-fmt, matrix.poetry-version, matrix.os, steps.setup-python.outputs.python-version) }} |
| 61 | + poetry-version: ${{ matrix.poetry-version }} |
| 62 | + poetry-home: ${{ matrix.poetry-home }} |
| 63 | + poetry-path: ${{ matrix.poetry-path }} |
| 64 | + |
| 65 | + - name: Set up Poetry dependencies |
| 66 | + id: setup-poetry-dependencies |
| 67 | + uses: ./.github/actions/setup-poetry-dependencies |
| 68 | + with: |
| 69 | + cache-key: ${{ format(matrix.venv-cache-key-fmt, matrix.os, steps.setup-python.outputs.python-version, hashFiles('**/poetry.lock')) }} |
| 70 | + python-version: ${{ steps.setup-python.outputs.python-version }} |
| 71 | + poetry-install-args: --no-interaction --no-root --with dev |
| 72 | + |
| 73 | + - name: Test with pytest |
| 74 | + id: test-with-pytest |
| 75 | + if: inputs.enable-test == true |
| 76 | + run: | |
| 77 | + ${{ steps.setup-poetry-dependencies.outputs.venv-activate }} |
| 78 | + tox -e py -- -v --color=yes |
| 79 | + deactivate |
| 80 | + # Create a dummy file. |
| 81 | + touch "dummy-$(echo .coverage.*)" |
| 82 | +
|
| 83 | + - name: Upload coverage reports |
| 84 | + if: steps.test-with-pytest.conclusion != 'skipped' && matrix.enable-coverage == 'true' |
| 85 | + uses: actions/upload-artifact@v3 |
| 86 | + with: |
| 87 | + name: ${{ inputs.artifact-name }} |
| 88 | + path: .coverage.* |
| 89 | + retention-days: 1 |
| 90 | + |
| 91 | + - name: Upload dummy files |
| 92 | + if: steps.test-with-pytest.conclusion != 'skipped' && matrix.enable-coverage == 'true' |
| 93 | + uses: actions/upload-artifact@v3 |
| 94 | + with: |
| 95 | + name: dummy-files |
| 96 | + path: dummy-* |
| 97 | + retention-days: 1 |
| 98 | + |
| 99 | + check: |
| 100 | + needs: build |
| 101 | + runs-on: ubuntu-latest |
| 102 | + outputs: |
| 103 | + has-coverage-reports: ${{ steps.download.outputs.download-path != '' }} |
| 104 | + steps: |
| 105 | + - name: Download dummy files |
| 106 | + id: download |
| 107 | + continue-on-error: true |
| 108 | + uses: actions/download-artifact@v3 |
| 109 | + with: |
| 110 | + name: dummy-files |
0 commit comments