Skip to content

Commit

Permalink
ci: migrate to Orb Tools 12 (#203)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricRibeiro authored Dec 14, 2023
1 parent ab05d0e commit c543817
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 166 deletions.
48 changes: 15 additions & 33 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,45 +1,27 @@
version: 2.1
setup: true
orbs:
orb-tools: circleci/[email protected]
shellcheck: circleci/[email protected]

orb-tools: circleci/[email protected]
shellcheck: circleci/[email protected]
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
165 changes: 36 additions & 129 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
version: 2.1
orbs:
node: circleci/node@dev:<<pipeline.git.revision>>
orb-tools: circleci/[email protected]
jq: circleci/[email protected]
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/[email protected]
jq: circleci/[email protected]
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
Expand Down Expand Up @@ -150,109 +143,54 @@ 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
test-results-for: mocha
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
Expand All @@ -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
3 changes: 3 additions & 0 deletions src/scripts/install-nvm.sh
Original file line number Diff line number Diff line change
@@ -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.";
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/install-yarn.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if [[ $EUID == 0 ]]; then export SUDO=""; else export SUDO="sudo"; fi

# FUNCTIONS
Expand Down
10 changes: 6 additions & 4 deletions src/scripts/packages/determine-lockfile.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

TARGET_DIR="/tmp"
if [ -n "$HOMEDRIVE" ]; then
TARGET_DIR="$HOMEDRIVE\\tmp"
Expand All @@ -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
2 changes: 2 additions & 0 deletions src/scripts/packages/find-package.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

# Fail if package.json does not exist in working directory

if [ ! -f "package.json" ]; then
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/packages/npm-install.sh
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/packages/yarn-berry-install.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/packages/yarn-v1-install.sh
Original file line number Diff line number Diff line change
@@ -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:"
Expand Down
2 changes: 2 additions & 0 deletions src/scripts/run-commands-with.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env bash

if [[ "$ORB_PARAM_PKG_MANAGER" == "npm" ]]; then
npm run "$ORB_PARAM_NPM_RUN"
else
Expand Down

0 comments on commit c543817

Please sign in to comment.