@@ -3,24 +3,28 @@ name: Reusable Workflow
33on :
44 workflow_call :
55 inputs :
6- python-version :
7- required : false
8- type : string
9- default : ' 3.12'
106 mm-type :
117 required : true
128 type : string
139 mm-branch :
1410 required : false
1511 type : string
1612 default : ' master'
17- mm-auth :
13+ mm-auths :
1814 required : false
1915 type : string
20- default : ' '
21- rtppc-type :
16+ default : ' [""]'
17+ python-versions :
18+ required : false
19+ type : string
20+ default : ' ["3.12"]'
21+ rtppc-types :
2222 required : true
2323 type : string
24+ use-local-image :
25+ required : false
26+ type : boolean
27+ default : false
2428 rtpp-image :
2529 required : false
2630 type : string
3539 default : ' '
3640
3741jobs :
38- test :
42+ build_ssut_image :
43+ runs-on : ubuntu-latest
44+ permissions :
45+ contents : read
46+ packages : write
47+ outputs :
48+ image-ref : ${{ steps.meta.outputs.image-ref }}
49+ image-artifact : ${{ steps.meta.outputs.image-artifact }}
50+ env :
51+ DOCKER_BUILD_SUMMARY : false
52+ DOCKER_BUILD_RECORD_UPLOAD : false
53+ steps :
54+ - uses : actions/checkout@v5
55+
56+ - name : Compute image metadata
57+ id : meta
58+ run : |
59+ MM_BRANCH_SAFE="$(echo '${{ inputs.mm-branch }}' | sed 's|[^a-zA-Z0-9_.-]|-|g')"
60+ SHA_SHORT="$(printf '%s' "$GITHUB_SHA" | cut -c1-12)"
61+ IMAGE_REF="ghcr.io/${{ github.repository_owner }}/voiptests-${{ inputs.mm-type }}:ssut-${MM_BRANCH_SAFE}-${SHA_SHORT}"
62+ IMAGE_ARTIFACT="ssut-image-${{ inputs.mm-type }}-${MM_BRANCH_SAFE}-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}"
63+ echo "image-ref=${IMAGE_REF}" >> "$GITHUB_OUTPUT"
64+ echo "image-artifact=${IMAGE_ARTIFACT}" >> "$GITHUB_OUTPUT"
65+
66+ - name : Set up Docker Buildx
67+ uses : docker/setup-buildx-action@v3
68+
69+ - name : Login to GHCR
70+ if : ${{ !inputs.use-local-image }}
71+ uses : docker/login-action@v3
72+ with :
73+ registry : ghcr.io
74+ username : ${{ github.actor }}
75+ password : ${{ secrets.GITHUB_TOKEN }}
76+
77+ - name : Build and push SSUT image
78+ if : ${{ !inputs.use-local-image }}
79+ uses : docker/build-push-action@v6
80+ with :
81+ context : .
82+ file : ./.github/docker/Dockerfile.ssut
83+ push : true
84+ tags : ${{ steps.meta.outputs.image-ref }}
85+ build-args : |
86+ BASE_IMAGE=${{ inputs.rtpp-image }}:${{ inputs.rtpp-image-tag }}
87+ MM_TYPE=${{ inputs.mm-type }}
88+ MM_BRANCH=${{ inputs.mm-branch }}
89+
90+ - name : Build SSUT image tarball
91+ if : ${{ inputs.use-local-image }}
92+ uses : docker/build-push-action@v6
93+ with :
94+ context : .
95+ file : ./.github/docker/Dockerfile.ssut
96+ outputs : type=docker,dest=/tmp/ssut-image.tar
97+ tags : ${{ steps.meta.outputs.image-ref }}
98+ build-args : |
99+ BASE_IMAGE=${{ inputs.rtpp-image }}:${{ inputs.rtpp-image-tag }}
100+ MM_TYPE=${{ inputs.mm-type }}
101+ MM_BRANCH=${{ inputs.mm-branch }}
102+
103+ - name : Upload SSUT image artifact
104+ if : ${{ inputs.use-local-image }}
105+ uses : actions/upload-artifact@v4
106+ with :
107+ name : ${{ steps.meta.outputs.image-artifact }}
108+ path : /tmp/ssut-image.tar
109+
110+ test_ghcr :
111+ if : ${{ !inputs.use-local-image }}
39112 runs-on : ubuntu-latest
113+ needs : [build_ssut_image]
40114 container :
41- image : ${{ inputs.rtpp-image }}:${{ inputs.rtpp- image-tag }}
115+ image : ${{ needs.build_ssut_image.outputs. image-ref }}
42116 options : --privileged --sysctl net.ipv6.conf.all.disable_ipv6=0
43117 env :
44118 MM_TYPE : ${{ inputs.mm-type }}
45119 MM_BRANCH : ${{ inputs.mm-branch }}
46120 RTPP_BRANCH : DOCKER
47- RTPPC_TYPE : ${{ inputs.rtppc-type }}
121+ RTPPC_TYPE : ${{ matrix.rtppc-type }}
122+ MM_AUTH : ${{ matrix.mm-auth }}
123+ ARTIFACT_FILES : ${{ inputs.artifact-files }}
124+ strategy :
125+ fail-fast : false
126+ matrix :
127+ rtppc-type : ${{ fromJSON(inputs.rtppc-types) }}
128+ mm-auth : ${{ fromJSON(inputs.mm-auths) }}
129+ python-version : ${{ fromJSON(inputs.python-versions) }}
48130 steps :
49- - uses : actions/checkout@v4
50-
51- - name : Set up Python ${{ inputs.python-version }}
131+ - name : Set up Python ${{ matrix.python-version }}
52132 uses : actions/setup-python@v5
53133 with :
54- python-version : ${{ inputs .python-version }}
134+ python-version : ${{ matrix .python-version }}
55135
56136 - name : Define PYTHON_CMD
57- run : |
58- PYTHON_VER="`echo ${{ matrix.python-version }} | sed 's|-dev$||'`"
59- echo "PYTHON_CMD=python${PYTHON_VER}" >> $GITHUB_ENV
137+ run : echo "PYTHON_CMD=${pythonLocation}/bin/python" >> "$GITHUB_ENV"
60138
61- - name : before_install
62- run : sh -x cibits/before_install.sh
139+ - name : Install Python dependencies
140+ run : |
141+ cd /opt/voiptests
142+ ${PYTHON_CMD} -m pip install --upgrade pip
143+ ${PYTHON_CMD} -m pip install -r requirements.txt
144+ if [ "${MM_TYPE}" = "b2bua" ]
145+ then
146+ ${PYTHON_CMD} -m pip install -U -r dist/b2bua/requirements.txt
147+ fi
63148
64- - name : transform_var
65- id : transform_var
149+ - name : Build artifact name
150+ id : artifact_name
66151 run : |
67- ARTNAME="test-logs_${{ inputs.mm-type }}_${{ inputs.mm-branch }}_${{ inputs .rtppc-type }}"
68- MM_AUTH="` echo "${{ inputs .mm-auth }}" | sed 's|/|.|g'` "
69- if [ "${MM_AUTH}" != " " ]
152+ ARTNAME="test-logs_${{ inputs.mm-type }}_${{ inputs.mm-branch }}_${{ matrix .rtppc-type }}"
153+ MM_AUTH_SAFE="$( echo "${{ matrix .mm-auth }}" | sed 's|/|.|g') "
154+ if [ -n "${MM_AUTH_SAFE} " ]
70155 then
71- ARTNAME="${ARTNAME}_${MM_AUTH}"
72- echo "MM_AUTH=${{ inputs.mm-auth }}" >> $GITHUB_ENV
156+ ARTNAME="${ARTNAME}_${MM_AUTH_SAFE}"
73157 fi
74158 if [ "${{ inputs.mm-type }}" = "b2bua" ]
75159 then
76- ARTNAME="${ARTNAME}_${{ inputs .python-version }}"
160+ ARTNAME="${ARTNAME}_${{ matrix .python-version }}"
77161 fi
78- echo "ARTNAME =${ARTNAME}" >> $GITHUB_OUTPUT
162+ echo "artname =${ARTNAME}" >> " $GITHUB_OUTPUT"
79163
80- - name : Test (debug)
164+ - name : Run tests
81165 run : |
166+ cd /opt/voiptests
167+ rm -rf test.logs
168+ LOG_FILES="bob.log alice.log rtpproxy.log"
169+ if [ -n "${ARTIFACT_FILES}" ]
170+ then
171+ LOG_FILES="${LOG_FILES} ${ARTIFACT_FILES}"
172+ fi
173+
82174 RTPP_VERSION=debug sh -x ./test_run.sh
83175 mkdir -p test.logs/debug
84- mv bob.log alice.log rtpproxy.log ${{ inputs.artifact-files } } test.logs/debug
176+ mv ${LOG_FILES } test.logs/debug
85177
86- - name : Test (production)
87- run : |
88178 RTPP_VERSION=production sh -x ./test_run.sh
89179 mkdir -p test.logs/production
90- mv bob.log alice.log rtpproxy.log ${{ inputs.artifact-files }} test.logs/production
180+ mv ${LOG_FILES} test.logs/production
181+
182+ - name : Upload test logs
183+ uses : actions/upload-artifact@v4
184+ with :
185+ name : ${{ steps.artifact_name.outputs.artname }}
186+ path : /opt/voiptests/test.logs
187+ continue-on-error : true
188+
189+ test_local :
190+ if : ${{ inputs.use-local-image }}
191+ runs-on : ubuntu-latest
192+ needs : [build_ssut_image]
193+ strategy :
194+ fail-fast : false
195+ matrix :
196+ rtppc-type : ${{ fromJSON(inputs.rtppc-types) }}
197+ mm-auth : ${{ fromJSON(inputs.mm-auths) }}
198+ python-version : ${{ fromJSON(inputs.python-versions) }}
199+ steps :
200+ - name : Download SSUT image artifact
201+ uses : actions/download-artifact@v4
202+ with :
203+ name : ${{ needs.build_ssut_image.outputs.image-artifact }}
204+ path : /tmp
205+
206+ - name : Load SSUT image
207+ run : docker load --input /tmp/ssut-image.tar
208+
209+ - name : Build artifact name
210+ id : artifact_name
211+ run : |
212+ ARTNAME="test-logs_${{ inputs.mm-type }}_${{ inputs.mm-branch }}_${{ matrix.rtppc-type }}"
213+ MM_AUTH_SAFE="$(echo "${{ matrix.mm-auth }}" | sed 's|/|.|g')"
214+ if [ -n "${MM_AUTH_SAFE}" ]
215+ then
216+ ARTNAME="${ARTNAME}_${MM_AUTH_SAFE}"
217+ fi
218+ if [ "${{ inputs.mm-type }}" = "b2bua" ]
219+ then
220+ ARTNAME="${ARTNAME}_${{ matrix.python-version }}"
221+ fi
222+ echo "artname=${ARTNAME}" >> "$GITHUB_OUTPUT"
223+
224+ - name : Run tests in local image
225+ run : |
226+ PYTHON_VER="$(echo '${{ matrix.python-version }}' | sed 's|-dev$||')"
227+ CTR_NAME="voiptests-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}-${{ strategy.job-index }}"
228+ trap 'docker rm -f "${CTR_NAME}" >/dev/null 2>&1 || true' EXIT
229+
230+ docker create \
231+ --name "${CTR_NAME}" \
232+ --privileged \
233+ --sysctl net.ipv6.conf.all.disable_ipv6=0 \
234+ -e MM_TYPE='${{ inputs.mm-type }}' \
235+ -e MM_BRANCH='${{ inputs.mm-branch }}' \
236+ -e MM_AUTH='${{ matrix.mm-auth }}' \
237+ -e RTPP_BRANCH='DOCKER' \
238+ -e RTPPC_TYPE='${{ matrix.rtppc-type }}' \
239+ -e ARTIFACT_FILES='${{ inputs.artifact-files }}' \
240+ -e PYTHON_CMD="python${PYTHON_VER}" \
241+ '${{ needs.build_ssut_image.outputs.image-ref }}' \
242+ /bin/sh -lc '
243+ set -e
244+ cd /opt/voiptests
245+ if ! command -v "${PYTHON_CMD}" >/dev/null 2>&1
246+ then
247+ PYTHON_CMD=python3
248+ fi
249+ export PYTHON_CMD
250+ export PIP_BREAK_SYSTEM_PACKAGES=1
251+
252+ ${PYTHON_CMD} -m pip install --upgrade pip
253+ ${PYTHON_CMD} -m pip install -r requirements.txt
254+ if [ "${MM_TYPE}" = "b2bua" ]
255+ then
256+ ${PYTHON_CMD} -m pip install -U -r dist/b2bua/requirements.txt
257+ fi
258+
259+ rm -rf test.logs
260+ LOG_FILES="bob.log alice.log rtpproxy.log"
261+ if [ -n "${ARTIFACT_FILES}" ]
262+ then
263+ LOG_FILES="${LOG_FILES} ${ARTIFACT_FILES}"
264+ fi
265+
266+ RTPP_VERSION=debug sh -x ./test_run.sh
267+ mkdir -p test.logs/debug
268+ mv ${LOG_FILES} test.logs/debug
269+
270+ RTPP_VERSION=production sh -x ./test_run.sh
271+ mkdir -p test.logs/production
272+ mv ${LOG_FILES} test.logs/production
273+ '
274+
275+ docker start -a "${CTR_NAME}"
276+ rm -rf test.logs
277+ docker cp "${CTR_NAME}:/opt/voiptests/test.logs" ./test.logs
91278
92- - name : Test logs
279+ - name : Upload test logs
93280 uses : actions/upload-artifact@v4
94281 with :
95- name : ${{ steps.transform_var .outputs.ARTNAME }}
282+ name : ${{ steps.artifact_name .outputs.artname }}
96283 path : test.logs
97284 continue-on-error : true
0 commit comments