Skip to content

Commit 38c7d1b

Browse files
abnGobot1234
authored andcommitted
ci: refactor jobs and improve platform coverage (danielgtaylor#128)
1 parent 230f58b commit 38c7d1b

File tree

4 files changed

+108
-57
lines changed

4 files changed

+108
-57
lines changed

.github/workflows/ci.yml

+52-57
Original file line numberDiff line numberDiff line change
@@ -1,74 +1,69 @@
11
name: CI
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '**'
410

511
jobs:
6-
7-
check-formatting:
8-
runs-on: ubuntu-latest
9-
10-
name: Consult black on python formatting
11-
12+
tests:
13+
name: ${{ matrix.os }} / ${{ matrix.python-version }}
14+
runs-on: ${{ matrix.os }}-latest
15+
strategy:
16+
matrix:
17+
os: [Ubuntu, MacOS, Windows]
18+
python-version: [3.6, 3.7, 3.8]
19+
exclude:
20+
- os: Windows
21+
python-version: 3.6
1222
steps:
1323
- uses: actions/checkout@v2
14-
- uses: actions/setup-python@v2
15-
with:
16-
python-version: 3.7
17-
- uses: Gr1N/setup-poetry@v2
18-
- uses: actions/cache@v2
24+
25+
- name: Set up Python ${{ matrix.python-version }}
26+
uses: actions/setup-python@v1
1927
with:
20-
path: ~/.cache/pypoetry/virtualenvs
21-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
22-
restore-keys: |
23-
${{ runner.os }}-poetry-
24-
- name: Install dependencies
25-
run: poetry install
26-
- name: Run black
27-
run: poetry run poe check-style
28+
python-version: ${{ matrix.python-version }}
2829

29-
run-tests:
30-
runs-on: ubuntu-latest
30+
- name: Get full Python version
31+
id: full-python-version
32+
shell: bash
33+
run: echo ::set-output name=version::$(python -c "import sys; print('-'.join(str(v) for v in sys.version_info))")
3134

32-
name: Run tests with tox
35+
- name: Install poetry
36+
shell: bash
37+
run: |
38+
python -m pip install poetry
39+
echo "::set-env name=PATH::$HOME/.poetry/bin:$PATH"
3340
34-
strategy:
35-
matrix:
36-
python-version: [ '3.6', '3.7', '3.8']
41+
- name: Configure poetry
42+
shell: bash
43+
run: poetry config virtualenvs.in-project true
3744

38-
steps:
39-
- uses: actions/checkout@v2
40-
- uses: actions/setup-python@v2
45+
- name: Set up cache
46+
uses: actions/cache@v2
47+
id: cache
4148
with:
42-
python-version: ${{ matrix.python-version }}
43-
- uses: Gr1N/setup-poetry@v2
44-
- uses: actions/cache@v2
45-
with:
46-
path: ~/.cache/pypoetry/virtualenvs
47-
key: ${{ runner.os }}-poetry-${{ hashFiles('poetry.lock') }}
48-
restore-keys: |
49-
${{ runner.os }}-poetry-
49+
path: .venv
50+
key: venv-${{ runner.os }}-${{ steps.full-python-version.outputs.version }}-${{ hashFiles('**/poetry.lock') }}
51+
52+
- name: Ensure cache is healthy
53+
if: steps.cache.outputs.cache-hit == 'true'
54+
shell: bash
55+
run: poetry run pip --version >/dev/null 2>&1 || rm -rf .venv
56+
5057
- name: Install dependencies
58+
shell: bash
5159
run: |
52-
poetry run pip install --upgrade pip
60+
poetry run python -m pip install pip -U
5361
poetry install
54-
- name: Run tests
55-
run: |
56-
poetry run poe generate
57-
poetry run poe test
5862
59-
build-release:
60-
runs-on: ubuntu-latest
63+
- name: Generate code from proto files
64+
shell: bash
65+
run: poetry run python -m tests.generate -v
6166

62-
steps:
63-
- uses: actions/checkout@v2
64-
- uses: actions/setup-python@v2
65-
with:
66-
python-version: 3.7
67-
- uses: Gr1N/setup-poetry@v2
68-
- name: Build package
69-
run: poetry build
70-
- name: Publish package to PyPI
71-
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
72-
run: poetry publish -n
73-
env:
74-
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.pypi }}
67+
- name: Execute test suite
68+
shell: bash
69+
run: poetry run pytest tests/

.github/workflows/code-quality.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Code Quality
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- '**'
10+
11+
jobs:
12+
black:
13+
name: Black
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Run Black
18+
uses: lgeiger/black-action@master
19+
with:
20+
args: --check src/ tests/

.github/workflows/release.yml

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
tags:
8+
- '**'
9+
pull_request:
10+
branches:
11+
- '**'
12+
13+
jobs:
14+
packaging:
15+
name: Distribution
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Set up Python 3.8
20+
uses: actions/setup-python@v2
21+
with:
22+
python-version: 3.8
23+
- name: Install poetry
24+
run: python -m pip install poetry
25+
- name: Build package
26+
run: poetry build
27+
- name: Publish package to PyPI
28+
if: github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
29+
env:
30+
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.pypi }}
31+
run: poetry publish -n

tests/generate.py

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import asyncio
33
import os
44
from pathlib import Path
5+
import platform
56
import shutil
67
import sys
78
from typing import Set
@@ -134,6 +135,10 @@ def main():
134135
else:
135136
verbose = False
136137
whitelist = set(sys.argv[1:])
138+
139+
if platform.system() == "Windows":
140+
asyncio.set_event_loop(asyncio.ProactorEventLoop())
141+
137142
asyncio.get_event_loop().run_until_complete(generate(whitelist, verbose))
138143

139144

0 commit comments

Comments
 (0)