This repository was archived by the owner on Apr 23, 2026. It is now read-only.
Repository navigation
219 lines (191 loc) · 6.44 KB
/
Copy pathpython.yml
File metadata and controls
219 lines (191 loc) · 6.44 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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
name: python
permissions:
contents: write
id-token: write
packages: write
on:
push:
tags:
- v*
branches:
- main
paths:
- 'python/**'
- '.github/workflows/python.yml'
pull_request:
paths:
- 'python/**'
- '.github/workflows/python.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
FOLDER_LOCATION: python
IMAGE_REPOSITORY: ghcr.io/synkube/app
jobs:
file-changes:
name: file-changes
runs-on: ubuntu-latest
outputs:
dirs: ${{ steps.matrix.outputs.dirs }}
steps:
- uses: actions/checkout@v4
- name: Get changed files
id: changes
uses: tj-actions/changed-files@v44
- name: Changed files matrix
id: matrix
env:
MODIFIED_FILES: ${{ steps.changes.outputs.all_modified_files }}
run: |
set -x
modified_files=($(echo "$MODIFIED_FILES" | tr " " "\n"))
dirs=($(ls ${{ env.FOLDER_LOCATION }} | tr -d " "))
echo "Directories: ${dirs[@]}"
changed_dirs=()
include_all_dirs=false
# Check if core directory is modified, because it contains shared code
for file in "${modified_files[@]}"; do
if [[ $file =~ ${{ env.FOLDER_LOCATION }}/core/.* ]]; then
include_all_dirs=true
break
fi
done
if [ "$include_all_dirs" = true ]; then
for dir in "${dirs[@]}"; do
if [ "$dir" != "core" ]; then
changed_dirs+=("$dir")
fi
done
else
for dir in "${dirs[@]}"; do
for file in "${modified_files[@]}"; do
if [[ $file =~ ${{ env.FOLDER_LOCATION }}/$dir/.* ]]; then
if [ "$dir" != "core" ]; then
changed_dirs+=("$dir")
fi
break
fi
done
done
fi
echo "Changed directories:"
printf "%s\n" "${changed_dirs[@]}"
dirs_output=$(jq -nc '[$ARGS.positional[]]' --args "${changed_dirs[@]}")
echo "dirs=$dirs_output" >> $GITHUB_OUTPUT
python-build:
runs-on: ubuntu-latest
needs: [file-changes]
if: ${{ needs.file-changes.outputs.dirs != '[]' }}
strategy:
fail-fast: false
matrix:
project: ${{ fromJSON(needs.file-changes.outputs.dirs) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.4'
- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
- name: Install dependencies with Poetry
working-directory: ${{ env.FOLDER_LOCATION }}/${{ matrix.project }}
run: |
poetry install --no-root
- name: Run tests with Poetry
working-directory: ${{ env.FOLDER_LOCATION }}/${{ matrix.project }}
run: |
poetry run pytest
python-binary:
runs-on: ubuntu-latest
needs: [file-changes, python-build]
if: ${{ needs.file-changes.outputs.dirs != '[]' }}
strategy:
fail-fast: false
matrix:
project: ${{ fromJSON(needs.file-changes.outputs.dirs) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12.4'
- name: Install Pants
working-directory: ${{ env.FOLDER_LOCATION }}
run: |
curl --proto '=https' --tlsv1.2 -fsSL https://static.pantsbuild.org/setup/get-pants.sh | bash
- name: Build the binary with Pants
working-directory: ${{ env.FOLDER_LOCATION }}
run: |
~/.local/bin/pants package ${{ matrix.project }}:${{ matrix.project }}
docker-release:
runs-on: ubuntu-latest
needs: [file-changes, python-build]
if: ${{ needs.file-changes.outputs.dirs != '[]' }}
strategy:
fail-fast: false
matrix:
project: ${{ fromJSON(needs.file-changes.outputs.dirs) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: mikefarah/yq@v4.32.2
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: Bump version and push tag
id: tag_version
if: steps.branch-name.outputs.is_default == 'true'
uses: mathieudutour/github-tag-action@v6.2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
tag_prefix: ${{matrix.project}}/v
release_branches: main
fetch_all_tags: true
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build Docker image
working-directory: ${{ env.FOLDER_LOCATION }}
run: |
docker build -t $IMAGE_REPOSITORY/$IMAGE_NAME:latest -f ${{ matrix.project }}/Dockerfile .
env:
IMAGE_NAME: ${{ matrix.project }}
- name: Push Docker Images (Snapshot)
if: steps.branch-name.outputs.is_default != 'true'
run: |
docker tag $IMAGE_REPOSITORY/$IMAGE_NAME:latest $IMAGE_REPOSITORY/$IMAGE_NAME:${GITHUB_SHA}
docker push $IMAGE_REPOSITORY/$IMAGE_NAME:${GITHUB_SHA}
docker push $IMAGE_REPOSITORY/$IMAGE_NAME:latest
env:
IMAGE_NAME: ${{ matrix.project }}
- name: Push Docker Images (Tag/Latest)
if: steps.branch-name.outputs.is_default == 'true'
run: |
docker tag $IMAGE_REPOSITORY/$IMAGE_NAME:latest $IMAGE_REPOSITORY/$IMAGE_NAME:v$VERSION
docker tag $IMAGE_REPOSITORY/$IMAGE_NAME:latest $IMAGE_REPOSITORY/$IMAGE_NAME:${GITHUB_SHA}
docker push $IMAGE_REPOSITORY/$IMAGE_NAME:${GITHUB_SHA}
docker push $IMAGE_REPOSITORY/$IMAGE_NAME:v$VERSION
docker push $IMAGE_REPOSITORY/$IMAGE_NAME:latest
env:
IMAGE_NAME: ${{ matrix.project }}
VERSION: ${{ steps.tag_version.outputs.new_version }}