Skip to content

Commit

Permalink
Merge pull request #245 from CircleCI-Public/issue/132
Browse files Browse the repository at this point in the history
feat: conditional steps are now reviewed by RC008, RC009
  • Loading branch information
david-montano-circleci authored Dec 13, 2024
2 parents 3b18f4e + bbba88c commit 4cd440a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 39 deletions.
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ orbs:
# For the orb-tools-orb it must call itself within the first workflow,
# meaning this dev version will need to be published every 90 days.
# No other orbs will need to import themselves here.
orb-tools-alpha: circleci/orb-tools@12.1.0
shellcheck: circleci/shellcheck@3.1
orb-tools-alpha: circleci/orb-tools@12.2.0
shellcheck: circleci/shellcheck@3.2.0

filters: &filters
tags:
Expand Down
2 changes: 1 addition & 1 deletion src/@orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ display:

orbs:
cli: circleci/[email protected]
bats: circleci/bats@1.0.0
bats: circleci/bats@1.1.0
74 changes: 40 additions & 34 deletions src/scripts/review.bats
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,14 @@ setup() {
fi
ERROR_COUNT=0
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 | select(. != null)] | length' "$i")
j=0
while [ "$j" -lt "$ORB_COMPONENT_STEPS_COUNT" ]; do
ORB_COMPONENT_STEP=$(yq "[.steps.[] | .run | select(. != null)][$j]" "$i")
ORB_COMPONENT_STEP_TYPE=$(echo "$ORB_COMPONENT_STEP" | yq -o=json '.' | jq 'type')
ORB_COMPONENT_LINE_NUMBER=$(yq "[.steps.[] | .run | select(. != null)][$j] | line" "$i")
ORB_COMPONENT_STEP_NAME=$(yq "[.steps.[] | .run | select(. != null)][$j] | .name" "$i")
if [[ "$ORB_COMPONENT_STEP_TYPE" == '"string"' ]]; then
ORB_COMPONENT_STEPS_COUNT=$(yq -o json '.' "$i" | jq '[. | paths ] | map(select(last=="run")) | length')
RUN_ENTRIES=$(yq -o json '.' "$i" | jq -r '[paths] | map(select(last == "run") | join(".")) | .[]')

for ENTRY in $(echo "$RUN_ENTRIES"); do
ORB_COMPONENT_STEP=$(yq ".$ENTRY" "$i")
ORB_COMPONENT_STEP_TYPE=$(echo "$ORB_COMPONENT_STEP" | yq 'type')
ORB_COMPONENT_LINE_NUMBER=$(yq ".${ENTRY} | line" "$i")
if [[ "$ORB_COMPONENT_STEP_TYPE" == '!!str' ]]; then
echo "File: \"${i}\""
echo "Line number: ${ORB_COMPONENT_LINE_NUMBER}"
echo "It appears this 'run' step is using 'string' formatting."
Expand All @@ -122,15 +122,18 @@ setup() {
echo "$ORB_COMPONENT_STEP"
echo ---
ERROR_COUNT=$((ERROR_COUNT + 1))
elif [[ "$ORB_COMPONENT_STEP_NAME" == null || "$ORB_COMPONENT_STEP_NAME" == '""' ]]; then
echo "File: \"${i}\""
echo "Line number: ${ORB_COMPONENT_LINE_NUMBER}"
echo ---
yq "[.steps.[] | .run | select(. != null)][$j]" "$i"
echo ---
ERROR_COUNT=$((ERROR_COUNT + 1))
else
ORB_COMPONENT_STEP_NAME=$(echo "${ORB_COMPONENT_STEP}" | yq '.name')
ORB_COMPONENT_LINE_NUMBER=$(yq ".${ENTRY}.command | line" "$i")
if [[ "$ORB_COMPONENT_STEP_NAME" == null || "$ORB_COMPONENT_STEP_NAME" == '""' ]]; then
echo "File: \"${i}\""
echo "Line number: ${ORB_COMPONENT_LINE_NUMBER}"
echo ---
echo "$ORB_COMPONENT_STEP"
echo ---
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
fi
j=$((j + 1))
done
done
if [[ "$ERROR_COUNT" -gt 0 ]]; then
Expand All @@ -149,14 +152,14 @@ setup() {
fi
ERROR_COUNT=0
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 | select(. != null)] | length' "$i")
j=0
while [ "$j" -lt "$ORB_COMPONENT_STEPS_COUNT" ]; do
ORB_COMPONENT_STEP=$(yq "[.steps.[] | .run | select(. != null)][$j]" "$i")
ORB_COMPONENT_STEP_TYPE=$(echo "$ORB_COMPONENT_STEP" | yq -o=json '.' | jq 'type')
ORB_COMPONENT_LINE_NUMBER=$(yq "[.steps.[] | .run | select(. != null)][$j] | line" "$i")
ORB_COMPONENT_STEP_COMMAND=$(yq "[.steps.[] | .run | select(. != null)][$j] | .command" "$i")
if [[ "$ORB_COMPONENT_STEP_TYPE" == '"string"' ]]; then
ORB_COMPONENT_STEPS_COUNT=$(yq -o json '.' "$i" | jq '[. | paths ] | map(select(last=="run")) | length')
RUN_ENTRIES=$(yq -o json '.' "$i" | jq -r '[paths] | map(select(last == "run") | join(".")) | .[]')

for ENTRY in $(echo "$RUN_ENTRIES"); do
ORB_COMPONENT_STEP=$(yq ".$ENTRY" "$i")
ORB_COMPONENT_STEP_TYPE=$(echo "$ORB_COMPONENT_STEP" | yq 'type')
ORB_COMPONENT_LINE_NUMBER=$(yq ".${ENTRY} | line" "$i")
if [[ "$ORB_COMPONENT_STEP_TYPE" == '!!str' ]]; then
echo "File: \"${i}\""
echo "Line number: ${ORB_COMPONENT_LINE_NUMBER}"
echo "It appears this 'run' step is using 'string' formatting."
Expand All @@ -165,18 +168,21 @@ setup() {
echo "$ORB_COMPONENT_STEP"
echo ---
ERROR_COUNT=$((ERROR_COUNT + 1))
elif [[ "${#ORB_COMPONENT_STEP_COMMAND}" -gt "${ORB_VAL_MAX_COMMAND_LENGTH}" ]]; then
if [[ ! "$ORB_COMPONENT_STEP_COMMAND" =~ \<\<include\(* ]]; then
echo "File: \"${i}\""
echo "Line number: ${ORB_COMPONENT_LINE_NUMBER}"
echo "This command appears longer than ${ORB_VAL_MAX_COMMAND_LENGTH} characters. Consider using the 'include' syntax."
echo ---
echo "$ORB_COMPONENT_STEP_COMMAND"
echo ---
ERROR_COUNT=$((ERROR_COUNT + 1))
else
ORB_COMPONENT_STEP_COMMAND=$(echo "${ORB_COMPONENT_STEP}" | yq '.command')
ORB_COMPONENT_LINE_NUMBER=$(yq ".${ENTRY}.command | line" "$i")
if [[ "${#ORB_COMPONENT_STEP_COMMAND}" -gt "${ORB_VAL_MAX_COMMAND_LENGTH}" ]]; then
if [[ ! "$ORB_COMPONENT_STEP_COMMAND" =~ \<\<include\(* ]]; then
echo "File: \"${i}\""
echo "Line number: ${ORB_COMPONENT_LINE_NUMBER}"
echo "This command appears longer than ${ORB_VAL_MAX_COMMAND_LENGTH} characters. Consider using the 'include' syntax."
echo ---
echo "$ORB_COMPONENT_STEP_COMMAND"
echo ---
ERROR_COUNT=$((ERROR_COUNT + 1))
fi
fi
fi
j=$((j + 1))
done
done
if [[ "$ERROR_COUNT" -gt 0 ]]; then
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/review.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ fi
if ! command -v yq >/dev/null; then
echo 'The "yq" package must be installed to execute review testing.'
echo 'Installing "yq" automatically...'
YQ_VERSION=v4.20.1
YQ_VERSION=v4.44.6
YQ_BIN=yq_linux_amd64
wget https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/${YQ_BIN}.tar.gz -O - |
tar xz && mv ${YQ_BIN} /usr/bin/yq
fi

mkdir -p /tmp/orb_dev_kit/review/
echo "$ORB_VAL_REVIEW_BATS_FILE" >review.bats
echo "$ORB_VAL_REVIEW_BATS_FILE" > review.bats
echo "Reviewing orb best practices"
echo "If required, tests can be skipped via their \"RCXXX\" code with the \"exclude\" parameter."
bats -T --pretty --report-formatter junit --output /tmp/orb_dev_kit/review ./review.bats

0 comments on commit 4cd440a

Please sign in to comment.