|
| 1 | +# ------------------------------------------------------------ |
| 2 | +# Copyright (c) Microsoft Corporation and Dapr Contributors. |
| 3 | +# Licensed under the MIT License. |
| 4 | +# ------------------------------------------------------------ |
| 5 | + |
| 6 | +name: Components Integration Tests |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_dispatch: |
| 10 | + schedule: |
| 11 | + - cron: '*/30 * * * *' |
| 12 | + pull_request: |
| 13 | + branches: |
| 14 | + - master |
| 15 | + - release-* |
| 16 | + |
| 17 | +jobs: |
| 18 | + pre_job: |
| 19 | + name: Skip Duplicate Actions |
| 20 | + runs-on: ubuntu-latest |
| 21 | + outputs: |
| 22 | + should_skip: ${{ steps.skip_check.outputs.should_skip }} |
| 23 | + steps: |
| 24 | + - id: skip_check |
| 25 | + uses: fkirc/skip-duplicate-actions@v3.4.0 |
| 26 | + with: |
| 27 | + cancel_others: 'true' |
| 28 | + paths_ignore: '["**.md", ".codecov.yaml", ".github/workflows/dapr-automerge.yml"]' |
| 29 | + # Based on whether this is a PR or a scheduled run, we will run a different |
| 30 | + # subset of the integration tests. This allows all the tests not requiring |
| 31 | + # secrets to be executed on pull requests. |
| 32 | + generate-matrix: |
| 33 | + runs-on: ubuntu-latest |
| 34 | + needs: pre_job |
| 35 | + if: needs.pre_job.outputs.should_skip != 'true' |
| 36 | + steps: |
| 37 | + - name: Install yq |
| 38 | + run: | |
| 39 | + sudo snap install yq |
| 40 | +
|
| 41 | + - name: Specify components not requiring secrets nor certs |
| 42 | + id: pr-components |
| 43 | + run: | |
| 44 | + PR_COMPONENTS=$(yq -I0 --tojson eval - << EOF |
| 45 | + - bindings.mysql |
| 46 | + - bindings.rabbitmq |
| 47 | + - state.mysql |
| 48 | + - state.postgresql |
| 49 | + - state.sqlserver |
| 50 | + EOF |
| 51 | + ) |
| 52 | + echo "::set-output name=pr-components::$PR_COMPONENTS" |
| 53 | +
|
| 54 | + - name: Specify components requiring secrets or certs |
| 55 | + id: cron-components |
| 56 | + run: | |
| 57 | + if [ "${{ github.event_name }}" = "pull_request" ]; then |
| 58 | + echo "::set-output name=cron-components::[]" |
| 59 | + exit |
| 60 | + fi |
| 61 | + # Unfortunately, Azure secrets can't have underscores in |
| 62 | + # names, while environment variables with hyphens ('-') are |
| 63 | + # troublesome. |
| 64 | + # |
| 65 | + # We work around here by leveraging the fact that |
| 66 | + # environment variable names are case sensitive, so |
| 67 | + # CamelCase would still work. |
| 68 | + # |
| 69 | + # That is slightly better than something like |
| 70 | + # AZURECOSMOSDBMASTERKEY, which is extremely hard to read |
| 71 | + # and errorprone. |
| 72 | + # |
| 73 | + # Only list the secrets you need for the component. |
| 74 | + CRON_COMPONENTS=$(yq -I0 --tojson eval - << EOF |
| 75 | + - component: bindings.azure.servicebusqueues |
| 76 | + required-secrets: AzureServiceBusConnectionString |
| 77 | + EOF |
| 78 | + ) |
| 79 | + echo "::set-output name=cron-components::$CRON_COMPONENTS" |
| 80 | + outputs: |
| 81 | + pr-components: ${{ steps.pr-components.outputs.pr-components }} |
| 82 | + cron-components: ${{ steps.cron-components.outputs.cron-components }} |
| 83 | + |
| 84 | + integration: |
| 85 | + name: ${{ matrix.component }} integration |
| 86 | + runs-on: ubuntu-latest |
| 87 | + defaults: |
| 88 | + run: |
| 89 | + shell: bash |
| 90 | + working-directory: ./src/github.com/dapr/components-contrib |
| 91 | + needs: generate-matrix |
| 92 | + |
| 93 | + strategy: |
| 94 | + fail-fast: false # Keep running even if one component fails |
| 95 | + matrix: |
| 96 | + component: ${{ fromJson(needs.generate-matrix.outputs.pr-components) }} |
| 97 | + include: ${{ fromJson(needs.generate-matrix.outputs.cron-components) }} |
| 98 | + steps: |
| 99 | + - name: Check out code onto GOPATH |
| 100 | + uses: actions/checkout@v2 |
| 101 | + with: |
| 102 | + path: ./src/github.com/dapr/components-contrib |
| 103 | + |
| 104 | + - name: Setup test output |
| 105 | + shell: bash |
| 106 | + run: | |
| 107 | + export TEST_OUTPUT_FILE_PREFIX=$GITHUB_WORKSPACE/test_report |
| 108 | + echo "TEST_OUTPUT_FILE_PREFIX=$TEST_OUTPUT_FILE_PREFIX" >> $GITHUB_ENV |
| 109 | +
|
| 110 | + - uses: Azure/login@v1 |
| 111 | + with: |
| 112 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 113 | + if: matrix.required-secrets != '' |
| 114 | + |
| 115 | + - name: Setup secrets |
| 116 | + uses: Azure/get-keyvault-secrets@v1 |
| 117 | + with: |
| 118 | + # Set this GitHub secret to your KeyVault, and grant the KeyVault policy to your Service Principal: |
| 119 | + # az keyvault set-policy -n $AZURE_KEYVAULT --secret-permissions get list --spn $SPN_CLIENT_ID |
| 120 | + keyvault: ${{ secrets.AZURE_KEYVAULT }} |
| 121 | + secrets: ${{ matrix.required-secrets }} |
| 122 | + id: get-azure-secrets |
| 123 | + if: matrix.required-secrets != '' |
| 124 | + |
| 125 | + - name: Configure Azure servicebusqueues environment |
| 126 | + run: | |
| 127 | + export DAPR_TEST_AZURE_SERVICEBUS="${{ env.AzureServiceBusConnectionString }}" |
| 128 | + echo "DAPR_TEST_AZURE_SERVICEBUS=$DAPR_TEST_AZURE_SERVICEBUS" >> $GITHUB_ENV |
| 129 | + if: contains(matrix.component, 'azure.servicebusqueues') |
| 130 | + |
| 131 | + - name: Start sqlserver |
| 132 | + run: | |
| 133 | + export DAPR_TEST_SQL_CONNSTRING="server=localhost;user id=sa;password=Pass@Word1;port=1433;" |
| 134 | + echo "DAPR_TEST_SQL_CONNSTRING=$DAPR_TEST_SQL_CONNSTRING" >> $GITHUB_ENV |
| 135 | + docker-compose -f ./.github/infrastructure/docker-compose-sqlserver.yml -p sqlserver up -d |
| 136 | + if: contains(matrix.component, 'sqlserver') |
| 137 | + |
| 138 | + - name: Start rabbitmq |
| 139 | + run: | |
| 140 | + export DAPR_TEST_RABBITMQ_HOST="amqp://localhost:5672" |
| 141 | + echo "DAPR_TEST_RABBITMQ_HOST=$DAPR_TEST_RABBITMQ_HOST" >> $GITHUB_ENV |
| 142 | + docker-compose -f ./.github/infrastructure/docker-compose-rabbitmq.yml -p rabbitmq up -d |
| 143 | + if: contains(matrix.component, 'rabbitmq') |
| 144 | + |
| 145 | + - name: Start mysql |
| 146 | + run: | |
| 147 | + export MYSQL_TEST_CONN_URL="dapr:example@tcp(localhost:3306)/dapr_state_store?allowNativePasswords=true" |
| 148 | + echo "MYSQL_TEST_CONN_URL=$MYSQL_TEST_CONN_URL" >> $GITHUB_ENV |
| 149 | + export DAPR_TEST_MYSQL_CONNSTRING="dapr:example@tcp(localhost:3306)/?allowNativePasswords=true" |
| 150 | + echo "DAPR_TEST_MYSQL_CONNSTRING=$DAPR_TEST_MYSQL_CONNSTRING" >> $GITHUB_ENV |
| 151 | + docker-compose -f ./.github/infrastructure/docker-compose-mysql.yml -p mysql up -d |
| 152 | + if: contains(matrix.component, 'mysql') |
| 153 | + |
| 154 | + - name: Start postgresql |
| 155 | + run: | |
| 156 | + export DAPR_TEST_POSTGRES_CONNSTRING="host=localhost user=postgres password=example port=5432 connect_timeout=10 database=dapr_test" |
| 157 | + echo "DAPR_TEST_POSTGRES_CONNSTRING=$DAPR_TEST_POSTGRES_CONNSTRING" >> $GITHUB_ENV |
| 158 | + docker-compose -f ./.github/infrastructure/docker-compose-postgresql.yml -p postgresql up -d |
| 159 | + if: contains(matrix.component, 'postgresql') |
| 160 | + |
| 161 | + - name: Set up Go |
| 162 | + uses: actions/setup-go@v2 |
| 163 | + with: |
| 164 | + go-version: '^1.16.6' |
| 165 | + |
| 166 | + - name: Download Go dependencies |
| 167 | + run: | |
| 168 | + go mod download |
| 169 | + go install gotest.tools/gotestsum@latest |
| 170 | +
|
| 171 | + - name: Run tests |
| 172 | + continue-on-error: true |
| 173 | + run: | |
| 174 | + set -e |
| 175 | + KIND=$(echo ${{ matrix.component }} | cut -d. -f1) |
| 176 | + NAME=$(echo ${{ matrix.component }} | cut -d. -f2-) |
| 177 | + NAME_PATH=$(echo ${NAME} | tr '.' '/') |
| 178 | + echo "Running integration tests for ${KIND}/${NAME_PATH} ... " |
| 179 | +
|
| 180 | + set +e |
| 181 | + gotestsum --jsonfile ${{ env.TEST_OUTPUT_FILE_PREFIX }}_integration.json \ |
| 182 | + --junitfile ${{ env.TEST_OUTPUT_FILE_PREFIX }}_integration.xml --format standard-verbose -- \ |
| 183 | + -p 2 -count=1 -timeout=5m -tags=integration_test ./${KIND}/${NAME_PATH} |
| 184 | +
|
| 185 | + status=$? |
| 186 | + echo "Completed tests for Test${KIND_UPPER}Conformance/${KIND}/${NAME_PATH} ... " |
| 187 | + if test $status -ne 0; then |
| 188 | + echo "Setting INTEGRATION_FAILURE" |
| 189 | + echo "INTEGRATION_FAILURE=true" >> $GITHUB_ENV |
| 190 | + fi |
| 191 | + set -e |
| 192 | +
|
| 193 | + # Fail the step if we found no test to run |
| 194 | + if grep -q "warning: no tests to run" ${{ env.TEST_OUTPUT_FILE_PREFIX }}_integration.json ; then |
| 195 | + echo "::error:: No test was found for component ${{ matrix.component }}" |
| 196 | + exit -1 |
| 197 | + fi |
| 198 | +
|
| 199 | + - name: Check integration test passed |
| 200 | + continue-on-error: false |
| 201 | + run: | |
| 202 | + echo "INTEGRATION_FAILURE=$INTEGRATION_FAILURE" |
| 203 | + if [[ -v INTEGRATION_FAILURE ]]; then |
| 204 | + exit 1 |
| 205 | + fi |
| 206 | +
|
| 207 | + # Upload logs for test analytics to consume |
| 208 | + - name: Upload test results |
| 209 | + if: always() |
| 210 | + uses: actions/upload-artifact@master |
| 211 | + with: |
| 212 | + name: ${{ matrix.component }}_integration_test |
| 213 | + path: ${{ env.TEST_OUTPUT_FILE_PREFIX }}_integration.* |
0 commit comments