-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (105 loc) · 3.29 KB
/
CI.yaml
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
name: linters & tests
on:
push:
paths:
- '.github/**/*'
- 'pyproject.toml'
- 'poetry.lock'
- 'Dockerfile'
- 'app/**/*'
- 'tests/**/*'
workflow_dispatch:
env:
CI: true
DOCKER_IMAGE: caraconnect
jobs:
notify-start:
runs-on: ubuntu-latest
steps:
- run: echo "The job was automatically triggered by a '${{ github.event_name }}' event for '${{ github.ref }}' branch"
python-linters:
needs: [ notify-start ]
runs-on: ubuntu-latest
env:
PROJ_PATH: ./app
TESTS_PATH: ./tests
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- name: Install Dependencies
run: |
poetry env use 3.12
poetry install
- name: Run Black
run: poetry run black --check --diff $PROJ_PATH $TESTS_PATH
- name: Run Ruff
run: poetry run ruff check --output-format=github $PROJ_PATH $TESTS_PATH
- name: Run mypy
run: poetry run mypy $PROJ_PATH $TESTS_PATH
- name: Run Bandit
run: poetry run bandit -c pyproject.toml --silent -r $PROJ_PATH
python-tests:
needs: [ notify-start ]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
cache: 'poetry'
- name: Install Dependencies
run: |
poetry env use 3.12
poetry install
- name: Run tests
run: poetry run pytest
push-docker-image:
needs: [ python-linters, python-tests ]
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Docker meta
id: meta
run: |
now=$(date +"%Y_%m_%d_%H_%M_%S")
sha=$(echo $GITHUB_SHA | head -c7)
echo "image=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE }}:${{ github.ref_name }}-$now-$sha" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v3
if: ${{ github.ref_name == 'master' }}
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}
- name: Build and push
uses: docker/build-push-action@v6
if: ${{ github.ref_name == 'master' }}
with:
context: .
push: true
tags: ${{ steps.meta.outputs.image }}
cache-from: type=gha, scope=${{ github.workflow }}
cache-to: type=gha, scope=${{ github.workflow }}
provenance: false
- name: Update the "latest" tag
if: ${{ github.ref_name == 'master' }}
run: |
LATEST_TAG=${{ secrets.DOCKERHUB_USERNAME }}/${{ env.DOCKER_IMAGE }}:latest
docker manifest create $LATEST_TAG ${{ steps.meta.outputs.image }}
docker manifest push --purge $LATEST_TAG
notify-finish:
needs: [ push-docker-image ]
runs-on: ubuntu-latest
steps:
- run: echo "This job's status is '${{ job.status }}'"