From 45ae5a2995ebabb72fb301687d05a03e11a04b8c Mon Sep 17 00:00:00 2001 From: Saroj <43822041+sarojsarab@users.noreply.github.com> Date: Tue, 27 Jun 2023 22:25:44 +0530 Subject: [PATCH] ci: Get the newly added files from the PR branch for ts check (#24825) ## Description - Get the newly added files from the PR branch instead of commits for ts check - CI improvements, now added cypress dashboard link with the comments in PR - CI improvements removed the steps which saves un-necessary cache #### Type of change - Workflow file changes ## Testing > #### How Has This Been Tested? - Workflow run --- .github/workflows/ci-test.yml | 47 +++++++------ .github/workflows/client-build.yml | 69 ++++++++++--------- .../workflows/integration-tests-command.yml | 33 +++++---- 3 files changed, 78 insertions(+), 71 deletions(-) diff --git a/.github/workflows/ci-test.yml b/.github/workflows/ci-test.yml index 374ea18438..871a27f05e 100644 --- a/.github/workflows/ci-test.yml +++ b/.github/workflows/ci-test.yml @@ -66,7 +66,7 @@ jobs: # In case this is second attempt try restoring status of the prior attempt from cache - name: Restore the previous run result id: cache-appsmith - uses: martijnhols/actions-cache@v3.0.2 + uses: actions/cache@v3 with: path: | ~/run_result @@ -79,7 +79,7 @@ jobs: id: run_result run: | run_result_env=$(cat ~/run_result) - echo "::set-output name=run_result::$run_result_env" + echo "run_result=$run_result_env" >> $GITHUB_OUTPUT - name: Dump steps context env: @@ -281,6 +281,7 @@ jobs: - name: Run the cypress test if: steps.run_result.outputs.run_result != 'success' && steps.run_result.outputs.run_result != 'failedtest' + id: cypress_test uses: cypress-io/github-action@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -360,6 +361,7 @@ jobs: # In case of second attempt only run failed specs - name: Run the cypress test with failed tests if: steps.run_result.outputs.run_result == 'failedtest' + id: cypress_test_failedtest uses: cypress-io/github-action@v5 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -436,7 +438,7 @@ jobs: - name: Set fail if there are test failures if: failure() run: | - echo "::set-output name=run_result::failedtest" + echo "run_result=failedtest" >> $GITHUB_OUTPUT echo "failedtest" > ~/run_result # Create a directory ~/failed_spec_ci and add a dummy file @@ -471,33 +473,30 @@ jobs: # Force store previous run result to cache - name: Store the previous run result if: failure() - uses: martijnhols/actions-cache/save@v3 + uses: actions/cache/save@v3 with: path: | ~/run_result key: ${{ github.run_id }}-${{ github.job }}-${{ matrix.job }} - restore-keys: | - ${{ github.run_id }}-${{ github.job }}-${{ matrix.job }} + + - name: get cypress url dashboard url + id: dashboard_url + if: always() + run: | + if [[ "${{steps.run_result.outputs.run_result }}" != "success" && "${{steps.run_result.outputs.run_result }}" != "failedtest" ]]; then + echo "cypress_url=${{ steps.cypress_test.outputs.resultsUrl }}" >> ~/cypress_url + elif [[ "${{steps.run_result.outputs.run_result }}" == "failedtest" ]]; then + echo "cypress_url=${{ steps.cypress_test_failedtest.outputs.resultsUrl }}" >> ~/cypress_url + fi - # Force store previous failed test list to cache - - name: Store the previous failed test result - if: failure() - uses: martijnhols/actions-cache/save@v3 + # Force store previous run result to cache + - name: Store the previous run result + if: success() + uses: actions/cache/save@v3 with: path: | - ~/failed_spec_ci - key: ${{ github.run_id }}-${{ github.job }}-${{ matrix.job }} - restore-keys: | - ${{ github.run_id }}-${{ github.job }}-${{ matrix.job }} - - - name: Restore the previous bundle - uses: actions/cache@v3 - with: - path: | - app/client/cypress/snapshots/ - key: ${{ github.run_id }}-${{ github.job }}-${{ matrix.job }} - restore-keys: | - ${{ github.run_id }}-${{ github.job }}-${{ matrix.job }} + ~/cypress_url + key: ${{ github.run_id }}-dashboard-url-${{ github.run_number }} # Upload the log artifact so that it can be used by the test & deploy job in the workflow - name: Upload server logs bundle on failure @@ -510,5 +509,5 @@ jobs: # Set status = success - name: Save the status of the run run: | - echo "::set-output name=run_result::success" + echo "run_result=success" >> $GITHUB_OUTPUT echo "success" > ~/run_result diff --git a/.github/workflows/client-build.yml b/.github/workflows/client-build.yml index 6ee4c204dc..f8cc5226d4 100644 --- a/.github/workflows/client-build.yml +++ b/.github/workflows/client-build.yml @@ -66,42 +66,43 @@ jobs: with: fetch-depth: 0 - # # get all the files changes in the cypress/e2e folder - # - name: Get changed files in the cypress/e2e folder - # if: inputs.check-test-files == 'true' - # id: files - # uses: tj-actions/changed-files@v36 - # with: - # base_sha: ${{ github.event.client_payload.pull_request.base.sha }} - # files: app/client/cypress/e2e + # get all the files changes in the cypress/e2e folder + - name: Get added files in cypress/e2e folder + if: inputs.pr != 0 + id: files + uses: umani/changed-files@v4.0.0 + with: + repo-token: ${{ secrets.APPSMITH_CI_TEST_PAT }} + pattern: 'app/client/cypress/e2e/.*' + pr-number: ${{ inputs.pr }} - # # Check all the newly added files are in ts - # - name: Check the newly added files are written in ts - # if: inputs.check-test-files == 'true' - # id: check_files - # run: | - # files=(${{steps.files.outputs.added_files}}) - # non_ts_files=() - # for file in "${files[@]}"; do - # if [[ $file != *.ts ]]; then - # non_ts_files+=("
  • $file") - # fi - # done - # echo "non_ts_files=${non_ts_files[@]}" >> $GITHUB_OUTPUT - # echo "non_ts_files_count=${#non_ts_files[@]}" >> $GITHUB_OUTPUT + # Check all the newly added files are in ts + - name: Check the newly added files are written in ts + if: inputs.check-test-files == 'true' && inputs.pr != 0 + id: check_files + run: | + files=(${{steps.files.outputs.files_created}}) + non_ts_files=() + for file in "${files[@]}"; do + if [[ $file != *.ts ]]; then + non_ts_files+=("
  • $file") + fi + done + echo "non_ts_files=${non_ts_files[@]}" >> $GITHUB_OUTPUT + echo "non_ts_files_count=${#non_ts_files[@]}" >> $GITHUB_OUTPUT - # # Comment in PR if test files are not written in ts and fail the workflow - # - name: Comment in PR if test files are not written in ts - # if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' - # uses: peter-evans/create-or-update-comment@v1 - # with: - # issue-number: ${{ github.event.client_payload.pull_request.number }} - # body: | - # Below new test files are written in js 🔴 - # Expected format ts. Please fix and retrigger ok-to-test: - #
      ${{ steps.check_files.outputs.non_ts_files }}
    - # - if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' - # run: exit 1 + # Comment in PR if test files are not written in ts and fail the workflow + - name: Comment in PR if test files are not written in ts + if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' && inputs.pr != 0 + uses: peter-evans/create-or-update-comment@v1 + with: + issue-number: ${{ inputs.pr }} + body: | + Below new test files are written in js 🔴 + Expected format ts. Please fix and retrigger ok-to-test: +
      ${{ steps.check_files.outputs.non_ts_files }}
    + - if: steps.check_files.outputs.non_ts_files_count != 0 && inputs.check-test-files == 'true' && inputs.pr != 0 + run: exit 1 # Create a run record exactly at the time of merge to release to # ensure we compare run details with code at this point diff --git a/.github/workflows/integration-tests-command.yml b/.github/workflows/integration-tests-command.yml index bce790d4c8..26c2064ab7 100644 --- a/.github/workflows/integration-tests-command.yml +++ b/.github/workflows/integration-tests-command.yml @@ -140,6 +140,23 @@ jobs: run: | rm -f ~/failed_spec_ci rm -f ~/combined_failed_spec_ci + + # Force store previous cypress dashboard url from cache + - name: Store the previous cypress dashboard url + if: success() + uses: actions/cache@v3 + with: + path: | + ~/cypress_url + key: ${{ github.run_id }}-dashboard-url-${{ github.run_number }} + restore-keys: | + ${{ github.run_id }}-dashboard-url + + - name: Print cypress dashboard url + id: dashboard_url + run: | + cypress_url = $(cat ~/cypress_url) + echo "dashboard_url=$cypress_url" >> $GITHUB_OUTPUT # Download failed_spec list for all jobs - uses: actions/download-artifact@v3 @@ -156,17 +173,6 @@ jobs: echo "Debugging: failed specs in ~/failed_spec_ci/failed_spec_ci*" cat ~/failed_spec_ci/failed_spec_ci* cat ~/failed_spec_ci/failed_spec_ci* | sort -u >> ~/combined_failed_spec_ci - - # Force save the CI failed spec list into a cache - - name: Store the combined run result for CI - if: needs.ci-test.result != 'success' - uses: martijnhols/actions-cache/save@v3 - with: - path: | - ~/combined_failed_spec_ci - key: ${{ github.run_id }}-"ci-test-result" - restore-keys: | - ${{ github.run_id }}-${{ github.job }} # Upload combined failed CI spec list to a file # This is done for debugging. @@ -201,6 +207,7 @@ jobs: body: | Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>. Commit: `${{ github.event.client_payload.slash_command.args.named.sha }}`. + Cypress dashboard: ` Click here! ` The following are new failures, please fix them before merging the PR: ${{env.new_failed_spec_env}} To know the list of identified flaky tests - Refer here @@ -212,8 +219,8 @@ jobs: body: | Workflow run: <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}>. Commit: `${{ github.event.client_payload.slash_command.args.named.sha }}`. - All cypress tests have passed 🎉 - + Cypress dashboard url: `Click here!` + All cypress tests have passed 🎉🎉🎉 # Update check run called "ci-test-result" - name: Mark ci-test-result job as complete