-
Notifications
You must be signed in to change notification settings - Fork 63
85 lines (81 loc) · 2.3 KB
/
Copy pathci-cd.yml
File metadata and controls
85 lines (81 loc) · 2.3 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
name: CI/CD Pipeline
on:
release:
types: [ published ]
push:
branches:
- '**'
tags-ignore:
- '**'
jobs:
lint:
name: Lint Code
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Ruff lint
run: ruff check app/ tests/
test:
name: Run Tests
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run tests with coverage
run: pytest --cov=app --cov-report=term-missing --cov-fail-under=80
build:
name: Build Docker Image
runs-on: ubuntu-latest
needs: [lint, test]
if: github.event_name == 'push' || github.event_name == 'release'
permissions:
contents: read
actions: read
packages: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build image (push)
if: github.event_name == 'push'
run: |
IMAGE=ghcr.io/${{ github.repository }}
TAG=${{ github.sha }}
docker build -f docker/Dockerfile -t $IMAGE:$TAG .
docker push $IMAGE:$TAG
- name: Build image (release)
if: github.event_name == 'release'
run: |
IMAGE=ghcr.io/${{ github.repository }}
VERSION=${{ github.ref_name }}
docker build -f docker/Dockerfile -t $IMAGE:$VERSION -t $IMAGE:latest .
docker push $IMAGE:$VERSION
docker push $IMAGE:latest