-
Notifications
You must be signed in to change notification settings - Fork 400
116 lines (112 loc) · 4.96 KB
/
integration-tests.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
# 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
continue-on-error: true
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
continue-on-error: true
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 }}