From c5438177121fc0485d3edc31fcd4294d84733463 Mon Sep 17 00:00:00 2001 From: Eric Ribeiro Date: Thu, 14 Dec 2023 10:55:15 -0800 Subject: [PATCH] ci: migrate to Orb Tools 12 (#203) --- .circleci/config.yml | 48 ++---- .circleci/test-deploy.yml | 165 +++++---------------- src/scripts/install-nvm.sh | 3 + src/scripts/install-yarn.sh | 2 + src/scripts/packages/determine-lockfile.sh | 10 +- src/scripts/packages/find-package.sh | 2 + src/scripts/packages/npm-install.sh | 2 + src/scripts/packages/yarn-berry-install.sh | 2 + src/scripts/packages/yarn-v1-install.sh | 2 + src/scripts/run-commands-with.sh | 2 + 10 files changed, 72 insertions(+), 166 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index b09da2d..adbc14f 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,45 +1,27 @@ version: 2.1 setup: true orbs: - orb-tools: circleci/orb-tools@11.5 - shellcheck: circleci/shellcheck@3.1 - + orb-tools: circleci/orb-tools@12.0 + shellcheck: circleci/shellcheck@3.2 +filters: &filters + tags: + only: /.*/ workflows: lint-pack: jobs: - orb-tools/lint: - filters: - tags: - only: /.*/ + filters: *filters - orb-tools/pack: - filters: - tags: - only: /.*/ + filters: *filters - orb-tools/review: - filters: - tags: - only: /.*/ + exclude: RC010 + filters: *filters - shellcheck/check: - exclude: SC2148,SC2038,SC2086,SC2002,SC2016 - filters: - tags: - only: /.*/ - - orb-tools/publish: - orb-name: circleci/node - vcs-type: << pipeline.project.type >> - requires: - [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check] - # Use a context to hold your publishing token. - github-token: GHI_TOKEN - context: orb-publisher - filters: - tags: - only: /.*/ + filters: *filters # Triggers the next workflow in the Orb Development Kit. - orb-tools/continue: - pipeline-number: << pipeline.number >> - vcs-type: << pipeline.project.type >> - requires: [orb-tools/publish] - filters: - tags: - only: /.*/ + orb_name: node + pipeline_number: << pipeline.number >> + vcs_type: << pipeline.project.type >> + requires: [orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check] + filters: *filters diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index a598dad..5bb22c9 100644 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -1,31 +1,24 @@ version: 2.1 orbs: - node: circleci/node@dev:<> - orb-tools: circleci/orb-tools@11.5 - jq: circleci/jq@2.2.0 -commands: - check-uploaded-test-results: - parameters: - job-name: - type: string - expected-tests: - type: integer - steps: - - run: - name: check for << parameters.job-name >> test results - command: | - export TEST_JOB_NUMBER=$(jq '.items[] | select(.name == "<< parameters.job-name >>") | .job_number' workflow.json) - curl --request GET \ - --url https://circleci.com/api/v2/project/gh/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME/$TEST_JOB_NUMBER/tests \ - --header 'authorization: Basic $CIRCLE_TOKEN' \ - | jq '.items | length | if . != << parameters.expected-tests >> then halt_error else . end' + node: {} + orb-tools: circleci/orb-tools@12.0 + jq: circleci/jq@3.0 +filters: &filters + tags: + only: /.*/ +release-filters: &release-filters + branches: + ignore: /.*/ + tags: + only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ + executors: linux: docker: - image: cimg/base:stable macos: macos: - xcode: 13.2.0 + xcode: 15.1.0 machine: machine: image: ubuntu-2004:202111-01 @@ -150,99 +143,46 @@ jobs: app-dir: "~/project/sample" - run: cd ~/project/sample && yarn test - check-test-results-uploaded: - executor: - name: node/default - steps: - - jq/install - - run: - name: fetch workflow - command: | - curl --request GET \ - --url https://circleci.com/api/v2/workflow/$CIRCLE_WORKFLOW_ID/job \ - --header 'authorization: Basic $CIRCLE_TOKEN' > workflow.json - - check-uploaded-test-results: - job-name: node-npm-jest-test-job - expected-tests: 1 - - check-uploaded-test-results: - job-name: node-yarn-jest-test-job - expected-tests: 1 - - check-uploaded-test-results: - job-name: node-test-results-file-job - expected-tests: 1 - - check-uploaded-test-results: - job-name: node-npm-mocha-test-job - expected-tests: 1 - - check-uploaded-test-results: - job-name: node-yarn-mocha-test-job - expected-tests: 1 - workflows: test-deploy: jobs: - - orb-tools/lint: - filters: - tags: - only: /.*/ - - orb-tools/pack: - filters: - tags: - only: /.*/ - - orb-tools/review: - filters: - tags: - only: /.*/ - integration-test-install-specified-version: - filters: - tags: - only: /.*/ + filters: *filters matrix: parameters: os: [linux, macos, machine] - integration-test-install-latest: - filters: - tags: - only: /.*/ + filters: *filters matrix: parameters: os: [linux, macos, machine] - integration-test-install-lts: - filters: - tags: - only: /.*/ + filters: *filters matrix: parameters: os: [linux, macos, machine] - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-npm-jest-test-job app-dir: "~/project/sample" cache-version: v4 test-results-for: jest - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-yarn-jest-test-job app-dir: "~/project/sample" cache-version: v4 test-results-for: jest pkg-manager: yarn - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-npm-mocha-test-job app-dir: "~/project/sample" cache-version: v4 test-results-for: mocha run-command: testmocha - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-yarn-mocha-test-job app-dir: "~/project/sample" cache-version: v4 @@ -250,9 +190,7 @@ workflows: pkg-manager: yarn run-command: testmocha - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-yarn-mocha-with-test-result-path-job app-dir: "~/project/sample" cache-version: v4 @@ -261,83 +199,52 @@ workflows: run-command: testmocha test-results-path: sample/test-results.xml - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-test-results-file-job app-dir: "~/project/sample" cache-version: v4 test-results-path: sample/other-junit.xml - node/test: - filters: - tags: - only: /.*/ + filters: *filters name: node-test-no-junit app-dir: "~/project/sample" cache-version: v4 - - check-test-results-uploaded: - filters: - tags: - only: /.*/ - requires: - - node-npm-jest-test-job - - node-yarn-jest-test-job - - node-npm-mocha-test-job - - node-yarn-mocha-test-job - - node-test-results-file-job - node/run: - filters: - tags: - only: /.*/ + filters: *filters name: node-run-npm-job app-dir: "~/project/sample" cache-version: v4 npm-run: build - node/run: - filters: - tags: - only: /.*/ + filters: *filters name: node-run-yarn-job app-dir: "~/project/sample" cache-version: v5 pkg-manager: yarn yarn-run: build - integration-test-override-ci: - filters: - tags: - only: /.*/ + filters: *filters - integration-test-override-ci-windows: - filters: - tags: - only: /.*/ + filters: *filters - integration-test-yarn: - filters: - tags: - only: /.*/ + filters: *filters - integration-test-yarn-berry: - filters: - tags: - only: /.*/ + filters: *filters + - orb-tools/pack: + filters: *release-filters - orb-tools/publish: - orb-name: circleci/node - vcs-type: << pipeline.project.type >> - pub-type: production + orb_name: circleci/node + vcs_type: << pipeline.project.type >> + pub_type: production requires: - - orb-tools/lint - - orb-tools/review - orb-tools/pack - integration-test-install-specified-version - integration-test-install-latest - integration-test-install-lts - - check-test-results-uploaded - node-yarn-mocha-with-test-result-path-job - node-test-results-file-job - node-run-npm-job - node-run-yarn-job - github-token: GHI_TOKEN + github_token: GHI_TOKEN context: orb-publisher - filters: - branches: - ignore: /.*/ - tags: - only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ + filters: *release-filters diff --git a/src/scripts/install-nvm.sh b/src/scripts/install-nvm.sh index 78b01ee..8c259cf 100644 --- a/src/scripts/install-nvm.sh +++ b/src/scripts/install-nvm.sh @@ -1,3 +1,6 @@ +#!/usr/bin/env bash +# shellcheck disable=SC2016 + # Only install nvm if it's not already installed if command -v nvm &> /dev/null; then echo "nvm is already installed. Skipping nvm install."; diff --git a/src/scripts/install-yarn.sh b/src/scripts/install-yarn.sh index e38a381..0b35d00 100644 --- a/src/scripts/install-yarn.sh +++ b/src/scripts/install-yarn.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi # FUNCTIONS diff --git a/src/scripts/packages/determine-lockfile.sh b/src/scripts/packages/determine-lockfile.sh index 9ab65c5..1534215 100644 --- a/src/scripts/packages/determine-lockfile.sh +++ b/src/scripts/packages/determine-lockfile.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + TARGET_DIR="/tmp" if [ -n "$HOMEDRIVE" ]; then TARGET_DIR="$HOMEDRIVE\\tmp" @@ -6,13 +8,13 @@ fi # Link corresponding lock file to a temporary file used by cache commands if [ -f "package-lock.json" ]; then echo "Found package-lock.json file, assuming lockfile" - cp package-lock.json $TARGET_DIR/node-project-lockfile + cp package-lock.json "$TARGET_DIR"/node-project-lockfile elif [ -f "npm-shrinkwrap.json" ]; then echo "Found npm-shrinkwrap.json file, assuming lockfile" - cp npm-shrinkwrap.json $TARGET_DIR/node-project-lockfile + cp npm-shrinkwrap.json "$TARGET_DIR"/node-project-lockfile elif [ -f "yarn.lock" ]; then echo "Found yarn.lock file, assuming lockfile" - cp yarn.lock $TARGET_DIR/node-project-lockfile + cp yarn.lock "$TARGET_DIR"/node-project-lockfile fi -cp package.json $TARGET_DIR/node-project-package.json +cp package.json "$TARGET_DIR"/node-project-package.json diff --git a/src/scripts/packages/find-package.sh b/src/scripts/packages/find-package.sh index 90b0c50..ace71ae 100644 --- a/src/scripts/packages/find-package.sh +++ b/src/scripts/packages/find-package.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Fail if package.json does not exist in working directory if [ ! -f "package.json" ]; then diff --git a/src/scripts/packages/npm-install.sh b/src/scripts/packages/npm-install.sh index 0ca3119..87a6100 100644 --- a/src/scripts/packages/npm-install.sh +++ b/src/scripts/packages/npm-install.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Configure npm cache path if provided if [[ -n "$PARAM_CACHE_PATH" ]]; then npm config set cache "$PARAM_CACHE_PATH" diff --git a/src/scripts/packages/yarn-berry-install.sh b/src/scripts/packages/yarn-berry-install.sh index 528057d..a28398b 100644 --- a/src/scripts/packages/yarn-berry-install.sh +++ b/src/scripts/packages/yarn-berry-install.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Run override ci command if provided, otherwise run default yarn install # See: https://yarnpkg.com/configuration/yarnrc/#cacheFolder if [[ -n "$PARAM_CACHE_PATH" ]]; then diff --git a/src/scripts/packages/yarn-v1-install.sh b/src/scripts/packages/yarn-v1-install.sh index e46d947..bc2d98f 100644 --- a/src/scripts/packages/yarn-v1-install.sh +++ b/src/scripts/packages/yarn-v1-install.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # Run override ci command if provided, otherwise run default yarn install if [[ -n "$PARAM_OVERRIDE_COMMAND" ]]; then echo "Running override package installation command:" diff --git a/src/scripts/run-commands-with.sh b/src/scripts/run-commands-with.sh index 280b2c1..d520102 100644 --- a/src/scripts/run-commands-with.sh +++ b/src/scripts/run-commands-with.sh @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + if [[ "$ORB_PARAM_PKG_MANAGER" == "npm" ]]; then npm run "$ORB_PARAM_NPM_RUN" else