-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (134 loc) · 4.42 KB
/
ci.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
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
146
147
148
149
150
151
152
name: CI
on:
push:
pull_request:
workflow_dispatch:
inputs:
no-cache:
description: Disable the build caching
required: false
default: false
type: boolean
env:
ENABLE_DOCKER_DEPOT: ${{ vars.ENABLE_DOCKER_DEPOT == 'true' && github.event_name != 'pull_request' }}
IMAGE_BASE: ghcr.io/${{ github.repository }}
BUILD_PLATFORMS: linux/amd64, linux/arm64, linux/arm/v7
# BUILD_PLATFORMS: linux/amd64
PYTHON_VERSION: "3.10"
jobs:
python-lint:
name: Python Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install test dependencies
run: |
python -m pip install flake8 Flake8-pyproject
- name: Lint with flake8
run: |
flake8 src
docker-lint:
name: Docker Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: hadolint/hadolint-action@v3.1.0
with:
dockerfile: Dockerfile
ignore: DL3042
tests:
name: Unittests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python -m pip install --upgrade --no-cache-dir pip
python -m pip install --no-cache-dir -r requirements-test.txt
pip install --no-cache-dir --no-deps .
- name: Test
run: |
pytest --cov=calllogger --cov-report xml
- name: Upload test coverage to Codecov
continue-on-error: true
uses: codecov/codecov-action@v3.1.4
with:
flags: unittests
docker-build:
if: ${{ github.event_name != 'pull_request' }}
name: Build
runs-on: ubuntu-latest
needs: [docker-lint, python-lint, tests]
permissions:
contents: read
id-token: write
steps:
- name: Setup Depot Build
if: env.ENABLE_DOCKER_DEPOT == 'true'
uses: depot/setup-action@v1
- name: Setup Docker Buildkit
if: env.ENABLE_DOCKER_DEPOT == 'false'
uses: docker/setup-buildx-action@v2
- name: Set up QEMU
if: env.ENABLE_DOCKER_DEPOT == 'false'
uses: docker/setup-qemu-action@v2
- name: Login to Github Container Registry (Depot)
if: env.ENABLE_DOCKER_DEPOT == 'true'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.REGISTRY_TOKEN }}
- name: Login to Github Container Registry
if: env.ENABLE_DOCKER_DEPOT == 'false'
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ github.token }}
- name: Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.IMAGE_BASE }}
tags: |
type=semver,pattern=v{{version}}
type=ref,event=branch
type=ref,event=pr
labels: |
org.opencontainers.image.title=Calllogger
- name: Build/Push using Depot
if: env.ENABLE_DOCKER_DEPOT == 'true'
uses: depot/build-push-action@v1
with:
project: ${{ vars.DEPOT_PROJECT_ID }}
platforms: ${{ env.BUILD_PLATFORMS }}
build-args: |
REG_KEY=${{ secrets.REG_KEY }}
SENTRY_DSN=${{ secrets.SENTRY_DSN }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
no-cache: ${{ inputs.no-cache || 'false' }}
pull: ${{ inputs.no-cache || 'false' }}
push: true
- name: Build/Push using Buildkit
if: env.ENABLE_DOCKER_DEPOT == 'false'
uses: docker/build-push-action@v4
with:
platforms: ${{ env.BUILD_PLATFORMS }}
build-args: |
REG_KEY=${{ secrets.REG_KEY }}
SENTRY_DSN=${{ secrets.SENTRY_DSN }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.IMAGE_BASE }}:buildcache
cache-to: type=registry,ref=${{ env.IMAGE_BASE }}:buildcache,mode=max
no-cache: ${{ inputs.no-cache || 'false' }}
pull: ${{ inputs.no-cache || 'false' }}
push: true