Skip to content

Commit

Permalink
feat: add source-dir to both lint and review workflows (#160)
Browse files Browse the repository at this point in the history
* feat: closes issue 159 add source-dir to both lint and review workflows for compatibility with monorepos - address PR issues / test failures

Co-authored-by: Kyle T <[email protected]>
  • Loading branch information
surecloud-meason and KyleTryon authored Aug 26, 2022
1 parent c34bc9d commit 88d47a6
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
14 changes: 10 additions & 4 deletions src/jobs/lint.yml
Original file line number Diff line number Diff line change
@@ -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: <<include(scripts/lint.sh)>>
environment:
ORB_PARAM_SOURCE_DIR: << parameters.source-dir >>
5 changes: 5 additions & 0 deletions src/jobs/review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -28,6 +32,7 @@ steps:
environment:
PARAM_RC_EXCLUDE: <<parameters.exclude>>
ORB_REVIEW_BATS_FILE: <<include(scripts/review.bats)>>
ORB_PARAM_SOURCE_DIR: << parameters.source-dir >>
command: <<include(scripts/review.sh)>>
- store_test_results:
path: /tmp/orb_dev_kit/review/
8 changes: 4 additions & 4 deletions src/scripts/lint.sh
Original file line number Diff line number Diff line change
@@ -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"
25 changes: 13 additions & 12 deletions src/scripts/review.bats
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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}"
}

@test "RC001: Include source_url in @orb.yml" {
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 ]]
Expand All @@ -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
Expand All @@ -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
}
Expand All @@ -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'."
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88d47a6

Please sign in to comment.