-
Notifications
You must be signed in to change notification settings - Fork 1
218 lines (193 loc) · 7.43 KB
/
Copy pathci.yml
File metadata and controls
218 lines (193 loc) · 7.43 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
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python
name: CI
on:
push:
branches: [ "master" ]
paths-ignore:
- "*.md"
pull_request:
branches: [ "master" ]
paths-ignore:
- "*.md"
jobs:
lint:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install flake8 flake8-pyproject ruff
- name: Lint with flake8
run: |
flake8 .
- name: Lint with ruff
run: |
ruff check .
build-check:
runs-on: ubuntu-latest
needs: lint
steps:
- name: Checkout
uses: actions/checkout@v7
- name: Set up Python 3.12
uses: actions/setup-python@v6
with:
python-version: "3.12"
cache: 'pip'
- name: Install build tools
run: |
python -m pip install --upgrade pip
python -m pip install build twine
- name: Build package
run: |
python -m build
- name: Check package metadata
run: |
twine check dist/*
test:
runs-on: ubuntu-latest
needs: build-check
strategy:
fail-fast: false
matrix:
include:
- platform: "alpine"
python: "3.7"
- platform: "alpine"
python: "3.8"
- platform: "alpine"
python: "3.9"
- platform: "alpine"
python: "3.10"
- platform: "alpine"
python: "3.11"
- platform: "alpine"
python: "3.12"
- platform: "alpine"
python: "3.13"
- platform: "alpine"
python: "3.14"
- platform: "ubuntu_24_04"
python: "3"
- platform: "altlinux_10"
python: "3"
- platform: "altlinux_11"
python: "3"
- platform: "astralinux_1_7"
python: "3"
- platform: "rockylinux_8"
python: "3"
- platform: "rockylinux_9"
python: "3"
- platform: "rockylinux_10"
python: "3"
env:
BASE_SIGN: "${{ matrix.platform }}-py${{ matrix.python }}"
steps:
- name: Prepare variables
run: |
echo "RUN_CFG__NOW=$(date +'%Y%m%d_%H%M%S')" >> $GITHUB_ENV
echo "RUN_CFG__LOGS_DIR=logs-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "RUN_CFG__DOCKER_IMAGE_NAME=tests-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "RUN_CFG__NETWORK_NAME=network-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "RUN_CFG__MACHINE1_NAME=machine1-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "RUN_CFG__MACHINE2_NAME=machine2-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "RUN_CFG__SSH_KEY_NAME=id_ed25519-${{ env.BASE_SIGN }}" >> $GITHUB_ENV
echo "---------- [$GITHUB_ENV]"
cat $GITHUB_ENV
- name: Checkout
uses: actions/checkout@v7
- name: Prepare logs folder on the host
run: mkdir -p "${{ env.RUN_CFG__LOGS_DIR }}"
- name: Adjust logs folder permission
run: chmod -R 777 "${{ env.RUN_CFG__LOGS_DIR }}"
- name: Build local image ${{ matrix.alpine }}
run: docker build --build-arg PYTHON_VERSION="${{ matrix.python }}" -t "${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" -f Dockerfile--${{ matrix.platform }}.tmpl .
- name: Generate temporary SSH Key pair for CI
run: |
# Generate a key without a password directly on the GitHub Actions host
ssh-keygen -q -t ed25519 -N "" -f ${{ github.workspace }}/${{ env.RUN_CFG__SSH_KEY_NAME }}
- name: Setup network
run: |
docker network create ${{ env.RUN_CFG__NETWORK_NAME }}
- name: Run machine2 (for remote operations)
run: |
#
# "- sleep infinity" is a right command. Docker ignores "-" and runs "sleep infinity".
#
docker run -d -t \
--network ${{ env.RUN_CFG__NETWORK_NAME }} \
--name ${{ env.RUN_CFG__MACHINE2_NAME }} \
"${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}" \
sleep infinity
echo "Waiting for container ${{ env.RUN_CFG__MACHINE2_NAME }} to start ..."
# Set the timeout using the attempt counter
MAX_ATTEMPTS=50
ATTEMPT=0
until [ "$(docker container inspect --format '{{.State.Running}}' "${{ env.RUN_CFG__MACHINE2_NAME }}")" = "true" ]; do
ATTEMPT=$((ATTEMPT + 1))
if [ $ATTEMPT -ge $MAX_ATTEMPTS ]; then
echo "Error: Container did not start within the allotted time (timeout)!"
exit 1
fi
sleep 0.2
done
echo "Container successfully launched in $((ATTEMPT * 2 / 10)) second(s)!"
#
# Setup authorized_keys
#
cat ${{ github.workspace }}/${{ env.RUN_CFG__SSH_KEY_NAME }}.pub | \
docker exec -i -u test ${{ env.RUN_CFG__MACHINE2_NAME }} sh -c " \
cat >> /home/test/.ssh/authorized_keys && \
chmod 600 /home/test/.ssh/authorized_keys \
"
#
# Log status
#
docker exec -u root ${{ env.RUN_CFG__MACHINE2_NAME }} sh -c "
echo '--- INSIDE CONTAINER OS ---' && \
cat /etc/os-release && \
echo '--- INSIDE CONTAINER .SSH ---' && \
ls -la /home/test/.ssh/ \
"
- name: Run machine1 (main test container)
run: |
# Launch the main container, passing the private key to the .ssh folder of the test user.
# Pass environment variables so Python tests know where to start.
# Added the --rm flag so that the container is automatically deleted after the tests are completed
docker run --rm -t \
--network ${{ env.RUN_CFG__NETWORK_NAME }} \
--name ${{ env.RUN_CFG__MACHINE1_NAME }} \
-v ${{ github.workspace }}/${{ env.RUN_CFG__LOGS_DIR }}:/home/test/testgres/logs \
-v ${{ github.workspace }}/${{ env.RUN_CFG__SSH_KEY_NAME }}:/home/test/testgres/id_ed25519_test:ro \
-e TEST_CFG__REMOTE_HOST="${{ env.RUN_CFG__MACHINE2_NAME }}" \
-e TEST_CFG__REMOTE_PORT="22" \
-e TEST_CFG__REMOTE_USERNAME="test" \
-e TEST_CFG__REMOTE_SSH_KEY="/home/test/testgres/id_ed25519_test" \
"${{ env.RUN_CFG__DOCKER_IMAGE_NAME }}"
- name: Upload Logs
uses: actions/upload-artifact@v7
if: always() # IT IS IMPORTANT!
with:
name: testgres.os_ops--test_logs--${{ env.RUN_CFG__NOW }}-${{ env.BASE_SIGN }}-id${{ github.run_id }}
path: "${{ env.RUN_CFG__LOGS_DIR }}/"
- name: Cleanup Docker resources
if: always() # Ensures that the step is executed regardless of the result of the task
run: |
echo "=== Garbage Collection ==="
# Force kill the background machine (the -f flag will stop it if it is running)
docker rm -f "${{ env.RUN_CFG__MACHINE2_NAME }}" || true
# Delete the network (it will be deleted successfully, since all containers in it have already been destroyed)
docker network rm "${{ env.RUN_CFG__NETWORK_NAME }}" || true