|
| 1 | +--- |
1 | 2 | name: tox
|
2 | 3 |
|
3 | 4 | on:
|
4 |
| - create: # is used for publishing to PyPI and TestPyPI |
5 |
| - tags: # any tag regardless of its name, no branches |
6 |
| - push: # only publishes pushes to the main branch to TestPyPI |
7 |
| - branches: # any integration branch but not tag |
8 |
| - - "master" |
9 |
| - tags-ignore: |
10 |
| - - "**" |
| 5 | + push: # only publishes pushes to the main branch to TestPyPI |
| 6 | + branches: # any integration branch but not tag |
| 7 | + - "main" |
11 | 8 | pull_request:
|
12 |
| - schedule: |
13 |
| - - cron: 1 0 * * * # Run daily at 0:01 UTC |
| 9 | + branches: |
| 10 | + - "main" |
| 11 | + |
| 12 | +concurrency: |
| 13 | + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }} |
| 14 | + cancel-in-progress: true |
| 15 | + |
| 16 | +env: |
| 17 | + FORCE_COLOR: 1 # tox, pytest, ansible-lint |
| 18 | + PY_COLORS: 1 |
14 | 19 |
|
15 | 20 | jobs:
|
| 21 | + pre: |
| 22 | + name: pre |
| 23 | + runs-on: ubuntu-22.04 |
| 24 | + outputs: |
| 25 | + matrix: ${{ steps.generate_matrix.outputs.matrix }} |
| 26 | + steps: |
| 27 | + - name: Determine matrix |
| 28 | + id: generate_matrix |
| 29 | + uses: coactions/dynamic-matrix@v1 |
| 30 | + with: |
| 31 | + min_python: "3.9" |
| 32 | + max_python: "3.11" |
| 33 | + other_names: | |
| 34 | + lint |
| 35 | + pkg |
| 36 | +
|
| 37 | + platforms: linux,macos |
16 | 38 | build:
|
17 |
| - name: ${{ matrix.tox_env }} |
18 |
| - runs-on: ubuntu-latest |
| 39 | + name: ${{ matrix.name }} |
| 40 | + runs-on: ${{ matrix.os || 'ubuntu-22.04' }} |
| 41 | + needs: |
| 42 | + - pre |
| 43 | + defaults: |
| 44 | + run: |
| 45 | + shell: ${{ matrix.shell || 'bash'}} |
19 | 46 | strategy:
|
20 | 47 | fail-fast: false
|
21 |
| - matrix: |
22 |
| - include: |
23 |
| - - tox_env: lint |
24 |
| - # - tox_env: docs |
25 |
| - - tox_env: py36 |
26 |
| - PREFIX: PYTEST_REQPASS=0 |
27 |
| - - tox_env: py37 |
28 |
| - PREFIX: PYTEST_REQPASS=0 |
29 |
| - - tox_env: py38 |
30 |
| - PREFIX: PYTEST_REQPASS=0 |
31 |
| - - tox_env: packaging |
32 |
| - |
| 48 | + matrix: ${{ fromJson(needs.pre.outputs.matrix) }} |
| 49 | + # max-parallel: 5 |
| 50 | + # The matrix testing goal is to cover the *most likely* environments |
| 51 | + # which are expected to be used by users in production. Avoid adding a |
| 52 | + # combination unless there are good reasons to test it, like having |
| 53 | + # proof that we failed to catch a bug by not running it. Using |
| 54 | + # distribution should be preferred instead of custom builds. |
| 55 | + env: |
| 56 | + # vars safe to be passed to wsl: |
| 57 | + WSLENV: FORCE_COLOR:PYTEST_REQPASS:TOXENV:GITHUB_STEP_SUMMARY |
| 58 | + # Number of expected test passes, safety measure for accidental skip of |
| 59 | + # tests. Update value if you add/remove tests. |
| 60 | + PYTEST_REQPASS: 0 |
33 | 61 | steps:
|
34 |
| - - uses: actions/checkout@v1 |
35 |
| - - name: Find python version |
36 |
| - id: py_ver |
37 |
| - shell: python |
38 |
| - if: ${{ contains(matrix.tox_env, 'py') }} |
39 |
| - run: | |
40 |
| - v = '${{ matrix.tox_env }}'.split('-')[0].lstrip('py') |
41 |
| - print('::set-output name=version::{0}.{1}'.format(v[0],v[1:])) |
42 |
| - # Even our lint and other envs need access to tox |
43 |
| - - name: Install a default Python |
44 |
| - uses: actions/setup-python@v2 |
45 |
| - if: ${{ ! contains(matrix.tox_env, 'py') }} |
46 |
| - # Be sure to install the version of python needed by a specific test, if necessary |
47 |
| - - name: Set up Python version |
48 |
| - uses: actions/setup-python@v2 |
49 |
| - if: ${{ contains(matrix.tox_env, 'py') }} |
| 62 | + |
| 63 | + - uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + fetch-depth: 0 # needed by setuptools-scm |
| 66 | + submodules: true |
| 67 | + |
| 68 | + - name: Set pre-commit cache |
| 69 | + uses: actions/cache@v3 |
| 70 | + if: ${{ matrix.passed_name == 'lint' }} |
| 71 | + with: |
| 72 | + path: | |
| 73 | + ~/.cache/pre-commit |
| 74 | + key: pre-commit-${{ matrix.name || matrix.passed_name }}-${{ hashFiles('.pre-commit-config.yaml') }} |
| 75 | + |
| 76 | + - name: Set ansible cache(s) |
| 77 | + uses: actions/cache@v3 |
50 | 78 | with:
|
51 |
| - python-version: ${{ steps.py_ver.outputs.version }} |
52 |
| - - name: Install dependencies |
| 79 | + path: | |
| 80 | + .cache/eco |
| 81 | + examples/playbooks/collections/ansible_collections |
| 82 | + ~/.cache/ansible-compat |
| 83 | + ~/.ansible/collections |
| 84 | + ~/.ansible/roles |
| 85 | + key: ${{ matrix.name || matrix.passed_name }}-${{ hashFiles('tools/test-eco.sh', 'requirements.yml', 'examples/playbooks/collections/requirements.yml') }} |
| 86 | + |
| 87 | + - name: Set up Python ${{ matrix.python_version || '3.9' }} |
| 88 | + uses: actions/setup-python@v4 |
| 89 | + with: |
| 90 | + cache: pip |
| 91 | + python-version: ${{ matrix.python_version || '3.9' }} |
| 92 | + |
| 93 | + - name: Install tox |
53 | 94 | run: |
|
54 |
| - docker version |
55 |
| - docker info |
56 |
| - python -m pip install -U pip |
57 |
| - pip install tox |
58 |
| - - name: Run tox -e ${{ matrix.tox_env }} |
| 95 | + python3 -m pip install --upgrade pip |
| 96 | + python3 -m pip install --upgrade "tox>=4.0.0" |
| 97 | +
|
| 98 | + - name: Log installed dists |
| 99 | + run: python3 -m pip freeze --all |
| 100 | + |
| 101 | + - name: Initialize tox envs ${{ matrix.passed_name }} |
| 102 | + run: python3 -m tox --notest --skip-missing-interpreters false -vv -e ${{ matrix.passed_name }} |
| 103 | + timeout-minutes: 5 # average is under 1, but macos can be over 3 |
| 104 | + |
| 105 | + # sequential run improves browsing experience (almost no speed impact) |
| 106 | + - name: tox -e ${{ matrix.passed_name }} |
| 107 | + run: python3 -m tox -e ${{ matrix.passed_name }} |
| 108 | + |
| 109 | + # - name: Combine coverage data |
| 110 | + # if: ${{ startsWith(matrix.passed_name, 'py') }} |
| 111 | + # # produce a single .coverage file at repo root |
| 112 | + # run: tox -e coverage |
| 113 | + |
| 114 | + # - name: Upload coverage data |
| 115 | + # if: ${{ startsWith(matrix.passed_name, 'py') }} |
| 116 | + # uses: codecov/codecov-action@v3 |
| 117 | + # with: |
| 118 | + # name: ${{ matrix.passed_name }} |
| 119 | + # fail_ci_if_error: false # see https://github.com/codecov/codecov-action/issues/598 |
| 120 | + # token: ${{ secrets.CODECOV_TOKEN }} |
| 121 | + # verbose: true # optional (default = false) |
| 122 | + |
| 123 | + - name: Archive logs |
| 124 | + uses: actions/upload-artifact@v3 |
| 125 | + with: |
| 126 | + name: logs.zip |
| 127 | + path: .tox/**/log/ |
| 128 | + # https://github.com/actions/upload-artifact/issues/123 |
| 129 | + continue-on-error: true |
| 130 | + |
| 131 | + - name: Report failure if git reports dirty status |
59 | 132 | run: |
|
60 |
| - echo "${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }}" |
61 |
| - ${{ matrix.PREFIX }} tox -e ${{ matrix.tox_env }} |
| 133 | + if [[ -n $(git status -s) ]]; then |
| 134 | + # shellcheck disable=SC2016 |
| 135 | + echo -n '::error file=git-status::' |
| 136 | + printf '### Failed as git reported modified and/or untracked files\n```\n%s\n```\n' "$(git status -s)" | tee -a "$GITHUB_STEP_SUMMARY" |
| 137 | + exit 99 |
| 138 | + fi |
| 139 | + # https://github.com/actions/toolkit/issues/193 |
| 140 | + |
| 141 | + check: # This job does nothing and is only used for the branch protection |
| 142 | + if: always() |
| 143 | + permissions: |
| 144 | + pull-requests: write # allow codenotify to comment on pull-request |
62 | 145 |
|
63 |
| - publish: |
64 |
| - name: Publish to PyPI registry |
65 | 146 | needs:
|
66 | 147 | - build
|
67 |
| - runs-on: ubuntu-latest |
68 | 148 |
|
69 |
| - env: |
70 |
| - PY_COLORS: 1 |
71 |
| - TOXENV: packaging |
| 149 | + runs-on: ubuntu-latest |
72 | 150 |
|
73 | 151 | steps:
|
74 |
| - - name: Switch to using Python 3.6 by default |
75 |
| - uses: actions/setup-python@v2 |
| 152 | + - name: Decide whether the needed jobs succeeded or failed |
| 153 | + uses: re-actors/alls-green@release/v1 |
76 | 154 | with:
|
77 |
| - python-version: 3.6 |
78 |
| - - name: Install tox |
79 |
| - run: python -m pip install --user tox |
| 155 | + jobs: ${{ toJSON(needs) }} |
| 156 | + |
80 | 157 | - name: Check out src from Git
|
81 |
| - uses: actions/checkout@v2 |
82 |
| - with: |
83 |
| - # Get shallow Git history (default) for tag creation events |
84 |
| - # but have a complete clone for any other workflows. |
85 |
| - # Both options fetch tags but since we're going to remove |
86 |
| - # one from HEAD in non-create-tag workflows, we need full |
87 |
| - # history for them. |
88 |
| - fetch-depth: >- |
89 |
| - ${{ |
90 |
| - ( |
91 |
| - github.event_name == 'create' && |
92 |
| - github.event.ref_type == 'tag' |
93 |
| - ) && |
94 |
| - 1 || 0 |
95 |
| - }} |
96 |
| - - name: Drop Git tags from HEAD for non-tag-create events |
97 |
| - if: >- |
98 |
| - github.event_name != 'create' || |
99 |
| - github.event.ref_type != 'tag' |
100 |
| - run: >- |
101 |
| - git tag --points-at HEAD |
102 |
| - | |
103 |
| - xargs git tag --delete |
104 |
| - - name: Build dists |
105 |
| - run: python -m tox |
106 |
| - - name: Publish to test.pypi.org |
107 |
| - if: >- |
108 |
| - ( |
109 |
| - github.event_name == 'push' && |
110 |
| - github.ref == format( |
111 |
| - 'refs/heads/{0}', github.event.repository.default_branch |
112 |
| - ) |
113 |
| - ) || |
114 |
| - ( |
115 |
| - github.event_name == 'create' && |
116 |
| - github.event.ref_type == 'tag' |
117 |
| - ) |
118 |
| - uses: pypa/gh-action-pypi-publish@master |
119 |
| - with: |
120 |
| - password: ${{ secrets.testpypi_password }} |
121 |
| - repository_url: https://test.pypi.org/legacy/ |
122 |
| - - name: Publish to pypi.org |
123 |
| - if: >- # "create" workflows run separately from "push" & "pull_request" |
124 |
| - github.event_name == 'create' && |
125 |
| - github.event.ref_type == 'tag' |
126 |
| - uses: pypa/gh-action-pypi-publish@master |
127 |
| - with: |
128 |
| - password: ${{ secrets.pypi_password }} |
| 158 | + uses: actions/checkout@v4 |
| 159 | + |
| 160 | + - name: Notify repository owners about lint change affecting them |
| 161 | + uses: sourcegraph/codenotify@v0.6.4 |
| 162 | + env: |
| 163 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 164 | + # https://github.com/sourcegraph/codenotify/issues/19 |
| 165 | + continue-on-error: true |
0 commit comments