-
Notifications
You must be signed in to change notification settings - Fork 7
117 lines (99 loc) · 3.31 KB
/
api-pr-validation.yml
File metadata and controls
117 lines (99 loc) · 3.31 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
name: API PR Validation
on:
pull_request:
branches: ["main"]
paths:
- "api/**"
- ".github/workflows/api-pr-validation.yml"
env:
REGISTRY: cerit.io
IMAGE_NAME: mol-view-stories/mvs-api
jobs:
lint-and-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install dependencies
run: |
cd api
pip install -r requirements.txt
pip install flake8 black isort pytest
- name: Run linting (flake8)
run: |
cd api
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run code formatting check (black)
run: |
cd api
python -m black --check --diff .
- name: Run import sorting check (isort)
run: |
cd api
python -m isort --check-only --diff .
- name: Run tests
run: |
cd api
python -m pytest tests/ -v --cov=. --cov-report=xml --cov-report=html
- name: Upload coverage reports
uses: codecov/codecov-action@v3
with:
file: ./api/coverage.xml
flags: api
name: api-coverage
docker-build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build Docker image (without pushing)
uses: docker/build-push-action@v5
with:
context: ./api
push: false
load: true
tags: mol-view-stories-api:pr-test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Verify Docker image
run: |
docker images mol-view-stories-api:pr-test
docker run --rm mol-view-stories-api:pr-test python --version
docker-push-pr:
needs: lint-and-test
runs-on: ubuntu-latest
# Only run for PRs from this repository (secrets are not available for forks)
if: github.event.pull_request.head.repo.fork == false
outputs:
image_digest: ${{ steps.build_and_push_pr.outputs.digest }}
image_tag: pr-${{ github.event.number }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.CERIT_REGISTRY_USERNAME }}
password: ${{ secrets.CERIT_REGISTRY_PASSWORD }}
- name: Build and push PR image
id: build_and_push_pr
uses: docker/build-push-action@v5
with:
context: ./api
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:pr-${{ github.event.number }}-${{ github.sha }}
platforms: linux/amd64
cache-from: type=gha
cache-to: type=gha,mode=max