E2E by cibelius to ocrvs-10939 (core: 30d641b, farajaland: 2ecca1c) #11129
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: Deploy & run E2E | |
| run-name: 'E2E by ${{ github.event.client_payload.actor || github.actor }} to ${{ github.event.client_payload.stack || github.event.inputs.stack }} (core: ${{ github.event.client_payload.core-image-tag || inputs.core-image-tag }}, farajaland: ${{ github.event.client_payload.countryconfig-image-tag || inputs.countryconfig-image-tag }}) ${{ github.event.client_payload.runtime || inputs.runtime }}' | |
| on: | |
| repository_dispatch: | |
| types: [run_e2e] | |
| workflow_dispatch: | |
| inputs: | |
| core-image-tag: | |
| description: Core image tag | |
| required: true | |
| default: 'v1.8.0' | |
| countryconfig-image-tag: | |
| description: Your Country Config DockerHub image tag | |
| required: true | |
| default: 'v1.8.0' | |
| stack: | |
| type: string | |
| description: Stack name | |
| required: true | |
| keep-e2e: | |
| description: Keep environment after run | |
| required: false | |
| default: false | |
| type: boolean | |
| chart-branch: | |
| description: Helm chart version to deploy | |
| required: false | |
| default: 'develop' | |
| branch: | |
| description: e2e branch | |
| required: false | |
| default: 'develop' | |
| runtime: | |
| required: false | |
| default: 'none' | |
| type: choice | |
| options: | |
| - none | |
| - docker | |
| - k8s | |
| reset: | |
| description: reset e2e | |
| required: false | |
| default: false | |
| type: boolean | |
| concurrency: | |
| group: ${{ github.event.client_payload.stack || inputs.stack }} | |
| cancel-in-progress: true | |
| jobs: | |
| debug: | |
| name: Debug output | |
| runs-on: ubuntu-22.04 | |
| outputs: | |
| runtime: ${{ steps.runtime.outputs.runtime }} | |
| domain: ${{ steps.runtime.outputs.domain }} | |
| steps: | |
| - name: Print Entire Event Payload | |
| run: | | |
| echo "${{ toJson(github.event) }}" | |
| - name: Select docker swarm or k8s | |
| id: runtime | |
| env: | |
| run_id: ${{ github.run_id }} | |
| runtime: ${{ github.event.client_payload.runtime || inputs.runtime }} | |
| stack: ${{ github.event.client_payload.stack || inputs.stack }} | |
| run: | | |
| if [[ -n "$runtime" && "$runtime" != "none" ]]; then | |
| runtime="$runtime" | |
| else | |
| runtime="k8s" | |
| fi | |
| if [[ "$runtime" == "docker" ]]; then | |
| domain=${{ github.event.client_payload.stack || inputs.stack }}.${{ vars.DOMAIN }} | |
| else | |
| domain=${{ github.event.client_payload.stack || inputs.stack }}.e2e-k8s.${{ vars.DOMAIN }} | |
| fi | |
| echo "domain=$domain" >> $GITHUB_OUTPUT | |
| echo "runtime=$runtime" >> $GITHUB_OUTPUT | |
| echo "domain=$domain" | |
| echo "runtime=$runtime" | |
| cache-node-js: | |
| name: Cache Node.js dependencies | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| repository: 'opencrvs/opencrvs-farajaland' | |
| fetch-depth: 0 | |
| - name: Checkout country branch | |
| run: | | |
| git checkout ${{ github.event.client_payload.countryconfig-image-tag || inputs.countryconfig-image-tag }} | |
| - name: Set up Node.js from country .nvmrc | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: .nvmrc | |
| - name: Cache Node.js dependencies | |
| uses: actions/cache@v4 | |
| id: cache | |
| with: | |
| path: | | |
| node_modules | |
| ~/.cache/yarn/v6 | |
| ~/.cache/ms-playwright | |
| key: ${{ github.event.client_payload.countryconfig-image-tag || inputs.countryconfig-image-tag }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install Dependencies | |
| uses: nick-fields/retry@v3 | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: yarn | |
| - uses: nick-fields/retry@v3 | |
| name: Install Playwright Browsers | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: npx playwright install --with-deps | |
| deploy-docker: | |
| needs: debug | |
| if: needs.debug.outputs.runtime == 'docker' | |
| uses: ./.github/workflows/deploy.yml | |
| with: | |
| core-image-tag: ${{ github.event.client_payload.core-image-tag || github.event.inputs.core-image-tag }} | |
| countryconfig-image-tag: ${{ github.event.client_payload.countryconfig-image-tag || github.event.inputs.countryconfig-image-tag }} | |
| stack: ${{ github.event.client_payload.stack || github.event.inputs.stack }} | |
| dependencies: false | |
| e2e_branch: ${{ github.event.client_payload.branch || github.event.inputs.branch }} | |
| reset: 'true' | |
| secrets: inherit | |
| deploy-k8s: | |
| if: needs.debug.outputs.runtime == 'k8s' | |
| needs: debug | |
| uses: ./.github/workflows/k8s-deploy.yml | |
| with: | |
| core-image-tag: ${{ github.event.client_payload.core-image-tag || inputs.core-image-tag }} | |
| countryconfig-image-tag: ${{ github.event.client_payload.countryconfig-image-tag || inputs.countryconfig-image-tag }} | |
| environment: ${{ github.event.client_payload.stack || inputs.stack }} | |
| reset: ${{ github.event.client_payload.reset || inputs.reset || true }} | |
| chart-branch: ${{ github.event.client_payload.chart-branch || inputs.chart-branch }} | |
| keep-e2e: ${{ github.event.client_payload.keep-e2e == 'true' || github.event.client_payload.keep-e2e == true || inputs.keep-e2e || false }} | |
| secrets: inherit | |
| test: | |
| needs: [debug, deploy-docker, deploy-k8s, cache-node-js] | |
| # Continue if at least one dependency succeeded (docker OR k8s ran) | |
| if: | | |
| always() && ( | |
| needs.deploy-docker.result == 'success' || | |
| needs.deploy-k8s.result == 'success' | |
| ) | |
| runs-on: ubuntu-24.04 | |
| environment: ${{ github.event.client_payload.stack || inputs.stack }} | |
| strategy: | |
| max-parallel: 15 | |
| fail-fast: false | |
| matrix: | |
| shard: | |
| [ | |
| 1, | |
| 2, | |
| 3, | |
| 4, | |
| 5, | |
| 6, | |
| 7, | |
| 8, | |
| 9, | |
| 10, | |
| 11, | |
| 12, | |
| 13, | |
| 14, | |
| 15, | |
| 16, | |
| 17, | |
| 18, | |
| 19, | |
| 20 | |
| ] | |
| name: shard-${{ matrix.shard }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| repository: 'opencrvs/opencrvs-farajaland' | |
| fetch-depth: 0 | |
| - name: Checkout country branch | |
| run: | | |
| git checkout ${{ github.event.client_payload.countryconfig-image-tag || inputs.countryconfig-image-tag }} | |
| - name: Set up Node.js from country .nvmrc | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version-file: .nvmrc | |
| - name: Cache Node.js dependencies | |
| uses: actions/cache@v4 | |
| id: cache | |
| with: | |
| path: | | |
| node_modules | |
| ~/.cache/yarn/v6 | |
| ~/.cache/ms-playwright | |
| key: ${{ github.event.client_payload.countryconfig-image-tag || inputs.countryconfig-image-tag }} | |
| restore-keys: | | |
| ${{ runner.os }}-node- | |
| - name: Install Dependencies | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| run: yarn | |
| - uses: nick-fields/retry@v3 | |
| if: steps.cache.outputs.cache-hit != 'true' | |
| with: | |
| timeout_minutes: 10 | |
| max_attempts: 3 | |
| command: npx playwright install --with-deps | |
| - name: Run Playwright Tests | |
| run: | | |
| export NODE_EXTRA_CA_CERTS=/tmp/letsencrypt-stg-root-x1.pem | |
| curl -s -o $NODE_EXTRA_CA_CERTS https://letsencrypt.org/certs/staging/letsencrypt-stg-root-x1.pem | |
| npx playwright test --shard=${{ matrix.shard }}/20 | |
| env: | |
| DOMAIN: '${{ needs.debug.outputs.domain }}' | |
| - id: ctrf_check | |
| if: always() | |
| run: | | |
| [ -d ctrf ] && \ | |
| echo "ctrf=true" >> $GITHUB_OUTPUT || \ | |
| echo "ctrf=false" >> $GITHUB_OUTPUT | |
| - name: Publish Test Report | |
| uses: ctrf-io/github-test-reporter@v1 | |
| with: | |
| report-path: './ctrf/*.json' | |
| github-report: true | |
| summary-report: true | |
| test-report: true | |
| if: always() && steps.ctrf_check.outputs.ctrf == 'true' | |
| - name: Upload report artifact | |
| uses: actions/upload-artifact@v4 | |
| if: always() | |
| with: | |
| name: playwright-report-${{ github.event.client_payload.stack || inputs.stack }}-shard-${{ matrix.shard }}-${{ github.run_id }}-${{ github.run_attempt }} | |
| path: playwright-report/ | |
| retention-days: 30 | |
| get-previous-run: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| previous_run_result: ${{ steps.set-output.outputs.result }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Get Previous Run Conclusion | |
| id: get-previous-conclusion | |
| run: | | |
| previous_conclusion=$(gh run list --limit 1 --status=completed --workflow="Deploy & run E2E" --json conclusion -q '.[0].conclusion') | |
| echo "PREVIOUS_CONCLUSION=$previous_conclusion" >> $GITHUB_ENV | |
| env: | |
| GH_TOKEN: ${{ secrets.GH_TOKEN }} | |
| - name: Set Output Based on Conclusion | |
| id: set-output | |
| run: | | |
| echo "result=$PREVIOUS_CONCLUSION" >> $GITHUB_OUTPUT | |
| cleanup-stack-docker: | |
| needs: [test, debug] | |
| runs-on: ubuntu-24.04 | |
| if: always() && needs.debug.outputs.keep_e2e == 'false' && needs.debug.outputs.runtime == 'docker' | |
| env: | |
| stack: ${{ github.event.client_payload.stack || inputs.stack }} | |
| keep_e2e: ${{ github.event.client_payload.keep-e2e || inputs.keep-e2e }} | |
| steps: | |
| - uses: actions/checkout@v5 | |
| - name: Read known hosts | |
| run: | | |
| echo "KNOWN_HOSTS<<EOF" >> $GITHUB_ENV | |
| sed -i -e '$a\' ./infrastructure-swarm/known-hosts | |
| cat ./infrastructure-swarm/known-hosts >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| - name: Install SSH Key | |
| uses: shimataro/ssh-key-action@v2 | |
| with: | |
| key: ${{ secrets.SSH_KEY }} | |
| known_hosts: ${{ env.KNOWN_HOSTS }} | |
| - name: Unset KNOWN_HOSTS variable | |
| run: | | |
| echo "KNOWN_HOSTS=" >> $GITHUB_ENV | |
| - name: Cleanup e2e stack | |
| run: | | |
| bash infrastructure-swarm/deployment/cleanup-e2e-stack.sh \ | |
| --stack=${stack} \ | |
| --ssh_host=${{ vars.SSH_HOST || secrets.SSH_HOST }} \ | |
| --ssh_port=${{ vars.SSH_PORT || secrets.SSH_PORT }} \ | |
| --ssh_user=${{ secrets.SSH_USER }} | |
| cleanup-stack-k8s: | |
| needs: [test, debug] | |
| runs-on: [self-hosted] | |
| env: | |
| ENV: ${{ github.event.client_payload.stack || inputs.stack }} | |
| if: always() && needs.debug.outputs.keep_e2e == 'false' && needs.debug.outputs.runtime == 'k8s' | |
| steps: | |
| - name: Checkout repo | |
| uses: actions/checkout@v5 | |
| - name: Update k8s-env/opencrvs/values.yaml | |
| run: | | |
| sed -i -e "s#{{STACK}}#${ENV}#g" k8s-env/opencrvs/values.yaml | |
| - name: Cleanup environment | |
| run: | | |
| kubectl delete job -n opencrvs-${ENV} --ignore-not-found=true data-cleanup | |
| helm template -f k8s-env/opencrvs/values.yaml \ | |
| --set data_cleanup.enabled=true \ | |
| --set image.tag="$CORE_IMAGE_TAG" \ | |
| --namespace opencrvs-${ENV} \ | |
| -s templates/data-cleanup-job.yaml \ | |
| oci://ghcr.io/opencrvs/opencrvs-services | kubectl apply -n opencrvs-${ENV} --wait=true -f - | |
| sleep 30; | |
| kubectl logs job/data-cleanup -f --all-containers=true -n opencrvs-${ENV} || true | |
| kubectl wait --for=condition=complete job/data-cleanup -n opencrvs-${ENV} --timeout=600s; | |
| - name: Delete helm release and namespace | |
| run: | | |
| kubectl delete namespace opencrvs-${ENV} |