diff --git a/src/jobs/lint.yml b/src/jobs/lint.yml index 2a753852..384568a8 100644 --- a/src/jobs/lint.yml +++ b/src/jobs/lint.yml @@ -1,19 +1,25 @@ description: | Lint all YAML files in the project. A ".yamllint" file will be generated for you automatically by the Orb Development Kit. -docker: - - image: cimg/python:3.10.5 -resource_class: << parameters.resource_class >> - parameters: + source-dir: + description: Path to the orb source. Path must be absolute or relative to the working directory. + type: string + default: ./src/ resource_class: description: Configure the executor resource class type: enum enum: ["small", "medium", "medium+", "large", "xlarge", "2xlarge", "2xlarge+"] default: "medium" +docker: + - image: cimg/python:3.10.5 +resource_class: << parameters.resource_class >> + steps: - checkout - run: name: Linting all YAML files command: <> + environment: + ORB_PARAM_SOURCE_DIR: << parameters.source-dir >> diff --git a/src/jobs/review.yml b/src/jobs/review.yml index bd27dca2..7fddf49d 100644 --- a/src/jobs/review.yml +++ b/src/jobs/review.yml @@ -10,6 +10,10 @@ parameters: Example: "RC001,RC002" type: string default: "" + source-dir: + description: Path to the orb source. Path must be absolute or relative to the working directory. + type: string + default: ./src/ resource_class: description: Configure the executor resource class type: enum @@ -28,6 +32,7 @@ steps: environment: PARAM_RC_EXCLUDE: <> ORB_REVIEW_BATS_FILE: <> + ORB_PARAM_SOURCE_DIR: << parameters.source-dir >> command: <> - store_test_results: path: /tmp/orb_dev_kit/review/ diff --git a/src/scripts/lint.sh b/src/scripts/lint.sh index 01e6e968..6edeed37 100644 --- a/src/scripts/lint.sh +++ b/src/scripts/lint.sh @@ -1,8 +1,8 @@ #!/bin/bash -if [ ! -d "./src" ]; then - echo "No source directory located at ./src" - echo "This orb assumes you have build your orb using the Orb Development Kit" +if [ ! -d "$ORB_PARAM_SOURCE_DIR" ]; then + echo "No source directory located at $ORB_PARAM_SOURCE_DIR" + echo "This orb assumes you have built your orb using the Orb Development Kit" echo "https://circleci.com/docs/2.0/orb-author/#orb-development-kit" fi pip install --user yamllint -yamllint ./src +yamllint "$ORB_PARAM_SOURCE_DIR" diff --git a/src/scripts/review.bats b/src/scripts/review.bats index a9a2e119..10266b57 100644 --- a/src/scripts/review.bats +++ b/src/scripts/review.bats @@ -1,5 +1,6 @@ setup() { - REVIEW_TEST_DIR="./" + ORB_DEFAULT_SRC_DIR="./src/" + ORB_SOURCE_DIR=${ORB_PARAM_SOURCE_DIR:-$ORB_DEFAULT_SRC_DIR} IFS="," read -ra SKIPPED_REVIEW_CHECKS <<<"${PARAM_RC_EXCLUDE}" } @@ -7,7 +8,7 @@ setup() { if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC001" ]]; then skip fi - result=$(yq '.display.source_url' "${REVIEW_TEST_DIR}src/@orb.yml") + result=$(yq '.display.source_url' "${ORB_SOURCE_DIR}@orb.yml") echo 'Set a value for "source_url" under the "display" key in "@orb.yml"' [[ ! $result = null ]] @@ -17,7 +18,7 @@ setup() { if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC002" ]]; then skip fi - for i in $(find "${REVIEW_TEST_DIR}src/jobs" "${REVIEW_TEST_DIR}src/examples" "${REVIEW_TEST_DIR}src/commands" "${REVIEW_TEST_DIR}src/executors" -name "*.yml" 2>/dev/null); do + for i in $(find "${ORB_SOURCE_DIR}jobs" "${ORB_SOURCE_DIR}examples" "${ORB_SOURCE_DIR}commands" "${ORB_SOURCE_DIR}executors" -name "*.yml" 2>/dev/null); do ORB_ELEMENT_DESCRIPTION=$(yq '.description' "$i") if [[ "$ORB_ELEMENT_DESCRIPTION" == null || "$ORB_ELEMENT_DESCRIPTION" == '""' ]]; then echo @@ -33,11 +34,11 @@ setup() { if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC003" ]]; then skip fi - ORB_ELEMENT_EXAMPLE_COUNT=$(find ${REVIEW_TEST_DIR}src/examples/*.yml -type f 2>/dev/null | wc -l | xargs) + ORB_ELEMENT_EXAMPLE_COUNT=$(find ${ORB_SOURCE_DIR}examples/*.yml -type f 2>/dev/null | wc -l | xargs) if [ "$ORB_ELEMENT_EXAMPLE_COUNT" -lt 1 ]; then echo echo "This orb appears to be missing a usage example." - echo "Add examples under $(${REVIEW_TEST_DIR}src/examples) to document how to use the orb for any available use cases." + echo "Add examples under $(${ORB_SOURCE_DIR}examples) to document how to use the orb for any available use cases." exit 1 fi } @@ -46,7 +47,7 @@ setup() { if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC004" ]]; then skip fi - for i in $(find "${REVIEW_TEST_DIR}/src/examples/*.yml" -type f >/dev/null 2>&1); do + for i in $(find "${ORB_SOURCE_DIR}examples/*.yml" -type f >/dev/null 2>&1); do if [[ $i =~ "example" ]]; then echo echo "Usage example file name ${i} contains the word 'example'." @@ -60,11 +61,11 @@ setup() { if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC005" ]]; then skip fi - ORB_ELEMENT_DESCRIPTION=$(yq '.description' "${REVIEW_TEST_DIR}src/@orb.yml") + ORB_ELEMENT_DESCRIPTION=$(yq '.description' "${ORB_SOURCE_DIR}@orb.yml") if [[ "${#ORB_ELEMENT_DESCRIPTION}" -lt 64 ]]; then echo echo "Orb description appears short (under 64 characters)." - echo "Update the description in ${REVIEW_TEST_DIR}src/@orb.yml to provide a detailed description of the orb." + echo "Update the description in ${ORB_SOURCE_DIR}@orb.yml to provide a detailed description of the orb." echo "Use the orb description to help users find your orb via search. Try describing what use-case this orb solves for." exit 1 fi @@ -74,7 +75,7 @@ setup() { if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC006" ]]; then skip fi - SOURCE_URL=$(yq '.display.source_url' "${REVIEW_TEST_DIR}/src/@orb.yml") + SOURCE_URL=$(yq '.display.source_url' "${ORB_SOURCE_DIR}@orb.yml") HTTP_RESPONSE=$(curl -s -L -o /dev/null -w "%{http_code}" --retry 5 --retry-delay 5 "$SOURCE_URL") if [[ "$HTTP_RESPONSE" -ne 200 ]]; then echo @@ -85,7 +86,7 @@ setup() { } @test "RC007: Home URL should be valid." { - HOME_URL=$(yq '.display.home_url' "${REVIEW_TEST_DIR}/src/@orb.yml") + HOME_URL=$(yq '.display.home_url' "${ORB_SOURCE_DIR}@orb.yml") if [[ "${SKIPPED_REVIEW_CHECKS[*]}" =~ "RC007" || "$HOME_URL" == "null" ]]; then skip fi @@ -103,7 +104,7 @@ setup() { skip fi ERROR_COUNT=0 - for i in $(find "${REVIEW_TEST_DIR}src/jobs" "${REVIEW_TEST_DIR}src/commands" -name "*.yml" 2>/dev/null); do + for i in $(find "${ORB_SOURCE_DIR}jobs" "${ORB_SOURCE_DIR}commands" -name "*.yml" 2>/dev/null); do ORB_COMPONENT_STEPS_COUNT=$(yq '[.steps.[] | .run] | length' "$i") j=0 while [ "$j" -lt "$ORB_COMPONENT_STEPS_COUNT" ]; do @@ -146,7 +147,7 @@ setup() { skip fi ERROR_COUNT=0 - for i in $(find ${REVIEW_TEST_DIR}src/jobs ${REVIEW_TEST_DIR}src/commands -name "*.yml" 2>/dev/null); do + for i in $(find ${ORB_SOURCE_DIR}jobs ${ORB_SOURCE_DIR}commands -name "*.yml" 2>/dev/null); do ORB_COMPONENT_STEPS_COUNT=$(yq '[.steps.[] | .run] | length' "$i") j=0 while [ "$j" -lt "$ORB_COMPONENT_STEPS_COUNT" ]; do