From 7bea90e4d123823929c09b5b686ff37339796298 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20M=C5=82odzikowski?= Date: Wed, 28 Jun 2023 14:54:25 +0200 Subject: [PATCH 1/4] fix(ci): use jq to generate valid json arrays from bash (#4205) --- .github/workflows/ci-cd-trigger.yml | 55 +++++++++++++++++++---------- 1 file changed, 37 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci-cd-trigger.yml b/.github/workflows/ci-cd-trigger.yml index af4a5a30c..9ae7a075e 100644 --- a/.github/workflows/ci-cd-trigger.yml +++ b/.github/workflows/ci-cd-trigger.yml @@ -6,6 +6,8 @@ on: - release/* - develop - main + # uncomment pull_request and comment pull_request_target to test CI changes against feature branch not target branch (develop) + # pull_request: pull_request_target: types: - opened @@ -110,65 +112,82 @@ jobs: echo "Branch slug: ${branch_slug}" echo ">>>> eof debug" - projects_e2e="" + projects_array=() + preview_governance="not deployed" preview_trading="not deployed" preview_explorer="not deployed" preview_tools="not deployed" + + # parse if affected is any of three main applications, if none - use all of them if echo "$affected" | grep -q governance; then echo "Governance is affected" - projects_e2e+='"governance-e2e" ' + projects_array+=("governance") preview_governance=$(printf "https://%s.%s.vega.rocks" "governance" "$branch_slug") fi if echo "$affected" | grep -q trading; then echo "Trading is affected" - projects_e2e+='"trading-e2e" ' + projects_array+=("trading") preview_trading=$(printf "https://%s.%s.vega.rocks" "trading" "$branch_slug") fi if echo "$affected" | grep -q explorer; then echo "Explorer is affected" - projects_e2e+='"explorer-e2e" ' + projects_array+=("explorer") preview_explorer=$(printf "https://%s.%s.vega.rocks" "explorer" "$branch_slug") fi - if [[ -z "$projects_e2e" ]]; then - projects_e2e+='"governance-e2e" "trading-e2e" "explorer-e2e" ' + if [[ ${#projects_array[@]} -eq 0 ]]; then + projects_array=("governance" "trading" "explorer") preview_governance=$(printf "https://%s.%s.vega.rocks" "governance" "$branch_slug") preview_trading=$(printf "https://%s.%s.vega.rocks" "trading" "$branch_slug") preview_explorer=$(printf "https://%s.%s.vega.rocks" "explorer" "$branch_slug") fi - projects="$(echo $projects_e2e | sed 's|-e2e||g')" + + # applications parsed before this loop are applicable for running e2e-tests + projects_e2e_array=() + for project in "${projects_array[@]}"; do + projects_e2e_array+=("${project}-e2e") + done + # all applications below this loop are not applicable for running e2e-test + + # check if pull request event to deploy tools if [[ "${{ github.event_name }}" = "pull_request" ]]; then if echo "$affected" | grep -q multisig-signer; then echo "Tools are affected" - # tools are only applicable to check previews or deploy from develop to mainnet echo "Deploying tools on preview" preview_tools=$(printf "https://%s.%s.vega.rocks" "tools" "$branch_slug") - projects+=' "multisig-signer" ' + + projects_array+=("multisig-signer") fi + # those apps deploy only from develop to mainnet elif [[ "${{ github.ref }}" =~ .*develop$ ]]; then if echo "$affected" | grep -q multisig-signer; then echo "Tools are affected" - # tools are only applicable to check previews or deploy from develop to mainnet echo "Deploying tools on s3" - projects+=' "multisig-signer" ' + + projects_array+=("multisig-signer") fi if echo "$affected" | grep -q static; then echo "static is affected" echo "Deploying static on s3" - projects+=' "static" ' + + projects_array+=("static") fi if echo "$affected" | grep -q ui-toolkit; then echo "ui-toolkit is affected" echo "Deploying ui-toolkit on s3" - projects+=' "ui-toolkit" ' + + projects_array+=("ui-toolkit") fi fi - projects_e2e=${projects_e2e%?} - projects_e2e=[${projects_e2e// /,}] - projects=[${projects// /,}] - echo PROJECTS_E2E=$projects_e2e >> $GITHUB_ENV - echo PROJECTS=$projects >> $GITHUB_ENV + echo "Projects: ${projects_array[@]}" + echo "Projects E2E: ${projects_e2e_array[@]}" + projects_json=$(jq -M --compact-output --null-input '$ARGS.positional' --args -- "${projects_array[@]}") + projects_e2e_json=$(jq -M --compact-output --null-input '$ARGS.positional' --args -- "${projects_e2e_array[@]}") + + echo PROJECTS_E2E=$projects_e2e_json >> $GITHUB_ENV + echo PROJECTS=$projects_json >> $GITHUB_ENV + echo PREVIEW_GOVERNANCE=$preview_governance >> $GITHUB_ENV echo PREVIEW_TRADING=$preview_trading >> $GITHUB_ENV echo PREVIEW_EXPLORER=$preview_explorer >> $GITHUB_ENV From 6765f4d03abcbd5ea38e46a79e4b077d0fb3098f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20M=C5=82odzikowski?= Date: Wed, 28 Jun 2023 15:05:41 +0200 Subject: [PATCH 2/4] feat: add logic for testing against pull_request_target --- .github/workflows/ci-cd-trigger.yml | 4 ++-- .github/workflows/publish-dist.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-cd-trigger.yml b/.github/workflows/ci-cd-trigger.yml index 9ae7a075e..47f7b4a9b 100644 --- a/.github/workflows/ci-cd-trigger.yml +++ b/.github/workflows/ci-cd-trigger.yml @@ -49,7 +49,7 @@ jobs: lint-pr-title: needs: node-modules - if: ${{ github.event_name == 'pull_request' }} + if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} name: Verify PR title uses: ./.github/workflows/lint-pr.yml secrets: inherit @@ -225,7 +225,7 @@ jobs: needs: - publish-dist - lint-test-build - if: ${{ github.event_name == 'pull_request' }} + if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} timeout-minutes: 60 name: '(CD) comment preview links' steps: diff --git a/.github/workflows/publish-dist.yml b/.github/workflows/publish-dist.yml index 1533b5b47..68adbadc1 100644 --- a/.github/workflows/publish-dist.yml +++ b/.github/workflows/publish-dist.yml @@ -33,7 +33,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Log in to the Container registry (ghcr) - if: ${{ github.event_name == 'pull_request' }} + if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' )t' || github.event_name == 'pull_request_target' ) }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -145,7 +145,7 @@ jobs: ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local - name: Image digest - if: ${{ github.event_name == 'pull_request' }} + if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} run: echo ${{ steps.docker_build.outputs.digest }} - name: Sanity check docker image @@ -160,7 +160,7 @@ jobs: uses: docker/build-push-action@v3 continue-on-error: true id: ghcr-push - if: ${{ github.event_name == 'pull_request' }} + if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} with: context: . file: docker/node-outside-docker.Dockerfile @@ -230,7 +230,7 @@ jobs: - name: Add preview label uses: actions-ecosystem/action-add-labels@v1 - if: ${{ github.event_name == 'pull_request' }} + if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} with: labels: ${{ matrix.app }}-preview number: ${{ github.event.number }} From de0dc4af8eaaa5344176d8d94af8496f2f813b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20M=C5=82odzikowski?= Date: Wed, 28 Jun 2023 15:09:17 +0200 Subject: [PATCH 3/4] feat(ci): do not check empty arrays --- .github/workflows/ci-cd-trigger.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-cd-trigger.yml b/.github/workflows/ci-cd-trigger.yml index 47f7b4a9b..40f74dd1c 100644 --- a/.github/workflows/ci-cd-trigger.yml +++ b/.github/workflows/ci-cd-trigger.yml @@ -204,7 +204,7 @@ jobs: cypress: needs: lint-test-build name: '(CI) cypress' - if: ${{ needs.lint-test-build.outputs.projects-e2e != '[]' }} + # if: ${{ needs.lint-test-build.outputs.projects-e2e != '[]' }} uses: ./.github/workflows/cypress-run.yml secrets: inherit with: @@ -214,7 +214,7 @@ jobs: publish-dist: needs: lint-test-build name: '(CD) publish dist' - if: ${{ needs.lint-test-build.outputs.projects != '[]' }} + # if: ${{ needs.lint-test-build.outputs.projects != '[]' }} uses: ./.github/workflows/publish-dist.yml secrets: inherit with: From 019b2d7d890a38bc98e8035de809a42bc3f7cfd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=C5=82aj=20M=C5=82odzikowski?= Date: Wed, 28 Jun 2023 15:12:03 +0200 Subject: [PATCH 4/4] feat(ci): fix brakcets --- .github/workflows/ci-cd-trigger.yml | 4 ++-- .github/workflows/publish-dist.yml | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci-cd-trigger.yml b/.github/workflows/ci-cd-trigger.yml index 40f74dd1c..20c7ebf57 100644 --- a/.github/workflows/ci-cd-trigger.yml +++ b/.github/workflows/ci-cd-trigger.yml @@ -49,7 +49,7 @@ jobs: lint-pr-title: needs: node-modules - if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} name: Verify PR title uses: ./.github/workflows/lint-pr.yml secrets: inherit @@ -225,7 +225,7 @@ jobs: needs: - publish-dist - lint-test-build - if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} timeout-minutes: 60 name: '(CD) comment preview links' steps: diff --git a/.github/workflows/publish-dist.yml b/.github/workflows/publish-dist.yml index 68adbadc1..8292007a3 100644 --- a/.github/workflows/publish-dist.yml +++ b/.github/workflows/publish-dist.yml @@ -33,7 +33,7 @@ jobs: uses: docker/setup-buildx-action@v2 - name: Log in to the Container registry (ghcr) - if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' )t' || github.event_name == 'pull_request_target' ) }} + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} uses: docker/login-action@v2 with: registry: ghcr.io @@ -145,7 +145,7 @@ jobs: ghcr.io/vegaprotocol/frontend/${{ matrix.app }}:local - name: Image digest - if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} run: echo ${{ steps.docker_build.outputs.digest }} - name: Sanity check docker image @@ -160,7 +160,7 @@ jobs: uses: docker/build-push-action@v3 continue-on-error: true id: ghcr-push - if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} with: context: . file: docker/node-outside-docker.Dockerfile @@ -230,7 +230,7 @@ jobs: - name: Add preview label uses: actions-ecosystem/action-add-labels@v1 - if: ${{ ( github.event_name == 'pull_request' || github.event_name == 'pull_request_target' ) }} + if: ${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' }} with: labels: ${{ matrix.app }}-preview number: ${{ github.event.number }}