From 1856b8d1e64d8b7274e67ecff02570f4d3d1701c Mon Sep 17 00:00:00 2001 From: Ivan Tsai <9553914+oscar60310@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:12:49 +0800 Subject: [PATCH] ci: fix CI script on develop and main branches --- .circleci/config.yml | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 699da6aa..d360d36c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,15 +12,32 @@ executors: set_env: &set_env name: Setup Environment Variables command: | + if [ ! -z "$CIRCLE_PULL_REQUEST" ]; then + # Use the base commit of PR as the affected base. + + echo 'Fetching Base Commit from GitHub' + # Get the PR number from env for different kinds of PR + echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV + source $BASH_ENV + + # Obtain the SHA via Github API + echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV + # Set the affected args for nx affect xxx commands + echo 'export AFFECTED_ARGS="--head=HEAD --base=${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV + + elif [ "$CIRCLE_BRANCH" == "develop" ]; then + # Merge into develop branch, use main branch as the base. + + echo "Using main branch as the base" + echo 'export AFFECTED_ARGS="--head=HEAD --base=main"' >> $BASH_ENV + + else + + echo "Testing/Linting on all packages" + echo 'export AFFECTED_ARGS="--all"' >> $BASH_ENV + + fi - echo 'Fetching Base Commit from GitHub' - # Get the PR number from env for different kinds of PR - echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV - source $BASH_ENV - # Obtain the SHA via Github API - echo "export CIRCLE_PR_BASE_SHA=`curl -s https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/pulls/${CIRCLE_PR_NUMBER} | jq -r '.base.sha'`" >> $BASH_ENV - # Set the affected args for nx affect xxx commands - echo 'export AFFECTED_ARGS="--base=${CIRCLE_PR_BASE_SHA}"' >> $BASH_ENV # Set the memory size for node processes echo 'export NODE_OPTIONS="--max_old_space_size=6144"' >> $BASH_ENV source $BASH_ENV @@ -87,7 +104,7 @@ jobs: - restore_cache: <<: *yarn_cache - run: yarn nx workspace-lint - - run: yarn nx affected --target=lint --head=HEAD --maxWarnings=0 ${AFFECTED_ARGS} + - run: yarn nx affected --target=lint --maxWarnings=0 ${AFFECTED_ARGS} test: executor: node-executor @@ -100,7 +117,7 @@ jobs: - restore_cache: keys: - codecov-0.1.0_4653 - - run: yarn nx affected --target=test --head=HEAD --ci --coverage --maxWorkers=2 --coverageReporters=lcov ${AFFECTED_ARGS} + - run: yarn nx affected --target=test --ci --coverage --maxWorkers=2 --coverageReporters=lcov ${AFFECTED_ARGS} # --maxWorkers=2 is required because we'll run virtual machine with 32 cores CPU (with actually 4 CPI), jest spawns lots of workers if we don't fix the worker size. # https://support.circleci.com/hc/en-us/articles/360005442714-Your-test-tools-are-smart-and-that-s-a-problem-Learn-about-when-optimization-goes-wrong- - run: ./codecov -t ${CODECOV_TOKEN}