From 178aaa72fcf5e47095c8e2571ab4d2ec544ebb53 Mon Sep 17 00:00:00 2001 From: David Zager Date: Mon, 6 Nov 2023 13:45:43 -0500 Subject: [PATCH] :sparkles: run ci via bundle Signed-off-by: David Zager --- .github/workflows/global-ci-bundle.yml | 314 +++++++++++++++++++++++++ 1 file changed, 314 insertions(+) create mode 100644 .github/workflows/global-ci-bundle.yml diff --git a/.github/workflows/global-ci-bundle.yml b/.github/workflows/global-ci-bundle.yml new file mode 100644 index 0000000..36d7720 --- /dev/null +++ b/.github/workflows/global-ci-bundle.yml @@ -0,0 +1,314 @@ +name: Konveyor CI via Operator Bundle + +on: + workflow_call: + inputs: + artifact: + description: | + The name of the artifact storing custom images to be used during the CI run. All + images stored in the artifact will be automatically loaded. + type: string + required: false + bundle_image: + description: | + Image URI for the Konveyor operator bundle to be used when installing Konveyor. + This image MUST be publicly accessible (ie. not in the artifact). + For example, `ttl.sh/konveyor-operator-bundle-${SHA}:1h` + type: string + required: false + default: "" + namespace: + description: | + Namespace for the konveyor install. + type: string + required: false + default: "" + tackle_cr: + description: | + Full yaml encoded string representing the Tackle resource to be created. + type: string + required: false + default: "" + run_api_tests: + description: | + A flag that determines whether the API tests should be run or not + type: boolean + required: false + default: true + run_ui_tests: + description: | + A flag that determines whether the UI tests should be run or not + type: boolean + required: false + # TODO: Swap to true once these are passing consistently + default: false + api_tests_ref: + description: | + The branch or PR of the go-konveyor-tests repository to clone. + For a pull request, the reference format would be "refs/pull/${PR_NUMBER}/merge". + For a branch, the reference format would just be the branch name. + This input can be set automatically on a pull request by adding a string of the format: + Go tests PR: 140 + replacing "140" with the appropriate PR number. This will make it easier to coordinate changes + that require updating the global tests as well. + required: false + type: string + default: main + ui_tests_ref: + description: | + The branch or PR of the tackle-ui-tests repository to clone. + For a pull request, the reference format would be "refs/pull/${PR_NUMBER}/merge". + For a branch, the reference format would just be the branch name. + This input can be set automatically on a pull request by adding a string of the format: + UI tests PR: 140 + replacing "140" with the appropriate PR number. This will make it easier to coordinate changes + that require updating the global tests as well. + required: false + type: string + default: main + workflow_dispatch: + inputs: + artifact: + description: | + The name of the artifact storing custom images to be used during the CI run. All + images stored in the artifact will be automatically loaded. + type: string + required: false + bundle_image: + description: | + Image URI for the Konveyor operator bundle to be used when installing Konveyor. + This image MUST be publicly accessible (ie. not in the artifact). + For example, `ttl.sh/konveyor-operator-bundle-${SHA}:1h` + type: string + required: false + namespace: + description: | + Namespace for the konveyor install. + type: string + required: false + default: "" + tackle_cr: + description: | + Full yaml encoded string representing the Tackle resource to be created. + type: string + required: false + run_api_tests: + description: | + A flag that determines whether the API tests should be run or not + type: boolean + required: false + default: true + run_ui_tests: + description: | + A flag that determines whether the UI tests should be run or not + type: boolean + required: false + # TODO: Swap to true once these are passing consistently + default: false + api_tests_ref: + description: | + The branch or PR of the go-konveyor-tests repository to clone. + For a pull request, the reference format would be "refs/pull/${PR_NUMBER}/merge". + For a branch, the reference format would just be the branch name. + This input can be set automatically on a pull request by adding a string of the format: + Go tests PR: 140 + replacing "140" with the appropriate PR number. This will make it easier to coordinate changes + that require updating the global tests as well. + required: false + type: string + default: main + ui_tests_ref: + description: | + The branch or PR of the tackle-ui-tests repository to clone. + For a pull request, the reference format would be "refs/pull/${PR_NUMBER}/merge". + For a branch, the reference format would just be the branch name. + This input can be set automatically on a pull request by adding a string of the format: + UI tests PR: 140 + replacing "140" with the appropriate PR number. This will make it easier to coordinate changes + that require updating the global tests as well. + required: false + type: string + default: main + +jobs: + e2e-api-integration-tests: + runs-on: ubuntu-latest + if: ${{ inputs.run_api_tests }} + steps: + - name: Extract pull request number from inputs or PR description + run: | + PULL_REQUEST_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -oP '[A|a][P|p][I|i] [T|t]ests [P|p][R|r]: \K\d+' || true) + if [ -z "$PULL_REQUEST_NUMBER" ]; then + echo "GOLANG_TESTS_REF=${{ inputs.api_tests_ref }}" >>$GITHUB_ENV + else + echo "GOLANG_TESTS_REF=refs/pull/$PULL_REQUEST_NUMBER/merge" >>$GITHUB_ENV + fi + + - name: Checkout golang api tests repo + uses: actions/checkout@v3 + with: + repository: konveyor/go-konveyor-tests + path: go-konveyor-tests + ref: "${{ env.GOLANG_TESTS_REF }}" + + # TODO Should DRY this + - name: set up docker buildx + if: ${{ inputs.artifact != '' }} + uses: docker/setup-buildx-action@v2 + + - name: Download artifact + if: ${{ inputs.artifact != '' }} + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact }} + path: /tmp/images + + - name: start minikube + uses: konveyor/tackle2-operator/.github/actions/start-minikube@main + with: + memory: 6500M + + - name: Load images + if: ${{ inputs.artifact != '' }} + run: | + export SHELL=/bin/bash + eval $(minikube -p minikube docker-env) + for image in $(ls /tmp/images/*.tar); do + docker load --input ${image} + ; done + + - name: install konveyor + uses: konveyor/tackle2-operator/.github/actions/install-konveyor@main + with: + bundle_image: ${{ inputs.bundle_image }} + namespace: ${{ inputs.namespace }} + tackle_cr: ${{ inputs.tackle_cr }} + # end DRY + + - uses: actions/setup-go@v4 + with: + go-version: 1.18 + + - name: Install test dependencies + run: | + go install github.com/onsi/ginkgo/v2/ginkgo + working-directory: go-konveyor-tests + + - name: Build and run golang API tests + run: | + export HUB_BASE_URL="http://$(minikube ip)/hub" + make test-tier0 test-tier1 + working-directory: go-konveyor-tests + + e2e-ui-integration-tests: + if: ${{ inputs.run_ui_tests }} + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + # TODO: Support cypress-split in main tackle-ui-test project + # split: [0, 1, 2, 3, 4, 5, 6, 7, 8] + tier: [tier1, tier2, tier3] + steps: + + - name: Extract pull request number from inputs or PR description + run: | + PULL_REQUEST_NUMBER=$(echo "${{ github.event.pull_request.body }}" | grep -oP '[U|u][I|i] [T|t]ests [P|p][R|r]: \K\d+' || true) + if [ -z "$PULL_REQUEST_NUMBER" ]; then + echo "UI_TESTS_REF=${{ inputs.ui_tests_ref }}" >>$GITHUB_ENV + else + echo "UI_TESTS_REF=refs/pull/$PULL_REQUEST_NUMBER/merge" >>$GITHUB_ENV + fi + + - name: Checkout ui tests repo + uses: actions/checkout@v3 + with: + repository: konveyor/tackle-ui-tests + path: tackle-ui-tests + ref: "${{ env.UI_TESTS_REF }}" + + # TODO Should DRY this + - name: set up docker buildx + if: ${{ inputs.artifact != '' }} + uses: docker/setup-buildx-action@v2 + + - name: Download artifact + if: ${{ inputs.artifact != '' }} + uses: actions/download-artifact@v3 + with: + name: ${{ inputs.artifact }} + path: /tmp/images + + - name: start minikube + uses: konveyor/tackle2-operator/.github/actions/start-minikube@main + with: + memory: 6500M + + - name: Load images + if: ${{ inputs.artifact != '' }} + run: | + export SHELL=/bin/bash + eval $(minikube -p minikube docker-env) + for image in $(ls /tmp/images/*.tar); do + docker load --input ${image} + ; done + + - name: install konveyor + uses: konveyor/tackle2-operator/.github/actions/install-konveyor@main + with: + bundle_image: ${{ inputs.bundle_image }} + namespace: ${{ inputs.namespace }} + tackle_cr: ${{ inputs.tackle_cr }} + # end DRY + + - name: Wait for Ingress and expose UI service + run: | + external_ip="" + echo $external_ip; + while [[ -z $external_ip ]] + do + echo "Waiting for end point..." + external_ip=$(kubectl get ingress tackle --template="{{range.status.loadBalancer.ingress}}{{.ip}}{{end}}" -n konveyor-tackle);[[ -z $external_ip ]] && + echo $external_ip; + sleep 10; + done + echo "End point ready:" && + echo $external_ip; + echo "UI_URL=https://$(minikube ip)" >>$GITHUB_ENV + + - name: Run login tests + uses: cypress-io/github-action@v5 + env: + CYPRESS_user: admin + CYPRESS_pass: password + CYPRESS_tackleUrl: "${{ env.UI_URL }}" + with: + working-directory: tackle-ui-tests + spec: "cypress/e2e/tests/login.test.ts" + + - name: Run UI tests + uses: cypress-io/github-action@v5 + env: + CYPRESS_INCLUDE_TAGS: "@${{ matrix.tier }}" + CYPRESS_user: "admin" + CYPRESS_pass: "Dog8code" + CYPRESS_tackleUrl: "${{ env.UI_URL }}" + CYPRESS_git_user: "fakeuser" + CYPRESS_git_password: "${{ secrets.GITHUB_TOKEN }}" + CYPRESS_git_key: "${{ secrets.GITHUB_TOKEN }}" + # TODO: Support cypress-split in main tackle-ui-test project + # CYPRESS_split: "${{ strategy.job-total }}" + # CYPRESS_splitIndex: "${{ strategy.job-index }}" + with: + working-directory: tackle-ui-tests + spec: "**/*.test.ts" + + - name: Upload cypress report data as artifact + uses: actions/upload-artifact@v3 + if: always() + with: + # name: tackle-ui-test-reports-${{ matrix.split }} + name: tackle-ui-test-reports-${{ matrix.tier }} + path: | + tackle-ui-tests/cypress/reports + tackle-ui-tests/cypress/screenshots