Skip to content

Commit

Permalink
ci: skip unnecessary stages when containers are the same (#1592)
Browse files Browse the repository at this point in the history
Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
  • Loading branch information
RobPasMue and pyansys-ci-bot authored Dec 18, 2024
1 parent f7a10a4 commit 9f07547
Show file tree
Hide file tree
Showing 3 changed files with 159 additions and 7 deletions.
105 changes: 101 additions & 4 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,71 @@ jobs:
directory: docker
recursive: true

manifests:
name: Check Docker manifests
runs-on: ubuntu-latest
outputs:
skip_dms: ${{ steps.services.outputs.skip_dms }}
skip_core_windows: ${{ steps.services.outputs.skip_core_windows }}
skip_core_linux: ${{ steps.services.outputs.skip_core_linux }}
strategy:
matrix:
include:
- container-stable: "windows-latest"
container-unstable: "windows-latest-unstable"
service: "dms"
service-name: "Windows DMS"
- container-stable: "core-windows-latest"
container-unstable: "core-windows-latest-unstable"
service: "core_windows"
service-name: "Windows Core Service"
- container-stable: "core-linux-latest"
container-unstable: "core-linux-latest-unstable"
service: "core_linux"
service-name: "Linux Core Service"
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Check ${{ matrix.service-name }} manifest
id: services
run: |
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-stable }} > ${{ matrix.container-stable }}.json
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-unstable }} > ${{ matrix.container-unstable }}.json || true
# Verify that the unstable manifest exists - otherwise create an empty file
if [ ! -f ${{ matrix.container-unstable }}.json ]; then
touch ${{ matrix.container-unstable }}.json
fi
# Check if the manifests are the same (and if so, create an output that will skip the next job)
if diff ${{ matrix.container-stable }}.json ${{ matrix.container-unstable }}.json; then
echo "${{ matrix.service-name }} container manifests are the same... skipping"
echo "skip_${{ matrix.service }}=1" >> "$GITHUB_OUTPUT"
else
echo "${{ matrix.service-name }} container manifests are different"
echo "skip_${{ matrix.service }}=0" >> "$GITHUB_OUTPUT"
fi
# =================================================================================================
# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv RUNNING ON SELF-HOSTED RUNNER vvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
# =================================================================================================

testing-windows:
name: Testing and coverage (Windows)
needs: [smoke-tests]
needs: [smoke-tests, manifests]
# runs-on: [self-hosted, Windows, pygeometry]
runs-on: # TODO: Waiting for ansys-network runner to be updated
group: pyansys-self-hosted
labels: [self-hosted, Windows, pygeometry]
continue-on-error: ${{ matrix.experimental }}
env:
SKIP_UNSTABLE: ${{ vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY == 1 && matrix.experimental }}
SKIP_UNSTABLE: false
PYVISTA_OFF_SCREEN: true
strategy:
fail-fast: false
Expand All @@ -131,6 +182,30 @@ jobs:
experimental: true

steps:
- name: Calculate SKIP_UNSTABLE
if: matrix.experimental
run: |
# Choose the manifests output to consider (for DMS or Core service)
# based on the matrix value
if ("${{ matrix.docker-image }}" -eq "windows-latest-unstable") {
$ImagesAreEqual = ${{ needs.manifests.outputs.skip_dms }}
} elseif ("${{ matrix.docker-image }}" -eq "core-windows-latest-unstable") {
$ImagesAreEqual = ${{ needs.manifests.outputs.skip_core_windows }}
} else {
Write-Output "Unknown docker image"
exit 1
}
$A = $env:SKIP_UNSTABLE_CONTAINERS_TEMPORARILY -eq 1
$B = $ImagesAreEqual -eq 1
# Calculate the logical expression
$Result = ($A -or $B).ToString().ToLower()
# Export it as an environment variable with true/false value
Write-Output "SKIP_UNSTABLE=$Result" | Out-File -FilePath $env:GITHUB_ENV -Append
Write-Output "SKIP_UNSTABLE will be: $Result"
- uses: actions/checkout@v4
if: env.SKIP_UNSTABLE == 'false'

Expand Down Expand Up @@ -329,11 +404,11 @@ jobs:

testing-linux:
name: Testing and coverage (Linux)
needs: [smoke-tests]
needs: [smoke-tests, manifests]
runs-on: ubuntu-latest
continue-on-error: ${{ matrix.experimental }}
env:
SKIP_UNSTABLE: ${{ vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY == 1 && matrix.experimental }}
SKIP_UNSTABLE: false
strategy:
fail-fast: false
matrix:
Expand All @@ -344,6 +419,28 @@ jobs:
experimental: true

steps:
- name: Calculate SKIP_UNSTABLE
if: matrix.experimental
run: |
# Choose the manifests output to consider (for Core service)
# based on the matrix value
if [[ "${{ matrix.docker-image }}" == "core-linux-latest-unstable" ]]; then
ImagesAreEqual=${{ needs.manifests.outputs.skip_core_linux }}
else
echo "Unknown docker image"
exit 1
fi
A=$([[ "$SKIP_UNSTABLE_CONTAINERS_TEMPORARILY" == "1" ]] && echo true || echo false)
B=$([[ "$ImagesAreEqual" == "1" ]] && echo true || echo false)
# Calculate the logical expression
Result=$([[ "$A" == true || "$B" == true ]] && echo true || echo false)
# Export it as an environment variable with true/false value
echo "SKIP_UNSTABLE=$Result" >> $GITHUB_ENV
echo "SKIP_UNSTABLE will be: $Result"
- name: Login in Github Container registry
if: env.SKIP_UNSTABLE == 'false'
uses: docker/login-action@v3
Expand Down
60 changes: 57 additions & 3 deletions .github/workflows/nightly_docker_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,65 @@ concurrency:

jobs:

manifests:
name: Check Docker manifests
runs-on: ubuntu-latest
outputs:
skip_dms: ${{ steps.services.outputs.skip_dms }}
skip_core_windows: ${{ steps.services.outputs.skip_core_windows }}
skip_core_linux: ${{ steps.services.outputs.skip_core_linux }}
strategy:
matrix:
include:
- container-stable: "windows-latest"
container-unstable: "windows-latest-unstable"
service: "dms"
service-name: "Windows DMS"
- container-stable: "core-windows-latest"
container-unstable: "core-windows-latest-unstable"
service: "core_windows"
service-name: "Windows Core Service"
- container-stable: "core-linux-latest"
container-unstable: "core-linux-latest-unstable"
service: "core_linux"
service-name: "Linux Core Service"
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Check ${{ matrix.service-name }} manifest
id: services
run: |
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-stable }} > ${{ matrix.container-stable }}.json
docker manifest inspect ghcr.io/ansys/geometry:${{ matrix.container-unstable }} > ${{ matrix.container-unstable }}.json || true
# Verify that the unstable manifest exists - otherwise create an empty file
if [ ! -f ${{ matrix.container-unstable }}.json ]; then
touch ${{ matrix.container-unstable }}.json
fi
# Check if the manifests are the same (and if so, create an output that will skip the next job)
if diff ${{ matrix.container-stable }}.json ${{ matrix.container-unstable }}.json; then
echo "${{ matrix.service-name }} container manifests are the same... skipping"
echo "skip_${{ matrix.service }}=1" >> "$GITHUB_OUTPUT"
else
echo "${{ matrix.service-name }} container manifests are different"
echo "skip_${{ matrix.service }}=0" >> "$GITHUB_OUTPUT"
fi
# =================================================================================================
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ RUNNING ON SELF-HOSTED RUNNER ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# =================================================================================================

windows-dms-tests:
name: Windows DMS
if: vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY != 1
needs: manifests
if: needs.manifests.outputs.skip_dms == 0
runs-on: [self-hosted, Windows, pygeometry]
env:
PYVISTA_OFF_SCREEN: true
Expand Down Expand Up @@ -146,7 +198,8 @@ jobs:
windows-core-tests:
name: Windows Core Service
if: vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY != 1
needs: manifests
if: needs.manifests.outputs.skip_core_windows == 0
# runs-on: [self-hosted, Windows, pygeometry]
runs-on: # TODO: Waiting for ansys-network runner to be updated
group: pyansys-self-hosted
Expand Down Expand Up @@ -259,7 +312,8 @@ jobs:

linux-tests:
name: Linux Core Service
if: vars.SKIP_UNSTABLE_CONTAINERS_TEMPORARILY != 1
needs: manifests
if: needs.manifests.outputs.skip_core_linux == 0
runs-on: ubuntu-latest

steps:
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1592.maintenance.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
skip unnecessary stages when containers are the same

0 comments on commit 9f07547

Please sign in to comment.