-
Notifications
You must be signed in to change notification settings - Fork 6
213 lines (212 loc) · 10.8 KB
/
integration-test.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
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
# Copyright (c) IBM Corporation.
# Copyright (c) Microsoft Corporation.
name: integration-test
on:
workflow_dispatch:
inputs:
deployWLO:
description: 'WebSphere Liberty Operator'
required: true
type: boolean
default: false
deployApplication:
description: 'Deploy application'
required: true
type: boolean
default: true
appImagePath:
description: 'Application image path'
required: true
default: 'icr.io/appcafe/open-liberty/samples/getting-started'
autoScaling:
description: 'Autoscaling for app deployment'
required: true
type: boolean
default: false
deleteAzureResources:
description: 'Delete Azure resources at the end'
required: true
type: boolean
default: true
# Allows you to run this workflow using GitHub workflow dispatch APIs
# PERSONAL_ACCESS_TOKEN=<GITHUB_PERSONAL_ACCESS_TOKEN>
# REPO_NAME=WASdev/azure.liberty.aro
# Enable/disable WebSphere Liberty Operator and sample application. Keep/delete Azure resources at the end.
# curl --verbose -XPOST -u "WASdev:${PERSONAL_ACCESS_TOKEN}" -H "Accept: application/vnd.github.everest-preview+json" -H "Content-Type: application/json" https://api.github.com/repos/${REPO_NAME}/actions/workflows/integration-test.yaml/dispatches --data '{"ref": "main", "inputs":{"deployWLO": "true|false", "deployApplication": "true|false", "autoScaling": "true|false", "deleteAzureResources": "true|false"}}'
repository_dispatch:
types: [integration-test]
# Allows you to run this workflow using GitHub repository dispatch APIs
# PERSONAL_ACCESS_TOKEN=<GITHUB_PERSONAL_ACCESS_TOKEN>
# REPO_NAME=WASdev/azure.liberty.aro
# Enable/disable WebSphere Liberty Operator and sample application. Keep/delete Azure resources at the end.
# curl --verbose -X POST https://api.github.com/repos/${REPO_NAME}/dispatches -H "Accept: application/vnd.github.everest-preview+json" -H "Authorization: token ${PERSONAL_ACCESS_TOKEN}" --data '{"event_type": "integration-test", "client_payload": {"deployWLO": true|false, "deployApplication": true|false, "autoScaling": "true|false", "deleteAzureResources": "true|false"}}'
env:
repoName: "azure.liberty.aro"
azureCredentials: ${{ secrets.AZURE_CREDENTIALS }}
userName: ${{ secrets.USER_NAME }}
pullSecretEncoded: ${{ secrets.PULL_SECRET_ENCODED }}
msTeamsWebhook: ${{ secrets.MSTEAMS_WEBHOOK }}
testResourceGroup: libertyAroTestRG-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }}
testDeploymentName: libertyAroTestDeployment-${{ github.run_id }}-${{ github.run_number }}
location: eastus
jobs:
integration-test:
runs-on: ubuntu-latest
outputs:
clientId: ${{ steps.deploy.outputs.clientId }}
steps:
- name: Get versions of external dependencies
run: |
curl -Lo external-deps-versions.properties https://raw.githubusercontent.com/Azure/azure-javaee-iaas/main/external-deps-versions.properties
source external-deps-versions.properties
echo "bicepVersion=${BICEP_VERSION}" >> $GITHUB_ENV
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
server-username: MAVEN_USERNAME # env variable for username
server-password: MAVEN_TOKEN # env variable for token
- name: Set Maven env
env:
MAVEN_USERNAME: github
MAVEN_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
echo "MAVEN_USERNAME=${MAVEN_USERNAME}" >> "$GITHUB_ENV"
echo "MAVEN_TOKEN=${MAVEN_TOKEN}" >> "$GITHUB_ENV"
- name: Checkout arm-ttk
uses: actions/checkout@v2
with:
repository: Azure/arm-ttk
path: arm-ttk
- name: Checkout ${{ env.repoName }}
uses: actions/checkout@v2
with:
path: ${{ env.repoName }}
ref: ${{ github.event.inputs.ref }}
- name: Build ${{ env.repoName }}
run: |
deployWLO=false
if ${{ inputs.deployWLO == true || github.event.client_payload.deployWLO == true }}; then
deployWLO=true
fi
deployApplication=false
if ${{ inputs.deployApplication == true || github.event.client_payload.deployApplication == true }}; then
deployApplication=true
fi
echo "deployApplication=${deployApplication}" >> $GITHUB_ENV
autoScaling=false
if ${{ inputs.autoScaling == true || github.event.client_payload.autoScaling == true }}; then
autoScaling=true
fi
cd ${{ env.repoName }}
mvn -Dgit.repo=${{ env.userName }} -Dgit.tag=$GITHUB_REF_NAME -DcreateCluster=true \
-DdeployWLO=${deployWLO} -Dedition="IBM WebSphere Application Server" -DproductEntitlementSource="Standalone" \
-DdeployApplication=${deployApplication} -DappImagePath=${{ inputs.appImagePath }} -DautoScalingParam=${autoScaling} -DappReplicas=2 \
-Dtest.args="-Test All" -Passembly -Ptemplate-validation-tests clean install
- uses: azure/login@v1
id: azure-login
with:
creds: ${{ env.azureCredentials }}
- name: Start the deployment
id: deploy
run: |
servicePrincipal=$(az ad sp create-for-rbac --sdk-auth)
clientId=$(echo $servicePrincipal | jq -r '.clientId')
echo "clientId=${clientId}" >> $GITHUB_ENV
echo "clientId=${clientId}" >> "$GITHUB_OUTPUT"
clientSecret=$(echo $servicePrincipal | jq -r '.clientSecret')
aadObjectId=$(az ad sp show --id ${clientId} --query id -o tsv)
rpObjectId=$(az ad sp list --display-name "Azure Red Hat OpenShift RP" --query [0].id -o tsv)
cd ${{ env.repoName }}/target/cli
chmod a+x deploy.azcli
./deploy.azcli -n ${{ env.testDeploymentName }} -g ${{ env.testResourceGroup }} -l ${{ env.location }} -t ${{ env.pullSecretEncoded }} \
-c ${clientId} -s ${clientSecret} -a ${aadObjectId} -r ${rpObjectId}
- name: Verify the deployment
run: |
clusterName=$(az deployment group show -n ${{ env.testDeploymentName }} -g ${{ env.testResourceGroup }} --query 'properties.outputs.clusterName.value' -o tsv)
appEndpoint=$(az resource show -n aroscript${clusterName:7} -g ${{ env.testResourceGroup }} --resource-type Microsoft.Resources/deploymentScripts --query "properties.outputs.appEndpoint" -o tsv)
echo "appEndpoint: ${appEndpoint}"
if [[ $deployApplication == "true" ]]; then
if [[ -z "$appEndpoint" ]]; then
echo "Invalid value of appEndpoint: ${appEndpoint}"
exit 1
fi
httpCode=$(curl --verbose --connect-timeout 60 --max-time 180 --retry 10 --retry-delay 30 --retry-max-time 180 --retry-connrefused --write-out '%{http_code}' --silent --output /dev/null $appEndpoint)
echo "http_code is $httpCode"
if [ "$httpCode" -ne 200 ]; then
echo "Failed to access ${appEndpoint}."
exit 1
fi
elif [[ -n "$appEndpoint" ]]; then
echo "Invalid value of appEndpoint: ${appEndpoint}"
exit 1
fi
- name: Generate artifact file name and path
id: artifact_file
run: |
version=$(awk '/<version>[^<]+<\/version>/{gsub(/<version>|<\/version>/,"",$1);print $1;exit;}' ${{ env.repoName }}/pom.xml)
artifactName=${{ env.repoName }}-$version-arm-assembly
unzip ${{ env.repoName }}/target/$artifactName.zip -d ${{ env.repoName }}/target/$artifactName
echo "##[set-output name=artifactName;]${artifactName}"
echo "##[set-output name=artifactPath;]${{ env.repoName }}/target/$artifactName"
- name: Archive ${{ env.repoName }} template
uses: actions/upload-artifact@v4
if: success()
with:
name: ${{steps.artifact_file.outputs.artifactName}}
path: ${{steps.artifact_file.outputs.artifactPath}}
notification:
needs: integration-test
if: always()
runs-on: ubuntu-latest
steps:
- name: Output inputs from workflow_dispatch
run: echo "${{ toJSON(github.event.inputs) }}"
- name: Output client_payload from repository_dispatch
run: echo "${{ toJSON(github.event.client_payload) }}"
- name: Send notification
if: ${{ env.msTeamsWebhook != 'NA' }}
run: |
workflowJobs=$(curl -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ env.userName }}/${{ env.repoName }}/actions/runs/${{ github.run_id }}/jobs)
successIntegrationTestJob=$(echo $workflowJobs | jq 'select(.jobs != null) | .jobs | map(select(.name=="integration-test" and .conclusion=="success")) | length')
echo "$successIntegrationTestJob"
if [ -z $successIntegrationTestJob ];then
echo "jobs not retrieved."
elif (($successIntegrationTestJob == 0));then
echo "Job integration-test failed, send notification to Teams"
curl ${{ env.msTeamsWebhook }} \
-H 'Content-Type: application/json' \
--data-binary @- << EOF
{
"@context":"http://schema.org/extensions",
"@type":"MessageCard",
"text":"Workflow integration-test of repo ${{ env.repoName }} failed, please take a look at: https://github.com/${{ env.userName }}/${{ env.repoName }}/actions/runs/${{ github.run_id }}"
}
EOF
else
echo "Job integration-test succeeded."
fi
delete-resources:
needs: [integration-test, notification]
runs-on: ubuntu-latest
if: always()
steps:
- uses: azure/login@v1
id: azure-login
with:
creds: ${{ env.azureCredentials }}
- name: Checkout ${{ env.repoName }}
uses: actions/checkout@v2
with:
path: ${{ env.repoName }}
ref: ${{ github.event.inputs.ref }}
- name: Delete all Azure resources
id: delete-resources
if: ${{ (github.event_name == 'workflow_dispatch' && inputs.deleteAzureResources) || (github.event_name == 'repository_dispatch' && github.event.client_payload.deleteAzureResources) }}
run: |
echo "delete resource group: " ${{ env.testResourceGroup }}
az group delete -n ${{ env.testResourceGroup }} --yes
echo "delete app with clientId: " ${{ needs.integration-test.outputs.clientId }}
az ad app delete --id ${{ needs.integration-test.outputs.clientId }}