-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (110 loc) · 3.25 KB
/
ci.yaml
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
name: CI
on:
push:
branches:
- master
pull_request:
types:
- "opened"
- "reopened"
- "synchronize"
branches:
- master
concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
jobs:
determine_build:
name: Determine follow up builds
runs-on: ubuntu-latest
outputs:
docker: ${{ steps.result.outputs.docker }}
gradle: ${{ steps.result.outputs.gradle }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Get changed files
id: changed
uses: tj-actions/changed-files@v41
with:
separator: ","
- name: Output result
id: result
run: |
CHANGES=${{ steps.changed.outputs.all_changed_files }}
DOCKER="0"
if [[ $CHANGES =~ ^.*(docker-compose\.yaml|wiremock\.Dockerfile).*$ ]]; then
echo "Dockerfile has been changed"
DOCKER="1"
fi
GRADLE="0"
if [[ $CHANGES =~ ^.*(mock-api\/.*).*$ ]]; then
echo "mock-api has been changed"
GRADLE="1"
fi
echo -e " docker = $DOCKER \n build_gradle = $GRADLE"
{
echo "docker=$DOCKER"
echo "gradle=$GRADLE"
} >> "$GITHUB_OUTPUT"
docker:
name: Build docker
runs-on: ubuntu-latest
needs: determine_build
if: ${{ needs.determine_build.outputs.docker == '1' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Start stack
run: docker compose up -d
- name: Wait for wiremock to be ready
run: sleep 10
- name: Test endpoint
run: |
RESPONSE=$(curl -s --retry 10 --retry-connrefused "http://localhost:8080/v1/hello")
echo -e "Got response from mock:\n$RESPONSE"
if [[ $(echo "$RESPONSE" | jq -r '.id') != "001" ]]; then
echo "Expect id in the response json to be '001'"
exit 1
fi
if [[ $(echo " $RESPONSE" | jq -r '.value') != "There" ]]; then
echo "Expect value in the response json to be 'There'"
exit 1
fi
- name: Clean up
if: ${{ always() }}
run: docker compose down
skip_docker:
name: Build docker
runs-on: ubuntu-latest
needs: determine_build
if: ${{ needs.determine_build.outputs.docker == '0' }}
steps:
- run: echo 'Skip docker check as non of the docker files have not been changed'
gradle:
name: Build gradle
runs-on: ubuntu-latest
needs: determine_build
if: ${{ needs.determine_build.outputs.gradle == '1' }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: Build and test
working-directory: mock-api
run: ./gradlew build -i
skip_gradle:
name: Build gradle
runs-on: ubuntu-latest
needs: determine_build
if: ${{ needs.determine_build.outputs.gradle == '0' }}
steps:
- run: echo 'Skip gradle check as the gradle module has not been changed'