Update multi tenancy_Integration.yml #14
Workflow file for this run
This file contains hidden or 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
| name: Multi Tenancy Integration Test | |
| on: | |
| push: | |
| branches: | |
| - multiTenancy_IntegrationTest | |
| workflow_dispatch: | |
| inputs: | |
| cf_space: | |
| description: 'Specify the Cloud Foundry space to run integration tests on' | |
| required: true | |
| default: developcap | |
| branch_name: | |
| description: 'Specify the branch to use for integration tests' | |
| required: true | |
| default: develop | |
| jobs: | |
| integration-test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| with: | |
| ref: ${{ github.event.inputs.branch_name }} | |
| - name: Set up Java 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: 17 | |
| distribution: 'temurin' | |
| - name: Install Cloud Foundry CLI and jq | |
| run: | | |
| echo -e "\033[36mInstalling Cloud Foundry CLI and jq...\033[0m" | |
| wget -q -O - https://packages.cloudfoundry.org/debian/cli.cloudfoundry.org.key | sudo apt-key add - | |
| echo "deb https://packages.cloudfoundry.org/debian stable main" | sudo tee /etc/apt/sources.list.d/cloudfoundry-cli.list | |
| sudo apt-get update | |
| sudo apt-get install -y cf8-cli jq | |
| echo -e "\033[32mInstallation complete!\033[0m" | |
| - name: Determine Cloud Foundry Space | |
| id: determine_space | |
| run: | | |
| if [ "${{ github.event.inputs.cf_space }}" == "developcap" ]; then | |
| space="${{ secrets.CF_SPACE }}" | |
| else | |
| space="${{ github.event.inputs.cf_space }}" | |
| fi | |
| echo -e "\033[34mSpace determined: \033[1m$space\033[22m\033[0m" | |
| echo "::set-output name=space::$space" | |
| - name: Login to Cloud Foundry | |
| run: | | |
| echo -e "\033[36mLogging in to Cloud Foundry...\033[0m" | |
| cf login -a ${{ secrets.CF_API }} \ | |
| -u ${{ secrets.CF_USER }} \ | |
| -p ${{ secrets.CF_PASSWORD }} \ | |
| -o ${{ secrets.CF_ORG }} \ | |
| -s ${{ steps.determine_space.outputs.space }} | |
| echo -e "\033[32mLogin successful!\033[0m" | |
| - name: Fetch and Escape Client Details for single tenant | |
| id: fetch_credentials | |
| run: | | |
| echo -e "\033[36mFetching Client Details for Single Tenant...\033[0m" | |
| service_instance_guid=$(cf service demoappjava-public-uaa --guid) | |
| if [ -z "$service_instance_guid" ]; then | |
| echo -e "\033[31mError: Unable to retrieve service instance GUID\033[0m" | |
| exit 1 | |
| fi | |
| bindings_response=$(cf curl "/v3/service_credential_bindings?service_instance_guids=${service_instance_guid}") | |
| binding_guid=$(echo $bindings_response | jq -r '.resources[0].guid') | |
| if [ -z "$binding_guid" ]; then | |
| echo -e "\033[31mError: Unable to retrieve binding GUID\033[0m" | |
| exit 1 | |
| fi | |
| binding_details=$(cf curl "/v3/service_credential_bindings/${binding_guid}/details") | |
| clientSecret=$(echo "$binding_details" | jq -r '.credentials.clientsecret') | |
| if [ -z "$clientSecret" ] || [ "$clientSecret" == "null" ]; then | |
| echo -e "\033[31mError: clientSecret is not set or is null\033[0m" | |
| exit 1 | |
| fi | |
| escapedClientSecret=$(echo "$clientSecret" | sed 's/\$/\\$/g') | |
| clientID=$(echo "$binding_details" | jq -r '.credentials.clientid') | |
| if [ -z "$clientID" ] || [ "$clientID" == "null" ]; then | |
| echo -e "\033[31mError: clientID is not set or is null\033[0m" | |
| exit 1 | |
| fi | |
| echo "::set-output name=CLIENT_SECRET::$escapedClientSecret" | |
| echo "::set-output name=CLIENT_ID::$clientID" | |
| echo -e "\033[32mClient Details fetched successfully!\033[0m" | |
| - name: Fetch and Escape Client Details for multi tenant | |
| id: fetch_credentials_mt | |
| run: | | |
| echo -e "\033[36mFetching Client Details for Multi Tenant...\033[0m" | |
| service_instance_guid=$(cf service bookshop-mt-uaa --guid) | |
| if [ -z "$service_instance_guid" ]; then | |
| echo -e "\033[31mError: Unable to retrieve service instance GUID\033[0m" | |
| exit 1 | |
| fi | |
| bindings_response=$(cf curl "/v3/service_credential_bindings?service_instance_guids=${service_instance_guid}") | |
| binding_guid=$(echo $bindings_response | jq -r '.resources[0].guid') | |
| if [ -z "$binding_guid" ]; then | |
| echo -e "\033[31mError: Unable to retrieve binding GUID\033[0m" | |
| exit 1 | |
| fi | |
| binding_details=$(cf curl "/v3/service_credential_bindings/${binding_guid}/details") | |
| clientSecret_mt=$(echo "$binding_details" | jq -r '.credentials.clientsecret') | |
| if [ -z "$clientSecret_mt" ] || [ "$clientSecret_mt" == "null" ]; then | |
| echo -e "\033[31mError: clientSecret_mt is not set or is null\033[0m" | |
| exit 1 | |
| fi | |
| escapedClientSecret_mt=$(echo "$clientSecret_mt" | sed 's/\$/\\$/g') | |
| clientID_mt=$(echo "$binding_details" | jq -r '.credentials.clientid') | |
| if [ -z "$clientID_mt" ] || [ "$clientID_mt" == "null" ]; then | |
| echo -e "\033[31mError: clientID_mt is not set or is null\033[0m" | |
| exit 1 | |
| fi | |
| echo "::set-output name=CLIENT_SECRET_MT::$escapedClientSecret_mt" | |
| echo "::set-output name=CLIENT_ID_MT::$clientID_mt" | |
| echo -e "\033[32mMulti Tenant Client Details fetched successfully!\033[0m" | |
| - name: Run integration tests | |
| env: | |
| CLIENT_SECRET: ${{ steps.fetch_credentials.outputs.CLIENT_SECRET }} | |
| CLIENT_ID: ${{ steps.fetch_credentials.outputs.CLIENT_ID }} | |
| CLIENT_SECRET_MT: ${{ steps.fetch_credentials_mt.outputs.CLIENT_SECRET_MT }} | |
| CLIENT_ID_MT: ${{ steps.fetch_credentials_mt.outputs.CLIENT_ID_MT }} | |
| run: | | |
| echo -e "\033[36mRunning Integration Tests...\033[0m" | |
| set -e | |
| PROPERTIES_FILE="sdm/src/test/resources/credentials.properties" | |
| appUrl="${{ secrets.CF_ORG }}-${{ steps.determine_space.outputs.space }}-demoappjava-srv.cfapps.eu12.hana.ondemand.com" | |
| appUrlMT="${{ secrets.CF_ORG }}-${{ steps.determine_space.outputs.space }}-bookshop-mt-srv.cfapps.eu12.hana.ondemand.com" | |
| authUrl="${{ secrets.CAPAUTH_URL }}" | |
| authUrlMT1="${{ secrets.AUTHURLMT1 }}" | |
| authUrlMT2="${{ secrets.AUTHURLMT2 }}" | |
| clientID="${{ env.CLIENT_ID }}" | |
| clientSecret="${{ env.CLIENT_SECRET }}" | |
| clientIDMT="${{ env.CLIENT_ID_MT }}" | |
| clientSecretMT="${{ env.CLIENT_SECRET_MT }}" | |
| username="${{ secrets.CF_USER }}" | |
| password="${{ secrets.CF_PASSWORD }}" | |
| noSDMRoleUsername="${{ secrets.NOSDMROLEUSERNAME }}" | |
| noSDMRoleUserPassword="${{ secrets.NOSDMROLEUSERPASSWORD }}" | |
| # Check for missing variables | |
| for var in appUrl appUrlMT authUrl authUrlMT1 authUrlMT2 clientID clientSecret clientIDMT clientSecretMT username password noSDMRoleUsername noSDMRoleUserPassword; do | |
| if [ -z "${!var}" ]; then | |
| echo -e "\033[31mError: ${var} is not set\033[0m" | |
| exit 1 | |
| fi | |
| done | |
| cat > "$PROPERTIES_FILE" <<EOL | |
| appUrl=$appUrl | |
| appUrlMT=$appUrlMT | |
| authUrl=$authUrl | |
| authUrlMT1=$authUrlMT1 | |
| authUrlMT2=$authUrlMT2 | |
| clientID=$clientID | |
| clientSecret=$clientSecret | |
| clientIDMT=$clientIDMT | |
| clientSecretMT=$clientSecretMT | |
| username=$username | |
| password=$password | |
| noSDMRoleUsername=$noSDMRoleUsername | |
| noSDMRoleUserPassword=$noSDMRoleUserPassword | |
| EOL | |
| # Display properties file | |
| echo -e "\033[34mProperties File:\033[0m" | |
| cat "$PROPERTIES_FILE" | |
| # Run Maven integration tests | |
| echo -e "\033[34mRunning Maven tests for Multi Tenancy...\033[0m" | |
| mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=multi -Dtenant=TENANT1 -DskipUnitTests || { echo -e "\033[31mMaven tests failed for Named User Flow (Multi Tenancy, Tenant 1)\033[0m"; exit 1; } | |
| # mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=multi -Dtenant=TENANT1 -DskipUnitTests || { echo -e "\033[31mMaven tests failed for Technical User Flow (Multi Tenancy, Tenant 1)\033[0m"; exit 1; } | |
| # mvn clean verify -P integration-tests -DtokenFlow=namedUser -DtenancyModel=multi -Dtenant=TENANT2 -DskipUnitTests || { echo -e "\033[31mMaven tests failed for Named User Flow (Multi Tenancy, Tenant 2)\033[0m"; exit 1; } | |
| # mvn clean verify -P integration-tests -DtokenFlow=technicalUser -DtenancyModel=multi -Dtenant=TENANT2 -DskipUnitTests || { echo -e "\033[31mMaven tests failed for Technical User Flow (Multi Tenancy, Tenant 2)\033[0m"; exit 1; } | |
| echo -e "\033[32mIntegration tests completed successfully!\033[0m" |