105 lines (100 loc) · 4.12 KB
/
test-on-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# This workflow will check the project called `fizz_buzz` within the `better-python-with-ci-cd`
# repository for changes, add label, and then install Python, dependencies, run lint and tests
name: Test on PR
on:
push:
branches: [ main ]
pull_request:
types: [ opened, synchronize ]
branches: [ main ]
jobs:
test-fizz_buzz:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: [3.10.5]
steps:
- name: Set up node.js 12
uses: actions/setup-node@v2
with:
node-version: '12'
- name: Checkout code
uses: actions/checkout@v3
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v34.3.0
- name: Check for changes
env:
CONTAINS_PROJECT: ${{ contains(steps.changed-files.outputs.all_changed_files, 'fizz_buzz/') }}
CONTAINS_PYPROJECT_TOML: ${{ contains(steps.changed-files.outputs.all_changed_files, 'fizz_buzz/pyproject.toml') }}
run: |
echo "PROJECT_CHANGED=$(echo $CONTAINS_PROJECT)" >> $GITHUB_ENV
echo "PYPROJECT_TOML_CHANGED=$(echo $CONTAINS_PYPROJECT_TOML)" >> $GITHUB_ENV
- name: Exit if version unchanged
if: env.PROJECT_CHANGED == 'true' && env.PYPROJECT_TOML_CHANGED == 'false'
run: exit 1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
if: env.PROJECT_CHANGED == 'true'
run: pip install poetry
- name: Build fizz_buzz project
if: env.PROJECT_CHANGED == 'true'
working-directory: ./fizz_buzz
run: poetry install
- name: Run lint on fizz_buzz
if: env.PROJECT_CHANGED == 'true'
working-directory: ./fizz_buzz
run: |
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --max-complexity=30 --max-line-length=120 --statistics
- name: Test fizz_buzz with pytest
if: env.PROJECT_CHANGED == 'true'
working-directory: ./fizz_buzz/tests
run: poetry run pytest .
test-docker_python_postgres_tutorial:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
python-version: [3.10.5]
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v34.3.0
- name: Check for changes
env:
CONTAINS_PROJECT: ${{ contains(steps.changed-files.outputs.all_changed_files, 'docker_python_postgres_tutorial/') }}
CONTAINS_PYPROJECT_TOML: ${{ contains(steps.changed-files.outputs.all_changed_files, 'docker_python_postgres_tutorial/pyproject.toml') }}
run: |
echo "PROJECT_CHANGED=$(echo $CONTAINS_PROJECT)" >> $GITHUB_ENV
echo "PYPROJECT_TOML_CHANGED=$(echo $CONTAINS_PYPROJECT_TOML)" >> $GITHUB_ENV
- name: Exit if version unchanged
if: env.PROJECT_CHANGED == 'true' && env.PYPROJECT_TOML_CHANGED == 'false'
run: exit 1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
if: env.PROJECT_CHANGED == 'true'
run: pip install poetry
- name: Build docker_python_postgres_tutorial project
if: env.PROJECT_CHANGED == 'true'
working-directory: docker_python_postgres_tutorial
run: poetry install
- name: Run lint on docker_python_postgres_tutorial
if: env.PROJECT_CHANGED == 'true'
working-directory: docker_python_postgres_tutorial
run: |
poetry run flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
poetry run flake8 . --count --max-complexity=30 --max-line-length=120 --statistics
- name: Test docker_python_postgres_tutorial with pytest
if: env.PROJECT_CHANGED == 'true'
working-directory: docker_python_postgres_tutorial/tests
run: poetry run pytest .