Skip to content

Commit 2eeac52

Browse files
committed
👷 Add GitHub Actions for tests
1 parent 5f7b16f commit 2eeac52

File tree

2 files changed

+157
-0
lines changed

2 files changed

+157
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Test Redistribute
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
test-redistribute:
14+
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
package:
18+
- fastapi-cli-slim
19+
- fastapi-cli
20+
steps:
21+
- name: Dump GitHub context
22+
env:
23+
GITHUB_CONTEXT: ${{ toJson(github) }}
24+
run: echo "$GITHUB_CONTEXT"
25+
- uses: actions/checkout@v4
26+
- name: Set up Python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: "3.10"
30+
# Issue ref: https://github.com/actions/setup-python/issues/436
31+
# cache: "pip"
32+
# cache-dependency-path: pyproject.toml
33+
- name: Install build dependencies
34+
run: pip install build
35+
- name: Build source distribution
36+
env:
37+
TIANGOLO_BUILD_PACKAGE: ${{ matrix.package }}
38+
run: python -m build --sdist
39+
- name: Decompress source distribution
40+
run: |
41+
cd dist
42+
tar xvf fastapi-cli*.tar.gz
43+
- name: Install test dependencies
44+
run: |
45+
cd dist/fastapi-cli*/
46+
pip install -r requirements-tests.txt
47+
- name: Run source distribution tests
48+
run: |
49+
cd dist/fastapi-cli*/
50+
bash scripts/test.sh
51+
- name: Build wheel distribution
52+
run: |
53+
cd dist
54+
pip wheel --no-deps fastapi-cli*.tar.gz

.github/workflows/test.yml

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
name: Test
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
schedule:
12+
# cron every week on monday
13+
- cron: "0 0 * * 1"
14+
15+
jobs:
16+
test:
17+
runs-on: ubuntu-latest
18+
strategy:
19+
matrix:
20+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
21+
fail-fast: false
22+
steps:
23+
- name: Dump GitHub context
24+
env:
25+
GITHUB_CONTEXT: ${{ toJson(github) }}
26+
run: echo "$GITHUB_CONTEXT"
27+
- uses: actions/checkout@v4
28+
- name: Set up Python
29+
uses: actions/setup-python@v5
30+
with:
31+
python-version: ${{ matrix.python-version }}
32+
# Issue ref: https://github.com/actions/setup-python/issues/436
33+
# cache: "pip"
34+
# cache-dependency-path: pyproject.toml
35+
- uses: actions/cache@v3
36+
id: cache
37+
with:
38+
path: ${{ env.pythonLocation }}
39+
key: ${{ runner.os }}-python-${{ env.pythonLocation }}-${{ hashFiles('pyproject.toml', 'requirements-tests.txt') }}
40+
- name: Install Dependencies
41+
if: steps.cache.outputs.cache-hit != 'true'
42+
run: pip install -r requirements-tests.txt
43+
- name: Lint
44+
run: bash scripts/lint.sh
45+
- run: mkdir coverage
46+
- run: bash ./scripts/test-files.sh
47+
- name: Test
48+
run: bash scripts/test.sh
49+
env:
50+
COVERAGE_FILE: coverage/.coverage.${{ runner.os }}-py${{ matrix.python-version }}
51+
CONTEXT: ${{ runner.os }}-py${{ matrix.python-version }}
52+
- name: Store coverage files
53+
uses: actions/upload-artifact@v3
54+
with:
55+
name: coverage
56+
path: coverage
57+
58+
coverage-combine:
59+
needs: [test]
60+
runs-on: ubuntu-latest
61+
steps:
62+
- name: Dump GitHub context
63+
env:
64+
GITHUB_CONTEXT: ${{ toJson(github) }}
65+
run: echo "$GITHUB_CONTEXT"
66+
- uses: actions/checkout@v4
67+
- uses: actions/setup-python@v5
68+
with:
69+
python-version: '3.8'
70+
# Issue ref: https://github.com/actions/setup-python/issues/436
71+
# cache: "pip"
72+
# cache-dependency-path: pyproject.toml
73+
- name: Get coverage files
74+
uses: actions/download-artifact@v3
75+
with:
76+
name: coverage
77+
path: coverage
78+
- run: pip install coverage[toml]
79+
- run: ls -la coverage
80+
- run: coverage combine coverage
81+
- run: coverage report
82+
- run: coverage html --show-contexts --title "Coverage for ${{ github.sha }}"
83+
- name: Store coverage HTML
84+
uses: actions/upload-artifact@v3
85+
with:
86+
name: coverage-html
87+
path: htmlcov
88+
89+
# https://github.com/marketplace/actions/alls-green#why
90+
check: # This job does nothing and is only used for the branch protection
91+
if: always()
92+
needs:
93+
- coverage-combine
94+
runs-on: ubuntu-latest
95+
steps:
96+
- name: Dump GitHub context
97+
env:
98+
GITHUB_CONTEXT: ${{ toJson(github) }}
99+
run: echo "$GITHUB_CONTEXT"
100+
- name: Decide whether the needed jobs succeeded or failed
101+
uses: re-actors/alls-green@release/v1
102+
with:
103+
jobs: ${{ toJSON(needs) }}

0 commit comments

Comments
 (0)