| 1 |
name: Latest commit |
| 2 |
|
| 3 |
env: |
| 4 |
CACHE_VERSION: 1 |
| 5 |
DEFAULT_PYTHON: "3.14" |
| 6 |
PREK_HOME: ~/.cache/prek |
| 7 |
VENV: venv |
| 8 |
|
| 9 |
on: |
| 10 |
schedule: |
| 11 |
- cron: "2 4 * * 0" # weekly |
| 12 |
workflow_dispatch: |
| 13 |
push: |
| 14 |
# pull_request: |
| 15 |
|
| 16 |
jobs: |
| 17 |
# Check shellscripts |
| 18 |
shellcheck: |
| 19 |
name: Shellcheck |
| 20 |
runs-on: ubuntu-latest |
| 21 |
steps: |
| 22 |
- name: Check out committed code |
| 23 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 24 |
- name: Run ShellCheck |
| 25 |
uses: ludeeus/action-shellcheck@master |
| 26 |
|
| 27 |
ruff: |
| 28 |
runs-on: ubuntu-latest |
| 29 |
name: Ruff check and force |
| 30 |
steps: |
| 31 |
- name: Check out committed code |
| 32 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 33 |
with: |
| 34 |
persist-credentials: false |
| 35 |
- name: Use python |
| 36 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 37 |
with: |
| 38 |
python-version: ${{ env.DEFAULT_PYTHON }} |
| 39 |
- name: Prepare python |
| 40 |
run: | |
| 41 |
pip install uv |
| 42 |
uv venv --seed venv |
| 43 |
. venv/bin/activate |
| 44 |
uv pip install ruff -r requirements.txt -r requirements-test.txt |
| 45 |
- name: Ruff (with fix) |
| 46 |
run: | |
| 47 |
. venv/bin/activate |
| 48 |
ruff check airos/ tests/ |
| 49 |
- name: If needed, commit ruff changes to the pull request |
| 50 |
if: failure() |
| 51 |
run: | |
| 52 |
. venv/bin/activate |
| 53 |
ruff format airos/ tests/ |
| 54 |
git config --global user.name 'autoruff' |
| 55 |
git config --global user.email '[email protected]' |
| 56 |
git remote set-url origin https://x-access-token:${{ secrets.PAT_CT }}@github.com/$GITHUB_REPOSITORY |
| 57 |
git checkout $GITHUB_HEAD_REF |
| 58 |
git commit -am "fixup: ${GITHUB_REF##*/} Python code fixed using ruff" |
| 59 |
git push origin ${GITHUB_REF##*/} |
| 60 |
|
| 61 |
commitcheck: |
| 62 |
runs-on: ubuntu-latest |
| 63 |
name: Check commit |
| 64 |
needs: |
| 65 |
- ruff |
| 66 |
steps: |
| 67 |
- name: Check out committed code |
| 68 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 69 |
- name: Use python |
| 70 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 71 |
with: |
| 72 |
python-version: ${{ env.DEFAULT_PYTHON }} |
| 73 |
- name: Prepare python |
| 74 |
run: | |
| 75 |
pip install uv |
| 76 |
uv venv --seed venv |
| 77 |
. venv/bin/activate |
| 78 |
uv pip install prek -r requirements.txt -r requirements-test.txt |
| 79 |
prek install |
| 80 |
- name: Full prek (pre-commit) |
| 81 |
run: | |
| 82 |
. venv/bin/activate |
| 83 |
SKIP=no-commit-to-branch prek run --show-diff-on-failure --color=always --all-files |
| 84 |
|
| 85 |
pytest: |
| 86 |
runs-on: ubuntu-latest |
| 87 |
name: Run pytest using Python ${{ matrix.python-version }} |
| 88 |
needs: |
| 89 |
- ruff |
| 90 |
- commitcheck |
| 91 |
strategy: |
| 92 |
matrix: |
| 93 |
python-version: ["3.14"] |
| 94 |
steps: |
| 95 |
- name: Check out committed code |
| 96 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 97 |
- name: Use python ${{matrix.python-version}} |
| 98 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 99 |
with: |
| 100 |
python-version: ${{matrix.python-version}} |
| 101 |
- name: Prepare python |
| 102 |
run: | |
| 103 |
pip install uv |
| 104 |
uv venv --seed venv |
| 105 |
. venv/bin/activate |
| 106 |
uv pip install -r requirements.txt -r requirements-test.txt |
| 107 |
- name: Run all tests |
| 108 |
run: | |
| 109 |
. venv/bin/activate |
| 110 |
pytest --log-level info tests/ --cov='airos/' |
| 111 |
- name: Upload coverage artifact |
| 112 |
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a |
| 113 |
with: |
| 114 |
name: coverage-${{ matrix.python-version }} |
| 115 |
path: .coverage |
| 116 |
if-no-files-found: error |
| 117 |
include-hidden-files: true |
| 118 |
|
| 119 |
mypy: |
| 120 |
runs-on: ubuntu-latest |
| 121 |
name: Run mypy |
| 122 |
needs: |
| 123 |
- ruff |
| 124 |
- pytest |
| 125 |
steps: |
| 126 |
- name: Check out committed code |
| 127 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 128 |
with: |
| 129 |
persist-credentials: false |
| 130 |
- name: Use python |
| 131 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 132 |
with: |
| 133 |
python-version: ${{ env.DEFAULT_PYTHON }} |
| 134 |
- name: Prepare python |
| 135 |
run: | |
| 136 |
pip install uv |
| 137 |
uv venv --seed venv |
| 138 |
. venv/bin/activate |
| 139 |
uv pip install -r requirements.txt -r requirements-test.txt |
| 140 |
- name: Run mypy |
| 141 |
run: | |
| 142 |
. venv/bin/activate |
| 143 |
pip list | grep -i mypy |
| 144 |
mypy airos/ |
| 145 |
|
| 146 |
coverage: |
| 147 |
name: Process test coverage |
| 148 |
runs-on: ubuntu-latest |
| 149 |
needs: |
| 150 |
- ruff |
| 151 |
- pytest |
| 152 |
- mypy |
| 153 |
steps: |
| 154 |
- name: Check out committed code |
| 155 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 156 |
- name: Use python |
| 157 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 158 |
with: |
| 159 |
python-version: ${{ env.DEFAULT_PYTHON }} |
| 160 |
- name: Prepare python |
| 161 |
run: | |
| 162 |
pip install uv |
| 163 |
uv venv --seed venv |
| 164 |
. venv/bin/activate |
| 165 |
uv pip install -r requirements.txt -r requirements-test.txt |
| 166 |
- name: Download all coverage artifacts |
| 167 |
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c |
| 168 |
with: |
| 169 |
pattern: coverage-* |
| 170 |
merge-multiple: true |
| 171 |
path: ${{ github.workspace }}/artifacts |
| 172 |
- name: Combine coverage results |
| 173 |
run: | |
| 174 |
. venv/bin/activate |
| 175 |
coverage combine artifacts/.coverage* |
| 176 |
coverage report --fail-under=80 |
| 177 |
coverage xml |
| 178 |
- name: Upload coverage to Codecov |
| 179 |
uses: codecov/codecov-action@fb8b3582c8e4def4969c97caa2f19720cb33a72f |
| 180 |
env: |
| 181 |
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} |
| 182 |
slug: CoMPaTech/python-airos |
| 183 |
|
| 184 |
test-publishing: |
| 185 |
name: Build and publish Python 🐍 distributions 📦 to TestPyPI |
| 186 |
runs-on: ubuntu-latest |
| 187 |
environment: testpypi |
| 188 |
permissions: |
| 189 |
contents: read |
| 190 |
id-token: write |
| 191 |
needs: |
| 192 |
- coverage |
| 193 |
# - mypy |
| 194 |
steps: |
| 195 |
- name: Check out committed code |
| 196 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 197 |
- name: Use python |
| 198 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 199 |
with: |
| 200 |
python-version: ${{ env.DEFAULT_PYTHON }} |
| 201 |
- name: Prepare python |
| 202 |
run: | |
| 203 |
pip install uv |
| 204 |
uv venv --seed venv |
| 205 |
. venv/bin/activate |
| 206 |
uv pip install toml |
| 207 |
- name: Check for existing package on TestPyPI |
| 208 |
id: check_package |
| 209 |
run: | |
| 210 |
. venv/bin/activate |
| 211 |
PACKAGE_VERSION=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['version'])") |
| 212 |
PACKAGE_NAME=$(python -c "import toml; print(toml.load('pyproject.toml')['project']['name'])") |
| 213 |
echo "Checking for package: $PACKAGE_NAME==$PACKAGE_VERSION" |
| 214 |
|
| 215 |
if curl -s "https://test.pypi.org/pypi/$PACKAGE_NAME/json" | jq -r '.releases | keys[]' | grep -q "^$PACKAGE_VERSION$"; then |
| 216 |
echo "Package version already exists. Skipping upload." |
| 217 |
echo "should_publish=false" >> $GITHUB_OUTPUT |
| 218 |
else |
| 219 |
echo "Package version does not exist. Proceeding with upload." |
| 220 |
echo "should_publish=true" >> $GITHUB_OUTPUT |
| 221 |
fi |
| 222 |
- name: Build |
| 223 |
if: steps.check_package.outputs.should_publish == 'true' |
| 224 |
run: | |
| 225 |
. venv/bin/activate |
| 226 |
uv build |
| 227 |
- name: Generate PEP 740 Attestations |
| 228 |
if: steps.check_package.outputs.should_publish == 'true' |
| 229 |
uses: astral-sh/attest-action@f589a42a7efb6fe400b4f400de60b4bc90390027 # v0.0.6 |
| 230 |
- name: Publish distribution 📦 to TestPyPI |
| 231 |
if: steps.check_package.outputs.should_publish == 'true' |
| 232 |
run: | |
| 233 |
. venv/bin/activate |
| 234 |
uv publish --publish-url https://test.pypi.org/legacy/ |
| 235 |
|
| 236 |
|
| 237 |
complexity: |
| 238 |
name: Process test complexity |
| 239 |
runs-on: ubuntu-latest |
| 240 |
needs: |
| 241 |
- coverage |
| 242 |
steps: |
| 243 |
- name: Check out committed code |
| 244 |
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 |
| 245 |
- name: Use python |
| 246 |
uses: actions/setup-python@ece7cb06caefa5fff74198d8649806c4678c61a1 |
| 247 |
with: |
| 248 |
python-version: ${{ env.DEFAULT_PYTHON }} |
| 249 |
- name: Prepare python |
| 250 |
run: | |
| 251 |
pip install uv |
| 252 |
uv venv --seed venv |
| 253 |
. venv/bin/activate |
| 254 |
uv pip install -r requirements.txt -r requirements-test.txt |
| 255 |
- name: Run complexity report (click to view details) |
| 256 |
run: | |
| 257 |
. venv/bin/activate |
| 258 |
echo "Showing complexity higher or equal to 'C'" |
| 259 |
radon cc airos/ tests/ -s -nc --no-assert |