From 1e48906b4c8951666a8f971c37193410300618a2 Mon Sep 17 00:00:00 2001 From: aweng98 Date: Mon, 3 Jun 2024 18:45:37 -0400 Subject: [PATCH 1/9] Fix wait-for-job-finish script --- .circleci/config.yml | 3 +-- .circleci/wait-for-job-finish.sh | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 828cc9bbe4..a860da02e4 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -199,11 +199,10 @@ commands: working_directory: integration-tests name: Slack notification on dev branch only command: | - if [ "$CIRCLE_NODE_INDEX" -eq 0 ] && [ "$CIRCLE_BRANCH" = "dev" ]; then + if [ "$CIRCLE_BRANCH" = "alex-ci-testing" ]; then bash ../.circleci/wait-for-job-finish.sh node --require ../.pnp.cjs ./slack/notify-circleci-test-results.js fi - no_output_timeout: 30m when: always jobs: diff --git a/.circleci/wait-for-job-finish.sh b/.circleci/wait-for-job-finish.sh index 7d9531dfa5..79792eace2 100755 --- a/.circleci/wait-for-job-finish.sh +++ b/.circleci/wait-for-job-finish.sh @@ -6,26 +6,35 @@ set -o nounset # Use the error status of the first failure, rather than that of the last item in a pipeline. Also fail explicitly on any exit code. set -eo pipefail +trap 's=$?; echo -e >&2 "\nError in $0:\nat line "$LINENO": $BASH_COMMAND"; exit $s' ERR + +echo "Starting wait-for-job-finish script" + +date counter=0 +URL_BASE="https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui" # Wait up to 25 minutes for job to finish. A job can run on multiple nodes: parallelism > 1 while [ "$counter" -le 1500 ]; do - # Find number of nodes in running - job_detail=$(curl -s "https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM") - job_running_nodes_count=$(echo "$job_detail" | jq -r '[.parallel_runs[] | select(.status == "running") | select(.index != '"$CIRCLE_NODE_INDEX"')] | length') - - if [ "$job_running_nodes_count" -eq 0 ]; then - exit 0 + # Get job details + job_detail=$(curl -s "$URL_BASE/job/$CIRCLE_BUILD_NUM") + + # Wait for all nodes with status==running excluding self node + nodes=$(echo "$job_detail" | jq -r '.parallel_runs[]') + running_nodes=$(echo "$nodes" | jq -r --arg IDX "$CIRCLE_NODE_INDEX" 'select(.status=="running") | select(.index|tostring!=$IDX)') + count=$(echo "$running_nodes" | grep -c -e "running" || test $? = 1;) + if [ "$count" -eq 0 ]; then + echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Parallel running nodes have finished. Waited $counter seconds." + echo "$nodes" + exit 0 fi + echo "Waiting for parallel running nodes to finish. Sleep 10 seconds." sleep 10 counter=$(($counter + 10)) done -echo "Waited total $counter seconds" -date - # Something is wrong. Log response for error troubleshooting curl -s "https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui/job/$CIRCLE_BUILD_NUM" | jq -r '.' -echo "ERROR: Exceeded maximum waiting time 25 minutes." +echo "ERROR: Exceeded maximum wait time 25 minutes." exit 1 From 640f47dbda02299c806de816d6192d21c1ed287b Mon Sep 17 00:00:00 2001 From: aweng98 Date: Mon, 3 Jun 2024 20:00:35 -0400 Subject: [PATCH 2/9] 30 min --- .circleci/wait-for-job-finish.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.circleci/wait-for-job-finish.sh b/.circleci/wait-for-job-finish.sh index 79792eace2..1c45a24eab 100755 --- a/.circleci/wait-for-job-finish.sh +++ b/.circleci/wait-for-job-finish.sh @@ -14,8 +14,8 @@ date counter=0 URL_BASE="https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui" -# Wait up to 25 minutes for job to finish. A job can run on multiple nodes: parallelism > 1 -while [ "$counter" -le 1500 ]; do +# Wait up to 30 minutes for job to finish. A job can run on multiple nodes: parallelism > 1 +while [ "$counter" -le 1800 ]; do # Get job details job_detail=$(curl -s "$URL_BASE/job/$CIRCLE_BUILD_NUM") @@ -25,11 +25,11 @@ while [ "$counter" -le 1500 ]; do count=$(echo "$running_nodes" | grep -c -e "running" || test $? = 1;) if [ "$count" -eq 0 ]; then echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Parallel running nodes have finished. Waited $counter seconds." - echo "$nodes" + echo "$running_nodes" exit 0 fi - echo "Waiting for parallel running nodes to finish. Sleep 10 seconds." + echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Waiting for parallel running nodes to finish. Sleep 10 seconds." sleep 10 counter=$(($counter + 10)) done From b587d74a5911c512d74e1ee189466aab01318f01 Mon Sep 17 00:00:00 2001 From: aweng98 Date: Mon, 3 Jun 2024 20:44:26 -0400 Subject: [PATCH 3/9] sleep 10 sec first --- .circleci/wait-for-job-finish.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.circleci/wait-for-job-finish.sh b/.circleci/wait-for-job-finish.sh index 1c45a24eab..1d1a0a7fab 100755 --- a/.circleci/wait-for-job-finish.sh +++ b/.circleci/wait-for-job-finish.sh @@ -16,22 +16,24 @@ URL_BASE="https://circleci.com/api/v2/project/github/DataBiosphere/terra-ui" # Wait up to 30 minutes for job to finish. A job can run on multiple nodes: parallelism > 1 while [ "$counter" -le 1800 ]; do + counter=$(($counter + 10)) + sleep 10 + # Get job details job_detail=$(curl -s "$URL_BASE/job/$CIRCLE_BUILD_NUM") # Wait for all nodes with status==running excluding self node nodes=$(echo "$job_detail" | jq -r '.parallel_runs[]') running_nodes=$(echo "$nodes" | jq -r --arg IDX "$CIRCLE_NODE_INDEX" 'select(.status=="running") | select(.index|tostring!=$IDX)') - count=$(echo "$running_nodes" | grep -c -e "running" || test $? = 1;) + count=$(echo "$running_nodes" | length) + if [ "$count" -eq 0 ]; then echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Parallel running nodes have finished. Waited $counter seconds." echo "$running_nodes" exit 0 fi - echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Waiting for parallel running nodes to finish. Sleep 10 seconds." - sleep 10 - counter=$(($counter + 10)) + echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Waiting for parallel running nodes to finish." done # Something is wrong. Log response for error troubleshooting From 6316183e0411817aac62cc83cf348880b0163a6f Mon Sep 17 00:00:00 2001 From: aweng98 Date: Mon, 3 Jun 2024 21:15:48 -0400 Subject: [PATCH 4/9] sleep 10 sec first --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a860da02e4..c2933df60b 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -199,7 +199,7 @@ commands: working_directory: integration-tests name: Slack notification on dev branch only command: | - if [ "$CIRCLE_BRANCH" = "alex-ci-testing" ]; then + if [ "$CIRCLE_NODE_INDEX" -eq 0 ] && [ "$CIRCLE_BRANCH" = "alex-ci-testing" ]; then bash ../.circleci/wait-for-job-finish.sh node --require ../.pnp.cjs ./slack/notify-circleci-test-results.js fi From 47a9154f47593995efec1f6f2a2d276a2297a2d4 Mon Sep 17 00:00:00 2001 From: aweng98 Date: Mon, 3 Jun 2024 22:01:09 -0400 Subject: [PATCH 5/9] update --- .circleci/wait-for-job-finish.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/wait-for-job-finish.sh b/.circleci/wait-for-job-finish.sh index 1d1a0a7fab..ba8ea9ffc7 100755 --- a/.circleci/wait-for-job-finish.sh +++ b/.circleci/wait-for-job-finish.sh @@ -25,7 +25,7 @@ while [ "$counter" -le 1800 ]; do # Wait for all nodes with status==running excluding self node nodes=$(echo "$job_detail" | jq -r '.parallel_runs[]') running_nodes=$(echo "$nodes" | jq -r --arg IDX "$CIRCLE_NODE_INDEX" 'select(.status=="running") | select(.index|tostring!=$IDX)') - count=$(echo "$running_nodes" | length) + count=$(echo "$running_nodes" | grep -c -e "running" || test $? = 1;) if [ "$count" -eq 0 ]; then echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Parallel running nodes have finished. Waited $counter seconds." From 7508d6c991e2a4f1db2467a72468da61b33c9571 Mon Sep 17 00:00:00 2001 From: aweng98 Date: Tue, 4 Jun 2024 09:53:24 -0400 Subject: [PATCH 6/9] log --- integration-tests/slack/circleci-utils.js | 3 +++ integration-tests/slack/notify-circleci-test-results.js | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/integration-tests/slack/circleci-utils.js b/integration-tests/slack/circleci-utils.js index 94bb4d7cf3..d32c40c4a6 100644 --- a/integration-tests/slack/circleci-utils.js +++ b/integration-tests/slack/circleci-utils.js @@ -33,6 +33,8 @@ const fetchJobArtifacts = async ({ buildNum = process.env.CIRCLE_BUILD_NUM } = { * @returns {Array[string]} */ const getFailedTestNames = (aggregatedResults) => { + console.log(`aggregatedResults.testResults: ${aggregatedResults.testResults}`); + console.log('**'); return _.flow( _.filter((testResult) => testResult.numFailingTests > 0), _.map((testResult) => parse(testResult.testFilePath).name) @@ -45,6 +47,7 @@ const getFailedTestNames = (aggregatedResults) => { */ const getFailedTestNamesFromArtifacts = async () => { const urls = await fetchJobArtifacts(); + console.log(`urls: ${urls}`); return _.flatten( await Promise.all( _.map(async (url) => { diff --git a/integration-tests/slack/notify-circleci-test-results.js b/integration-tests/slack/notify-circleci-test-results.js index 446725b0e8..f03d040dd8 100644 --- a/integration-tests/slack/notify-circleci-test-results.js +++ b/integration-tests/slack/notify-circleci-test-results.js @@ -53,7 +53,8 @@ const getFailedTestsAndChannelIDs = (failedTests) => { // Post CircleCI UI test report to Slack channels const notifyCircleCITestResults = async () => { const failedTestNames = await getFailedTestNamesFromArtifacts(); - + console.log(`failedTestNames: ${failedTestNames}`); + /* if (failedTestNames.length === 0) { // Slack notification: CircleCI job succeeded const channelIDs = getAllSlackChannelsForPassedJob(); @@ -70,7 +71,7 @@ const notifyCircleCITestResults = async () => { console.log(`Notifying channel ${channelId} of ${testNames.length} test failures (${testNames.join(', ')})`); const messageBlocks = getMessageBlockTemplate(testNames); await postMessage({ channel: channelId, blocks: messageBlocks }); - }, _.toPairs(channelIDsAndNames)); + }, _.toPairs(channelIDsAndNames)); */ }; (async () => { From 7ac9386ed8abc906bbfeafcd3bbd7499aa6dc66f Mon Sep 17 00:00:00 2001 From: aweng98 Date: Tue, 4 Jun 2024 09:59:47 -0400 Subject: [PATCH 7/9] log --- integration-tests/slack/notify-circleci-test-results.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/integration-tests/slack/notify-circleci-test-results.js b/integration-tests/slack/notify-circleci-test-results.js index f03d040dd8..e4749fd206 100644 --- a/integration-tests/slack/notify-circleci-test-results.js +++ b/integration-tests/slack/notify-circleci-test-results.js @@ -1,6 +1,8 @@ const _ = require('lodash/fp'); const { getFailedTestNamesFromArtifacts } = require('./circleci-utils'); +// eslint-disable-next-line @typescript-eslint/no-unused-vars const { getMessageBlockTemplate } = require('./message-templates'); +// eslint-disable-next-line @typescript-eslint/no-unused-vars const { postMessage } = require('./post-message'); const testsInfo = require('./slack-notify-channels.json'); @@ -8,6 +10,7 @@ const testsInfo = require('./slack-notify-channels.json'); * Get array of Slack channel IDs for succeeded job notification * @returns {Array[string]} */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars const getAllSlackChannelsForPassedJob = () => { return _.map('id', testsInfo.pass); }; @@ -31,6 +34,7 @@ const getAllSlackChannelsForFailedJob = () => { * @param {Array[string]} failedTests * @returns {Map} A map object where key is channel_id, value is test_names array */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars const getFailedTestsAndChannelIDs = (failedTests) => { const allChannelsAndTests = getAllSlackChannelsForFailedJob(); From 3ecb604b471bcacbada66b3c1188ce6aa810a1d6 Mon Sep 17 00:00:00 2001 From: aweng98 Date: Tue, 4 Jun 2024 10:57:04 -0400 Subject: [PATCH 8/9] log --- .circleci/config.yml | 15 --------------- integration-tests/slack/circleci-utils.js | 5 ++++- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c2933df60b..5cb8ce2352 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -226,18 +226,7 @@ jobs: fi - run: yarn run build - run: yarn eslint --max-warnings=0 . - - run: yarn workspaces foreach --exclude terra-integration-tests run test --coverage --maxWorkers=2 --passWithNoTests - - store_artifacts: - path: test-report/index.html - - run: yarn check-types - - save_cache: - key: deps-{{ .Branch }}-{{ checksum ".pnp.cjs" }} - paths: - - .yarn/unplugged - - node_modules/.cache - run: tar -czf build.tgz .gcloudignore app.yaml build config - - store_artifacts: - path: build.tgz - persist_to_workspace: root: . paths: @@ -294,10 +283,6 @@ workflows: <<: *filter-pr-branch requires: - build - - deploy-pr: - <<: *filter-pr-branch - requires: - - build - deploy-dev: <<: *filter-dev-branch requires: diff --git a/integration-tests/slack/circleci-utils.js b/integration-tests/slack/circleci-utils.js index d32c40c4a6..051871479b 100644 --- a/integration-tests/slack/circleci-utils.js +++ b/integration-tests/slack/circleci-utils.js @@ -19,7 +19,10 @@ const fetchJobArtifacts = async ({ buildNum = process.env.CIRCLE_BUILD_NUM } = { // Because terra-ui is a public repository on GitHub, API token is not required. See: https://circleci.com/docs/oss#security const response = await fetch(`${apiUrlRoot}/${buildNum}/artifacts`); const { items } = await response.json(); - const testSummaryArtifacts = _.filter(_.flow(_.get('path'), _.includes('tests-summary')), items); + const itm = JSON.stringify(items, null, 2); + console.log(`items: ${itm}`); + const testSummaryArtifacts = _.filter(_.flow(_.get('path'), _.includes('tests-summary-')), items); + console.log(`testSummaryArtifacts: ${testSummaryArtifacts}`); return _.map('url', testSummaryArtifacts); } catch (e) { console.error(`** ERROR: Encountered error when getting CircleCI JOB_BUILD_NUM: ${buildNum} artifacts.`, e); From 58e3c431241eb8b3116f920c048cd72481735475 Mon Sep 17 00:00:00 2001 From: aweng98 Date: Tue, 4 Jun 2024 11:42:52 -0400 Subject: [PATCH 9/9] log --- .circleci/wait-for-job-finish.sh | 5 ++++- integration-tests/slack/circleci-utils.js | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.circleci/wait-for-job-finish.sh b/.circleci/wait-for-job-finish.sh index ba8ea9ffc7..a60a3a4d89 100755 --- a/.circleci/wait-for-job-finish.sh +++ b/.circleci/wait-for-job-finish.sh @@ -29,7 +29,10 @@ while [ "$counter" -le 1800 ]; do if [ "$count" -eq 0 ]; then echo "Checking from NODE_INDEX #$CIRCLE_NODE_INDEX: Parallel running nodes have finished. Waited $counter seconds." - echo "$running_nodes" + echo "$nodes" + + artifacts=$(curl -s "$URL_BASE/$CIRCLE_BUILD_NUM/artifacts") + echo "$artifacts" exit 0 fi diff --git a/integration-tests/slack/circleci-utils.js b/integration-tests/slack/circleci-utils.js index 051871479b..1c8e902b99 100644 --- a/integration-tests/slack/circleci-utils.js +++ b/integration-tests/slack/circleci-utils.js @@ -18,9 +18,13 @@ const fetchJobArtifacts = async ({ buildNum = process.env.CIRCLE_BUILD_NUM } = { try { // Because terra-ui is a public repository on GitHub, API token is not required. See: https://circleci.com/docs/oss#security const response = await fetch(`${apiUrlRoot}/${buildNum}/artifacts`); + const resp = await response.json(); + console.log(`response json: ${JSON.stringify(resp, null, 2)}`); + const { items } = await response.json(); const itm = JSON.stringify(items, null, 2); console.log(`items: ${itm}`); + const testSummaryArtifacts = _.filter(_.flow(_.get('path'), _.includes('tests-summary-')), items); console.log(`testSummaryArtifacts: ${testSummaryArtifacts}`); return _.map('url', testSummaryArtifacts);