integration-test #12
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
# Copyright (c) IBM Corporation. | |
# Copyright (c) Microsoft Corporation. | |
name: integration-test | |
on: | |
workflow_dispatch: | |
inputs: | |
enableAppGWIngress: | |
description: 'Application Gateway Ingress Controller' | |
required: true | |
type: boolean | |
default: true | |
deployWLO: | |
description: 'WebSphere Liberty Operator' | |
required: true | |
type: boolean | |
default: false | |
deployApplication: | |
description: 'Sample application' | |
required: true | |
type: boolean | |
default: true | |
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.aks | |
# Enable/disable AGIC, 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":{"enableAppGWIngress": "true|false", "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.aks | |
# Enable/disable AGIC, 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": {"enableAppGWIngress": true|false, "deployWLO": true|false, "deployApplication": true|false, "autoScaling": true|false, "deleteAzureResources": true|false}}' | |
env: | |
repoName: "azure.liberty.aks" | |
azureCredentials: ${{ secrets.AZURE_CREDENTIALS }} | |
userName: ${{ secrets.USER_NAME }} | |
msTeamsWebhook: ${{ secrets.MSTEAMS_WEBHOOK }} | |
testResourceGroup: libertyAksTestRG-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }} | |
testDeploymentName: libertyAksTestDeployment-${{ github.repository_owner }}-${{ github.run_id }}-${{ github.run_number }} | |
location: eastus | |
jobs: | |
integration-test: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get versions of external dependencies | |
id: get-external-deps-versions | |
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 "azCliVersion=${AZ_CLI_VERSION}" >> $GITHUB_ENV | |
echo "bicepVersion=${BICEP_VERSION}" >> $GITHUB_ENV | |
echo "refArmttk=${ARM_TTK_REFERENCE}" >> $GITHUB_ENV | |
echo "refJavaee=${AZURE_JAVAEE_IAAS_REFERENCE}" >> $GITHUB_ENV | |
- name: Set up JDK 1.8 | |
uses: actions/setup-java@v1 | |
with: | |
java-version: 1.8 | |
- name: Set up bicep | |
run: | | |
curl -Lo bicep https://github.com/Azure/bicep/releases/download/${{ env.bicepVersion }}/bicep-linux-x64 | |
chmod +x ./bicep | |
sudo mv ./bicep /usr/local/bin/bicep | |
bicep --version | |
- name: Checkout azure-javaee-iaas | |
uses: actions/checkout@v2 | |
with: | |
repository: Azure/azure-javaee-iaas | |
path: azure-javaee-iaas | |
ref: ${{ env.refJavaee }} | |
- name: Checkout arm-ttk | |
uses: actions/checkout@v2 | |
with: | |
repository: Azure/arm-ttk | |
path: arm-ttk | |
ref: ${{ env.refArmttk }} | |
- name: Checkout ${{ env.repoName }} | |
uses: actions/checkout@v2 | |
with: | |
path: ${{ env.repoName }} | |
ref: ${{ github.event.inputs.ref }} | |
- name: Build azure-javaee-iaas | |
run: mvn -DskipTests clean install --file azure-javaee-iaas/pom.xml | |
- name: Build ${{ env.repoName }} | |
run: | | |
enableAppGWIngress=false | |
if ${{ inputs.enableAppGWIngress == true || github.event.client_payload.enableAppGWIngress == true }}; then | |
enableAppGWIngress=true | |
fi | |
echo "enableAppGWIngress=${enableAppGWIngress}" >> $GITHUB_ENV | |
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 -DcreateACR=true \ | |
-DenableAppGWIngress=${enableAppGWIngress} -DappgwUsePrivateIP=false -DappGatewayCertificateOption=generateCert -DenableCookieBasedAffinity=true \ | |
-DdeployWLO=${deployWLO} -Dedition="IBM WebSphere Application Server" -DproductEntitlementSource="Standalone" \ | |
-DdeployApplication=${deployApplication} -DappImagePath=icr.io/appcafe/open-liberty/samples/getting-started -DappReplicas=2 \ | |
-DautoScalingParam=${autoScaling} -DcpuUtilizationPercentageParam=80 -DminReplicasParam=1 -DmaxReplicasParam=100 -DrequestCPUMillicoreParam=300 \ | |
-Dtest.args="-Test All" -Pbicep -Passembly -Ptemplate-validation-tests clean install | |
- uses: azure/login@v1 | |
id: azure-login | |
with: | |
creds: ${{ env.azureCredentials }} | |
- name: Start the deployment | |
run: | | |
cd ${{ env.repoName }}/target/cli | |
chmod a+x deploy.azcli | |
./deploy.azcli -n ${{ env.testDeploymentName }} -g ${{ env.testResourceGroup }} -l ${{ env.location }} | |
- name: Verify the deployment | |
run: | | |
outputs=$(az deployment group show -n ${{ env.testDeploymentName }} -g ${{ env.testResourceGroup }} --query 'properties.outputs') | |
appHttpEndpoint=$(echo $outputs | jq -r '.appHttpEndpoint.value') | |
echo "appHttpEndpoint: ${appHttpEndpoint}" | |
appHttpsEndpoint=$(echo $outputs | jq -r '.appHttpsEndpoint.value') | |
echo "appHttpsEndpoint: ${appHttpsEndpoint}" | |
if [[ $deployApplication == "true" ]]; then | |
if [[ -z "$appHttpEndpoint" ]]; then | |
echo "Invalid value of appHttpEndpoint: ${appHttpEndpoint}" | |
exit 1 | |
fi | |
curl --verbose --connect-timeout 60 --max-time 180 --retry 10 --retry-delay 30 --retry-max-time 180 --retry-connrefused $appHttpEndpoint | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to access ${appHttpEndpoint}." | |
exit 1 | |
fi | |
elif [[ -n "$appHttpEndpoint" ]]; then | |
echo "Invalid value of appHttpEndpoint: ${appHttpEndpoint}" | |
exit 1 | |
fi | |
if [[ $deployApplication == "true" && $enableAppGWIngress == "true" ]]; then | |
if [[ -z "$appHttpsEndpoint" ]]; then | |
echo "Invalid value of appHttpsEndpoint: ${appHttpsEndpoint}" | |
exit 1 | |
fi | |
curl --verbose --connect-timeout 60 --max-time 180 --retry 10 --retry-delay 30 --retry-max-time 180 --retry-connrefused $appHttpsEndpoint -k | |
if [[ $? -ne 0 ]]; then | |
echo "Failed to access ${appHttpsEndpoint}." | |
exit 1 | |
fi | |
elif [[ -n "$appHttpsEndpoint" ]]; then | |
echo "Invalid value of appHttpsEndpoint: ${appHttpsEndpoint}" | |
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@v1 | |
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: [notification,integration-test] | |
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-in-group | |
if: ${{ (github.event_name == 'workflow_dispatch' && inputs.deleteAzureResources) || (github.event_name == 'repository_dispatch' && github.event.client_payload.deleteAzureResources) }} | |
run: | | |
az group delete -n ${{ env.testResourceGroup }} --yes --no-wait |