|
| 1 | +--- |
| 2 | +name: tox |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: ["main"] |
| 6 | + pull_request: |
| 7 | + branches: ["main"] |
| 8 | + |
| 9 | +concurrency: |
| 10 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} |
| 11 | + cancel-in-progress: true |
| 12 | + |
| 13 | +env: |
| 14 | + FORCE_COLOR: 1 # tox, pytest |
| 15 | + PY_COLORS: 1 |
| 16 | + |
| 17 | +jobs: |
| 18 | + prepare: |
| 19 | + name: prepare |
| 20 | + runs-on: ubuntu-24.04 |
| 21 | + outputs: |
| 22 | + matrix: ${{ steps.generate_matrix.outputs.matrix }} |
| 23 | + steps: |
| 24 | + - name: Determine matrix |
| 25 | + id: generate_matrix |
| 26 | + uses: coactions/dynamic-matrix@v3 |
| 27 | + with: |
| 28 | + min_python: "3.9" |
| 29 | + max_python: "3.12" |
| 30 | + default_python: "3.9" |
| 31 | + other_names: | |
| 32 | + lint |
| 33 | + docs |
| 34 | + pkg |
| 35 | + # ^ arm64 runner is using py311 for matching python version used in AAP 2.5 |
| 36 | + platforms: linux,macos,linux-arm64:ubuntu-24.04-arm64-2core |
| 37 | + skip_explode: "1" |
| 38 | + build: |
| 39 | + name: ${{ matrix.name }} |
| 40 | + runs-on: ${{ matrix.os || 'ubuntu-24.04' }} |
| 41 | + needs: |
| 42 | + - prepare |
| 43 | + strategy: |
| 44 | + fail-fast: false |
| 45 | + matrix: ${{ fromJson(needs.prepare.outputs.matrix) }} |
| 46 | + steps: |
| 47 | + |
| 48 | + - uses: actions/checkout@v4 |
| 49 | + with: |
| 50 | + fetch-depth: 0 # needed by setuptools-scm |
| 51 | + submodules: true |
| 52 | + |
| 53 | + - name: Set pre-commit cache |
| 54 | + uses: actions/cache@v4 |
| 55 | + if: ${{ contains(matrix.name, 'lint') }} |
| 56 | + with: |
| 57 | + path: | |
| 58 | + ~/.cache/pre-commit |
| 59 | + key: pre-commit-${{ matrix.name }}-${{ hashFiles('.pre-commit-config.yaml') }} |
| 60 | + |
| 61 | + - name: Set up Python ${{ matrix.python_version || '3.10' }} |
| 62 | + uses: actions/setup-python@v5 |
| 63 | + with: |
| 64 | + cache: pip |
| 65 | + python-version: ${{ matrix.python_version || '3.10' }} |
| 66 | + cache-dependency-path: "*requirements*.txt" |
| 67 | + |
| 68 | + - name: Install tox |
| 69 | + run: | |
| 70 | + python3 -m pip install --upgrade pip wheel tox |
| 71 | +
|
| 72 | + - run: ${{ matrix.command }} |
| 73 | + |
| 74 | + - run: ${{ matrix.command2 }} |
| 75 | + if: ${{ matrix.command2 }} |
| 76 | + |
| 77 | + - run: ${{ matrix.command3 }} |
| 78 | + if: ${{ matrix.command3 }} |
| 79 | + |
| 80 | + - run: ${{ matrix.command4 }} |
| 81 | + if: ${{ matrix.command4 }} |
| 82 | + |
| 83 | + - run: ${{ matrix.command5 }} |
| 84 | + if: ${{ matrix.command5 }} |
| 85 | + |
| 86 | + - name: Archive logs |
| 87 | + uses: actions/upload-artifact@v4 |
| 88 | + with: |
| 89 | + name: logs-${{ matrix.name }}.zip |
| 90 | + if-no-files-found: error |
| 91 | + path: | |
| 92 | + .tox/**/log/ |
| 93 | + .tox/**/coverage.xml |
| 94 | +
|
| 95 | + - name: Report failure if git reports dirty status |
| 96 | + run: | |
| 97 | + if [[ -n $(git status -s) ]]; then |
| 98 | + # shellcheck disable=SC2016 |
| 99 | + echo -n '::error file=git-status::' |
| 100 | + printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY" |
| 101 | + exit 99 |
| 102 | + fi |
| 103 | + # https://github.com/actions/toolkit/issues/193 |
| 104 | + check: |
| 105 | + if: always() |
| 106 | + environment: check |
| 107 | + permissions: |
| 108 | + id-token: write |
| 109 | + checks: read |
| 110 | + |
| 111 | + needs: |
| 112 | + - build |
| 113 | + |
| 114 | + runs-on: ubuntu-24.04 |
| 115 | + |
| 116 | + steps: |
| 117 | + # checkout needed for codecov action which needs codecov.yml file |
| 118 | + - uses: actions/checkout@v4 |
| 119 | + |
| 120 | + - name: Set up Python # likely needed for coverage |
| 121 | + uses: actions/setup-python@v5 |
| 122 | + with: |
| 123 | + python-version: "3.12" |
| 124 | + |
| 125 | + - run: pip3 install 'coverage>=7.5.1' |
| 126 | + |
| 127 | + - name: Merge logs into a single archive |
| 128 | + uses: actions/upload-artifact/merge@v4 |
| 129 | + with: |
| 130 | + name: logs.zip |
| 131 | + pattern: logs-*.zip |
| 132 | + # artifacts like py312.zip and py312-macos do have overlapping files |
| 133 | + separate-directories: true |
| 134 | + |
| 135 | + - name: Download artifacts |
| 136 | + uses: actions/download-artifact@v4 |
| 137 | + with: |
| 138 | + name: logs.zip |
| 139 | + path: . |
| 140 | + |
| 141 | + - name: Check for expected number of coverage reports |
| 142 | + run: .github/check-coverage.sh |
| 143 | + |
| 144 | + # Single uploads inside check job for codecov to allow use to retry |
| 145 | + # it when it fails without running tests again. Fails often enough! |
| 146 | + - name: Upload junit xml reports |
| 147 | + # PRs from forks might not have access to the secret |
| 148 | + if: env.CODECOV_TOKEN |
| 149 | + env: |
| 150 | + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN || env.CODECOV_TOKEN }} |
| 151 | + uses: codecov/test-results-action@v1 |
| 152 | + with: |
| 153 | + name: ${{ matrix.name }} |
| 154 | + files: "*/tests/output/junit/*.xml" |
| 155 | + fail_ci_if_error: true |
| 156 | + token: ${{ secrets.CODECOV_TOKEN }} |
| 157 | + |
| 158 | + - name: Upload coverage data |
| 159 | + uses: codecov/codecov-action@v4 |
| 160 | + with: |
| 161 | + name: ${{ matrix.name }} |
| 162 | + # verbose: true # optional (default = false) |
| 163 | + fail_ci_if_error: true |
| 164 | + use_oidc: true # cspell:ignore oidc |
| 165 | + files: "*/tests/output/reports/coverage.xml" |
| 166 | + |
| 167 | + # - name: Check codecov.io status |
| 168 | + # if: github.event_name == 'pull_request' |
| 169 | + # uses: coactions/codecov-status@main |
| 170 | + |
| 171 | + - name: Decide whether the needed jobs succeeded or failed |
| 172 | + uses: re-actors/alls-green@release/v1 |
| 173 | + with: |
| 174 | + jobs: ${{ toJSON(needs) }} |
| 175 | + |
| 176 | + - name: Delete Merged Artifacts |
| 177 | + uses: actions/upload-artifact/merge@v4 |
| 178 | + with: |
| 179 | + delete-merged: true |
0 commit comments