fix: repair workflows integrationtests docker #479
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow will build a Java project with Maven | |
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | |
name: Integration test suite | |
on: | |
push: | |
branches: [ "main", "feat/**" ] | |
pull_request: | |
branches: [ "main", "feat/**" ] | |
jobs: | |
ors-test-scenarios: | |
name: Build with Maven and Docker caches | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up JDK 17 | |
uses: actions/setup-java@v4 | |
with: | |
distribution: 'temurin' | |
java-version: '17' | |
cache: 'maven' | |
cache-dependency-path: ./pom.xml | |
- name: Restore cached ors test image | |
id: restore-cached-image | |
uses: actions/cache/restore@v4 | |
with: | |
path: | | |
ors-test-scenario-builder.tar | |
key: ${{ runner.os }}-ors-test-scenario-builder | |
- name: Load the docker image | |
id: load-docker-image | |
run: | | |
echo "Loading the docker images" | |
if [ -f ors-test-scenario-builder.tar ]; then | |
docker load -i ors-test-scenario-builder.tar | |
docker inspect --format {{.Id}} ors-test-scenario-builder:latest | awk -F: '{print $2}' > last_image_build_id.log || touch last_image_build_id.log | |
# I get the docker last image id from a file | |
last_docker_id=$(cat last_image_build_id.log) | |
# Add last_docker_id to output | |
echo "last_docker_id=$last_docker_id" >> "$GITHUB_ENV" | |
fi | |
echo "List all docker images" | |
docker image ls -a | |
- name: Cache Maven dependencies for the ors maven project | |
run: | | |
echo "Caching the maven dependencies" | |
mvn -pl ors-test-scenarios package -Dmaven.test.skip=true -B dependency:go-offline -q | |
- name: Restore shared graphs | |
id: restore-cached-graphs | |
uses: actions/cache/restore@v4 | |
with: | |
path: ors-test-scenarios/graphs-integrationtests | |
key: ${{ runner.os }}-ors-test-scenarios-graphs-integrationtests-${{ env.last_docker_id }} | |
- name: Test if the graphs need to be rebuilt | |
id: build-one-shot-image | |
run: | | |
echo "Building the docker image with the one shot builder" | |
mvn -pl ors-test-scenarios -Dtest=utils.OneShotImageBuilderTest#oneShotImageBuilder test | |
docker inspect --format {{.Id}} ors-test-scenario-builder:latest | awk -F: '{print $2}' > docker_id_after_build.log || touch docker_id_after_build.log | |
docker_id_after_build=$(cat docker_id_after_build.log) | |
# if one is empty or both are different, then rebuild the graphs | |
if [ -z "${{ env.last_docker_id }}" ]; then | |
echo "Last docker id is empty, rebuilding the graphs" | |
rm -rf ors-test-scenarios/graphs-integrationtests | |
elif [ "$docker_id_after_build" != "${{ env.last_docker_id }}" ]; then | |
echo "Docker id after build is different from the last one, rebuilding the graphs" | |
rm -rf ors-test-scenarios/graphs-integrationtests | |
else | |
echo "Docker id after build is the same as the last one, no need to rebuild the graphs" | |
fi | |
# Save the last docker id to output | |
echo "docker_id_after_build=$docker_id_after_build" >> "$GITHUB_ENV" | |
echo "List all docker images" | |
docker image ls -a | |
env: | |
ONE_SHOT_IMAGE_BUILDER: true | |
- name: Rebuild shared graphs | |
run: | | |
echo "Rebuilding the shared graphs, if needed" | |
mvn -pl ors-test-scenarios -Dtest=utils.OneShotImageBuilderTest#oneShotGraphBuilder test | |
env: | |
ONE_SHOT_IMAGE_BUILDER: true | |
- name: Export the docker image to be cached | |
run: | | |
echo "Exporting the complete builder image" | |
docker save -o ors-test-scenario-builder.tar ors-test-scenario-builder:latest | |
- name: Save the docker image to the cache | |
uses: actions/cache/save@v4 | |
with: | |
path: | | |
ors-test-scenario-builder.tar | |
key: ${{ runner.os }}-ors-test-scenario-builder | |
- name: Run integration tests | |
run: | | |
echo "Running integration tests" | |
mvn -pl ors-test-scenarios test -Dtest=ConfigEnvironmentTest | |
- name: Delete previously cached graph | |
continue-on-error: true | |
run: | | |
gh extension install actions/gh-actions-cache | |
gh actions-cache delete "${{ runner.os }}-ors-test-scenarios-graphs-integrationtests-${{ env.docker_id_after_build }}" --confirm | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
- name: Save the graphs to cache | |
uses: actions/cache/save@v4 | |
with: | |
path: ors-test-scenarios/graphs-integrationtests | |
key: ${{ runner.os }}-ors-test-scenarios-graphs-integrationtests-${{ env.docker_id_after_build }} |