-
Notifications
You must be signed in to change notification settings - Fork 0
155 lines (138 loc) · 4.33 KB
/
ci-python.yml
File metadata and controls
155 lines (138 loc) · 4.33 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
146
147
148
149
150
151
152
153
154
155
name: CI (Python/FastAPI)
on:
push:
tags:
- 'pre-processing-v*'
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
branches:
- main
- develop
- release/**
paths:
- "apps/pre-processing-service/**"
permissions:
contents: read
packages: write
security-events: write
checks: write
pull-requests: write
jobs:
lint:
if: github.event.pull_request.draft == false
name: Lint & Format Check
runs-on: ubuntu-latest
defaults:
run:
working-directory: apps/pre-processing-service
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true
installer-parallel: true
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v4
with:
path: apps/pre-processing-service/.venv
key: venv-${{ runner.os }}-${{ hashFiles('apps/pre-processing-service/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
- name: Run Formatter Check (Black)
run: poetry run black --check .
# test:
# name: Run Tests
# runs-on: ubuntu-latest
# needs: lint
# defaults:
# run:
# working-directory: apps/pre-processing-service
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Set up Python 3.11
# uses: actions/setup-python@v5
# with:
# python-version: "3.11"
#
# - name: Install Poetry
# uses: snok/install-poetry@v1
# with:
# virtualenvs-create: true
# virtualenvs-in-project: true
# installer-parallel: true
#
# - name: Load cached venv
# id: cached-poetry-dependencies
# uses: actions/cache@v4
# with:
# path: apps/pre-processing-service/.venv
# key: venv-${{ runner.os }}-${{ hashFiles('apps/pre-processing-service/poetry.lock') }}
#
# - name: Install dependencies
# if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
# run: poetry install --no-interaction --no-root
#
# - name: Run tests with Pytest
# env:
# DB_HOST: localhost
# DB_PORT: 3306
# DB_USER: test_user
# DB_PASS: test_pass
# DB_NAME: test_db
# ENV_NAME: test
# run: poetry run pytest
set-image-tag:
name: Set IMAGE_TAG
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/pre-processing-v')
outputs:
image-tag: ${{ steps.extract-tag.outputs.IMAGE_TAG }}
steps:
- name: Extract version from tag
id: extract-tag
run: |
IMAGE_TAG="${GITHUB_REF#refs/tags/pre-processing-}"
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_OUTPUT
echo "Extracted IMAGE_TAG: $IMAGE_TAG"
build-and-push-docker:
name: Build Docker Image and push
runs-on: ubuntu-latest
needs:
# - test
- lint
- set-image-tag
if: startsWith(github.ref, 'refs/tags/pre-processing-v')
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Login to Docker Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set repo lowercase
run: echo "REPO_LC=${GITHUB_REPOSITORY,,}" >> $GITHUB_ENV
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./apps/pre-processing-service
push: true
tags: |
ghcr.io/${{ env.REPO_LC }}/pre-processing-service:${{ needs.set-image-tag.outputs.image-tag }}
ghcr.io/${{ env.REPO_LC }}/pre-processing-service:latest
- name: Analyze image layers
run: |
echo "=== Image Layer Analysis ==="
docker history ghcr.io/${{ env.REPO_LC }}/pre-processing-service:${{ needs.set-image-tag.outputs.image-tag }} --human --no-trunc