-
Notifications
You must be signed in to change notification settings - Fork 23
145 lines (121 loc) · 3.85 KB
/
python-app.yml
File metadata and controls
145 lines (121 loc) · 3.85 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# Building and testing Python
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: Python CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
lint:
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6.0.1
- name: Lint commit messages
uses: wagoid/commitlint-github-action@v6.2.1
- name: Set up Python
uses: actions/setup-python@v6.1.0
with:
python-version-file: '.python-version'
cache: 'pip'
- name: Install lint dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-lint.txt
- name: Lint with Flake8
run: |
flake8 .
- name: Check code formatting with Black
run: |
black --check .
test:
needs: lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout repository
uses: actions/checkout@v6.0.1
- name: Set up Python
uses: actions/setup-python@v6.1.0
with:
python-version-file: '.python-version'
cache: 'pip'
- name: Install test dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements-test.txt
- name: Run tests with pytest
run: |
pytest -v
- name: Generate coverage report
run: |
pytest --cov=./ --cov-report=xml --cov-report=term
- name: Upload coverage report artifact
uses: actions/upload-artifact@v6.0.0
with:
name: coverage.xml
path: ./coverage.xml
coverage:
needs: test
runs-on: ubuntu-latest
permissions:
contents: read
# Only run coverage for PRs from the same repository (not forks)
# This ensures secrets are available for Codecov and Codacy
if: github.event_name == 'push' || github.event.pull_request.head.repo.full_name == github.repository
strategy:
matrix:
service: [codecov, codacy]
steps:
- name: Checkout repository
uses: actions/checkout@v6.0.1
- name: Download coverage report artifact
uses: actions/download-artifact@v7.0.0
with:
name: coverage.xml
- name: Upload coverage report to ${{ matrix.service }}
if: ${{ matrix.service == 'codecov' }}
uses: codecov/codecov-action@v5.5.2
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: coverage.xml
- name: Upload coverage report to ${{ matrix.service }}
if: ${{ matrix.service == 'codacy' }}
uses: codacy/codacy-coverage-reporter-action@v1.3.0
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: coverage.xml
container:
needs: coverage
if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/master' }}
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@v6.0.1
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3.6.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3.12.0
- name: Build and push Docker image to GitHub Container Registry
uses: docker/build-push-action@v6.18.0
with:
context: .
push: true
platforms: linux/amd64
provenance: false
cache-from: type=gha
cache-to: type=gha,mode=max
tags: |
ghcr.io/${{ github.repository }}:latest
ghcr.io/${{ github.repository }}:sha-${{ github.sha }}