Skip to content

Commit 9f07547

Browse files
ci: skip unnecessary stages when containers are the same (#1592)
Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent f7a10a4 commit 9f07547

File tree

3 files changed

+159
-7
lines changed

3 files changed

+159
-7
lines changed

.github/workflows/ci_cd.yml

Lines changed: 101 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,71 @@ jobs:
102102
directory: docker
103103
recursive: true
104104

105+
manifests:
106+
name: Check Docker manifests
107+
runs-on: ubuntu-latest
108+
outputs:
109+
skip_dms: ${{ steps.services.outputs.skip_dms }}
110+
skip_core_windows: ${{ steps.services.outputs.skip_core_windows }}
111+
skip_core_linux: ${{ steps.services.outputs.skip_core_linux }}
112+
strategy:
113+
matrix:
114+
include:
115+
- container-stable: "windows-latest"
116+
container-unstable: "windows-latest-unstable"
117+
service: "dms"
118+
service-name: "Windows DMS"
119+
- container-stable: "core-windows-latest"
120+
container-unstable: "core-windows-latest-unstable"
121+
service: "core_windows"
122+
service-name: "Windows Core Service"
123+
- container-stable: "core-linux-latest"
124+
container-unstable: "core-linux-latest-unstable"
125+
service: "core_linux"
126+
service-name: "Linux Core Service"
127+
steps:
128+
- name: Login to GitHub Container Registry
129+
uses: docker/login-action@v3
130+
with:
131+
registry: ghcr.io
132+
username: ${{ github.actor }}
133+
password: ${{ secrets.GITHUB_TOKEN }}
134+
135+
- name: Check ${{ matrix.service-name }} manifest
136+
id: services
137+
run: |
138+
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-stable }} > ${{ matrix.container-stable }}.json
139+
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-unstable }} > ${{ matrix.container-unstable }}.json || true
140+
141+
# Verify that the unstable manifest exists - otherwise create an empty file
142+
if [ ! -f ${{ matrix.container-unstable }}.json ]; then
143+
touch ${{ matrix.container-unstable }}.json
144+
fi
145+
146+
147+
# Check if the manifests are the same (and if so, create an output that will skip the next job)
148+
if diff ${{ matrix.container-stable }}.json ${{ matrix.container-unstable }}.json; then
149+
echo "${{ matrix.service-name }} container manifests are the same... skipping"
150+
echo "skip_${{ matrix.service }}=1" >> "$GITHUB_OUTPUT"
151+
else
152+
echo "${{ matrix.service-name }} container manifests are different"
153+
echo "skip_${{ matrix.service }}=0" >> "$GITHUB_OUTPUT"
154+
fi
155+
105156
# =================================================================================================
106157
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv RUNNING ON SELF-HOSTED RUNNER vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
107158
# =================================================================================================
108159

109160
testing-windows:
110161
name: Testing and coverage (Windows)
111-
needs: [smoke-tests]
162+
needs: [smoke-tests, manifests]
112163
# runs-on: [self-hosted, Windows, pygeometry]
113164
runs-on: # TODO: Waiting for ansys-network runner to be updated
114165
group: pyansys-self-hosted
115166
labels: [self-hosted, Windows, pygeometry]
116167
continue-on-error: ${{ matrix.experimental }}
117168
env:
118-
SKIP_UNSTABLE: ${{ vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY == 1 && matrix.experimental }}
169+
SKIP_UNSTABLE: false
119170
PYVISTA_OFF_SCREEN: true
120171
strategy:
121172
fail-fast: false
@@ -131,6 +182,30 @@ jobs:
131182
experimental: true
132183

133184
steps:
185+
- name: Calculate SKIP_UNSTABLE
186+
if: matrix.experimental
187+
run: |
188+
# Choose the manifests output to consider (for DMS or Core service)
189+
# based on the matrix value
190+
if ("${{ matrix.docker-image }}" -eq "windows-latest-unstable") {
191+
$ImagesAreEqual = ${{ needs.manifests.outputs.skip_dms }}
192+
} elseif ("${{ matrix.docker-image }}" -eq "core-windows-latest-unstable") {
193+
$ImagesAreEqual = ${{ needs.manifests.outputs.skip_core_windows }}
194+
} else {
195+
Write-Output "Unknown docker image"
196+
exit 1
197+
}
198+
199+
$A = $env:SKIP_UNSTABLE_CONTAINERS_TEMPORARILY -eq 1
200+
$B = $ImagesAreEqual -eq 1
201+
202+
# Calculate the logical expression
203+
$Result = ($A -or $B).ToString().ToLower()
204+
205+
# Export it as an environment variable with true/false value
206+
Write-Output "SKIP_UNSTABLE=$Result" | Out-File -FilePath $env:GITHUB_ENV -Append
207+
Write-Output "SKIP_UNSTABLE will be: $Result"
208+
134209
- uses: actions/checkout@v4
135210
if: env.SKIP_UNSTABLE == 'false'
136211

@@ -329,11 +404,11 @@ jobs:
329404

330405
testing-linux:
331406
name: Testing and coverage (Linux)
332-
needs: [smoke-tests]
407+
needs: [smoke-tests, manifests]
333408
runs-on: ubuntu-latest
334409
continue-on-error: ${{ matrix.experimental }}
335410
env:
336-
SKIP_UNSTABLE: ${{ vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY == 1 && matrix.experimental }}
411+
SKIP_UNSTABLE: false
337412
strategy:
338413
fail-fast: false
339414
matrix:
@@ -344,6 +419,28 @@ jobs:
344419
experimental: true
345420

346421
steps:
422+
- name: Calculate SKIP_UNSTABLE
423+
if: matrix.experimental
424+
run: |
425+
# Choose the manifests output to consider (for Core service)
426+
# based on the matrix value
427+
if [[ "${{ matrix.docker-image }}" == "core-linux-latest-unstable" ]]; then
428+
ImagesAreEqual=${{ needs.manifests.outputs.skip_core_linux }}
429+
else
430+
echo "Unknown docker image"
431+
exit 1
432+
fi
433+
434+
A=$([[ "$SKIP_UNSTABLE_CONTAINERS_TEMPORARILY" == "1" ]] && echo true || echo false)
435+
B=$([[ "$ImagesAreEqual" == "1" ]] && echo true || echo false)
436+
437+
# Calculate the logical expression
438+
Result=$([[ "$A" == true || "$B" == true ]] && echo true || echo false)
439+
440+
# Export it as an environment variable with true/false value
441+
echo "SKIP_UNSTABLE=$Result" >> $GITHUB_ENV
442+
echo "SKIP_UNSTABLE will be: $Result"
443+
347444
- name: Login in Github Container registry
348445
if: env.SKIP_UNSTABLE == 'false'
349446
uses: docker/login-action@v3

.github/workflows/nightly_docker_test.yml

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,65 @@ concurrency:
3535

3636
jobs:
3737

38+
manifests:
39+
name: Check Docker manifests
40+
runs-on: ubuntu-latest
41+
outputs:
42+
skip_dms: ${{ steps.services.outputs.skip_dms }}
43+
skip_core_windows: ${{ steps.services.outputs.skip_core_windows }}
44+
skip_core_linux: ${{ steps.services.outputs.skip_core_linux }}
45+
strategy:
46+
matrix:
47+
include:
48+
- container-stable: "windows-latest"
49+
container-unstable: "windows-latest-unstable"
50+
service: "dms"
51+
service-name: "Windows DMS"
52+
- container-stable: "core-windows-latest"
53+
container-unstable: "core-windows-latest-unstable"
54+
service: "core_windows"
55+
service-name: "Windows Core Service"
56+
- container-stable: "core-linux-latest"
57+
container-unstable: "core-linux-latest-unstable"
58+
service: "core_linux"
59+
service-name: "Linux Core Service"
60+
steps:
61+
- name: Login to GitHub Container Registry
62+
uses: docker/login-action@v3
63+
with:
64+
registry: ghcr.io
65+
username: ${{ github.actor }}
66+
password: ${{ secrets.GITHUB_TOKEN }}
67+
68+
- name: Check ${{ matrix.service-name }} manifest
69+
id: services
70+
run: |
71+
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-stable }} > ${{ matrix.container-stable }}.json
72+
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-unstable }} > ${{ matrix.container-unstable }}.json || true
73+
74+
# Verify that the unstable manifest exists - otherwise create an empty file
75+
if [ ! -f ${{ matrix.container-unstable }}.json ]; then
76+
touch ${{ matrix.container-unstable }}.json
77+
fi
78+
79+
80+
# Check if the manifests are the same (and if so, create an output that will skip the next job)
81+
if diff ${{ matrix.container-stable }}.json ${{ matrix.container-unstable }}.json; then
82+
echo "${{ matrix.service-name }} container manifests are the same... skipping"
83+
echo "skip_${{ matrix.service }}=1" >> "$GITHUB_OUTPUT"
84+
else
85+
echo "${{ matrix.service-name }} container manifests are different"
86+
echo "skip_${{ matrix.service }}=0" >> "$GITHUB_OUTPUT"
87+
fi
88+
3889
# =================================================================================================
3990
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUNNING ON SELF-HOSTED RUNNER ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4091
# =================================================================================================
4192

4293
windows-dms-tests:
4394
name: Windows DMS
44-
if: vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY != 1
95+
needs: manifests
96+
if: needs.manifests.outputs.skip_dms == 0
4597
runs-on: [self-hosted, Windows, pygeometry]
4698
env:
4799
PYVISTA_OFF_SCREEN: true
@@ -146,7 +198,8 @@ jobs:
146198
147199
windows-core-tests:
148200
name: Windows Core Service
149-
if: vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY != 1
201+
needs: manifests
202+
if: needs.manifests.outputs.skip_core_windows == 0
150203
# runs-on: [self-hosted, Windows, pygeometry]
151204
runs-on: # TODO: Waiting for ansys-network runner to be updated
152205
group: pyansys-self-hosted
@@ -259,7 +312,8 @@ jobs:
259312

260313
linux-tests:
261314
name: Linux Core Service
262-
if: vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY != 1
315+
needs: manifests
316+
if: needs.manifests.outputs.skip_core_linux == 0
263317
runs-on: ubuntu-latest
264318

265319
steps:

doc/changelog.d/1592.maintenance.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
skip unnecessary stages when containers are the same

0 commit comments

Comments
 (0)