-
Notifications
You must be signed in to change notification settings - Fork 0
144 lines (134 loc) · 4.31 KB
/
docker-build.yml
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
---
name: Build-Publish
on:
push:
branches: ["**"]
tags-ignore: ["**"]
release:
types: [released]
jobs:
build-publish:
name: "Python-${{ matrix.PYTHON }}"
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
PYTHON:
- 3.9.20
- 3.10.15
- 3.11.10
- 3.12.7
- 3.13.0
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set Variables
id: vars
run: |
# Extract python subversion
PYTHON_MAJOR=$(echo $PYTHON | sed 's/\.[0-9]\+$//')
PYTHON_PATCH=$(echo $PYTHON | sed 's/^[0-9]\+\.[0-9]\+\.//')
# Build Docker image tag
if [ "${{ github.ref_type }}" = "tag" ]; then
TAG="${PYTHON_MAJOR}"
else
TAG="${PYTHON}"
fi
# Output for debugging
echo "TAG=${TAG}"
# Store GitHub Action env vars
echo "PYTHON_MAJOR=${PYTHON_MAJOR}" >> "${GITHUB_ENV}"
echo "PYTHON_PATCH=${PYTHON_PATCH}" >> "${GITHUB_ENV}"
echo "TAG=${TAG}" >> "${GITHUB_ENV}"
env:
PYTHON: ${{ matrix.PYTHON }}
- name: Build
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make build PYTHON_MAJOR=${PYTHON_MAJOR} PYTHON_PATCH=${PYTHON_PATCH}
env:
RETRIES: 5
- name: Test
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make test PYTHON_MAJOR=${PYTHON_MAJOR} PYTHON_PATCH=${PYTHON_PATCH}
env:
RETRIES: 5
- name: Tag
run: |
make tag TAG=${TAG}
docker images
- name: Login
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make login DOCKER_USER=${{ secrets.DOCKER_USERNAME }} DOCKER_PASS=${{ secrets.DOCKER_PASSWORD }}
env:
RETRIES: 5
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
(github.event_name == 'schedule' && github.ref_name == 'master')
||
(github.event_name == 'push' && github.ref_name == 'master')
||
(github.event_name == 'release' && github.event.action == 'released')
)
- name: Push
run: |
retry() {
for n in $(seq ${RETRIES}); do
echo "[${n}/${RETRIES}] ${*}";
if eval "${*}"; then
echo "[SUCC] ${n}/${RETRIES}";
return 0;
fi;
sleep 2;
echo "[FAIL] ${n}/${RETRIES}";
done;
return 1;
}
retry make push TAG=${TAG}
env:
RETRIES: 5
# https://help.github.com/en/github/automating-your-workflow-with-github-actions/contexts-and-expression-syntax-for-github-actions#functions
if: github.event.pull_request.base.repo.id == github.event.pull_request.head.repo.id
&& (
(github.event_name == 'schedule' && github.ref_name == 'master')
||
(github.event_name == 'push' && github.ref_name == 'master')
||
(github.event_name == 'release' && github.event.action == 'released')
)