-
Notifications
You must be signed in to change notification settings - Fork 7
236 lines (199 loc) · 9.06 KB
/
build.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#
# Copyright contributors to the Galasa project
#
# SPDX-License-Identifier: EPL-2.0
#
name: Main build
on:
workflow_dispatch:
push:
branches: [main]
env:
REGISTRY: ghcr.io
NAMESPACE: galasa-dev
BRANCH: ${{ github.ref_name }}
jobs:
log-github-ref:
name: Log the GitHub ref this workflow is running on (Branch or tag that received dispatch)
runs-on: ubuntu-latest
steps:
- name: Log GitHub ref of workflow
run: |
echo "This workflow is running on GitHub ref ${{ env.BRANCH }}"
build-cli:
name: Build the Galasa CLI
runs-on: ubuntu-latest
steps:
- name: Checkout CLI
uses: actions/checkout@v4
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: 8.9
cache-disabled: true
# Pull down dependencies with Gradle and put them in the right places.
- name: Gather dependencies using Gradle
run : |
set -o pipefail
gradle -b build.gradle installJarsIntoTemplates --info \
--no-daemon --console plain \
-PsourceMaven=https://development.galasa.dev/${{ env.BRANCH }}/maven-repo/maven \
-PcentralMaven=https://repo.maven.apache.org/maven2/ \
-PtargetMaven=${{ github.workspace }}/repo 2>&1 | tee build.log
- name: Upload Gradle installJarsIntoTemplates log
if: failure()
uses: actions/upload-artifact@v4
with:
name: gradle-installJarsIntoTemplates-log
path: build.log
retention-days: 7
# Generate client code so galasactl can communicate with the API server.
- name: Generate Go client code using openapi.yaml
run : |
docker run --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/openapi:main java -jar /opt/openapi/openapi-generator-cli.jar generate -i /var/workspace/build/dependencies/openapi.yaml -g go -o /var/workspace/pkg/galasaapi --additional-properties=packageName=galasaapi --global-property=apiTests=false
# The go.mod and go.sum are out of date, as they do not include the generated code so they are deleted here. They get re-generated when we compile.
# Due to permissions, deleting the go.mod and go.sum must be done by the openapi image as the image generated those files.
- name: Clear go.mod
run : |
docker run --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/openapi:main rm /var/workspace/pkg/galasaapi/go.mod
- name: Clear go.sum
run : |
docker run --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/openapi:main rm /var/workspace/pkg/galasaapi/go.sum
# The go code needs to know which version of Galasa it is part of, so substitute an eye-catcher with the correct value.
- name: Update version
run : |
version=$(cat VERSION) &&
cat pkg/cmd/root.go | sed "s/unknowncliversion-unknowngithash/${version}/1" > temp.txt &&
mv -f temp.txt pkg/cmd/root.go &&
cat pkg/cmd/root.go
# Invoke the make command to build the go code, run unit tests and gather code coverage stats.
- name: Build Go code with the Makefile
run : |
make all
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'semeru'
- name: Chmod local test script
run: |
chmod +x test-galasactl-local.sh
- name: Run local test script with Maven
run : |
./test-galasactl-local.sh --buildTool maven
- name: Run local test script with Gradle
run : |
./test-galasactl-local.sh --buildTool gradle
# Commenting out for now as we cannot reach the prod1 ecosystem from GitHub Actions.
# - name: Chmod ecosystem test script
# run : |
# chmod +x test-galasactl-ecosystem.sh
# - name: Run ecosystem test script
# run : |
# ./test-galasactl-ecosystem.sh --bootstrap https://prod1-galasa-dev.cicsk8s.hursley.ibm.com/api/bootstrap
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: galasa-team
password: ${{ secrets.GALASA_TEAM_WRITE_PACKAGES_TOKEN }}
- name: Extract metadata for galasactl image
id: metadata-galasactl
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/galasactl-x86_64
- name: Build galasactl image
id: build-galasactl
uses: docker/build-push-action@v5
with:
context: .
file: dockerfiles/dockerfile.galasactl
push: true
tags: ${{ steps.metadata-galasactl.outputs.tags }}
labels: ${{ steps.metadata-galasactl.outputs.labels }}
build-args: |
platform=linux-x86_64
- name: Extract metadata for galasactl-ibm image
id: metadata-galasactl-ibm
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/galasactl-ibm-x86_64
- name: Build galasactl-ibm image
id: build-galasactl-ibm
uses: docker/build-push-action@v5
with:
context: dockerfiles/certs
file: dockerfiles/dockerfile.galasactl-ibm
push: true
tags: ${{ steps.metadata-galasactl-ibm.outputs.tags }}
labels: ${{ steps.metadata-galasactl-ibm.outputs.labels }}
build-args: |
dockerRepository=ghcr.io
tag=${{ env.BRANCH }}
- name: Extract metadata for galasactl-executables image
id: metadata-galasactl-executables
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/galasactl-executables
- name: Build galasactl-executables image
id: build-galasactl-executables
uses: docker/build-push-action@v5
with:
context: .
file: dockerfiles/dockerfile.galasactl-executables
push: true
tags: ${{ steps.metadata-galasactl-executables.outputs.tags }}
labels: ${{ steps.metadata-galasactl-executables.outputs.labels }}
- name: Recycle application in ArgoCD
env:
ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
run: |
docker run --env ARGOCD_AUTH_TOKEN=${{ env.ARGOCD_AUTH_TOKEN }} --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/argocdcli:main app actions run ${{ env.BRANCH }}-cli restart --kind Deployment --resource-name cli-${{ env.BRANCH }} --server argocd.galasa.dev
- name: Wait for application health in ArgoCD
env:
ARGOCD_AUTH_TOKEN: ${{ secrets.ARGOCD_TOKEN }}
run: |
docker run --env ARGOCD_AUTH_TOKEN=${{ env.ARGOCD_AUTH_TOKEN }} --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/argocdcli:main app wait ${{ env.BRANCH }}-cli --resource apps:Deployment:cli-${{ env.BRANCH }} --health --server argocd.galasa.dev
build-galasactl-ibm-testing-image-and-trigger-tekton-pipeline:
name: Build image containing galasactl, OpenJDK and Gradle for testing
runs-on: ubuntu-latest
needs: build-cli
steps:
- name: Checkout CLI
uses: actions/checkout@v4
- name: Login to Github Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: galasa-team
password: ${{ secrets.GALASA_TEAM_WRITE_PACKAGES_TOKEN }}
- name: Extract metadata for galasactl-ibm-testing image
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.NAMESPACE }}/galasactl-ibm-x86_64-testing
- name: Build galasactl-ibm-testing image
id: build
uses: docker/build-push-action@v5
with:
context: .
file: dockerfiles/dockerfile.galasactl-ibm-testing
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
branch=${{ env.BRANCH }}
- name: Attempt to trigger test-cli-ecosystem-commands Tekton pipeline
run: |
echo "The Tekton pipeline test-cli-ecosystem-commands should be triggered in the next 2-minutes - check the Tekton dashboard"
report-failure:
name: Report failure in workflow
runs-on: ubuntu-latest
needs: [log-github-ref, build-cli, build-galasactl-ibm-testing-image-and-trigger-tekton-pipeline]
if: failure()
steps:
- name: Report failure in workflow to Slack
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
run : |
docker run --rm -v ${{ github.workspace }}:/var/workspace ghcr.io/galasa-dev/galasabld-ibm:main slackpost workflows --repo "cli" --workflowName "${{ github.workflow }}" --workflowRunNum "${{ github.run_id }}" --ref "${{ env.BRANCH }}" --hook "${{ env.SLACK_WEBHOOK }}"