Skip to content

Commit

Permalink
Boolean self managed [semver:patch] (#117)
Browse files Browse the repository at this point in the history
Drops use of the yaml provided `environments` to set shell values.

Instead we use our own step, prior to script, that `echo "NAME=VALUE >> $BASH_ENV"` for each property.  Script will fail if they are not present (for some shell error).

Because we pass they are always true/false strings in shell for consistent compare.
  • Loading branch information
eddiewebb authored Feb 23, 2024
1 parent e91af09 commit ff6b246
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 178 deletions.
7 changes: 6 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ commands:
- run:
name: Get PR Info
command: |
PR_NUMBER=`git log -1 --pretty=%s | sed -En 's/(Try|Merge) #([0-9]*).*/\2/p'`
#During OPEN PR, get from CCI.
PR_NUMBER=${CIRCLE_PULL_REQUEST##*/}
if [ -z "$PR)NUMBER" ];then
# get from merge commit on closed PR.
PR_NUMBER=`git log -1 --pretty=%s | sed -En 's/.*\(#([0-9]*)\).*/\1/p'`
fi
echo "PR_NUMBER is ${PR_NUMBER}"
echo "export PR_NUMBER=${PR_NUMBER}" >> $BASH_ENV
4 changes: 2 additions & 2 deletions scripts/loop.bash
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ load_variables(){

if [[ $DEBUG != "false" ]];then
echo "Using Temp Dir: $TMP_DIR"
set
#set
fi
}

Expand Down Expand Up @@ -109,7 +109,7 @@ update_active_run_data(){
echo "All running jobs with created_at:"
cat $AUGMENTED_JOBSTATUS_PATH || exit 0
echo "All workflow details."
cat /tmp/workflow-*.json
cat /tmp/workflow-*.json || echo "Could not load workflows.."
exit 1
fi
fi
Expand Down
1 change: 1 addition & 0 deletions src/@orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ description: |
This orb requires the project to have an **Personal** API key in order to query build states.
It requires a single environment variable CIRCLECI_API_KEY which can be created in account settings - https://circleci.com/account/api.
3.1.1: Boolean fix finally isolated, thanks @@charlescqian
3.1.0: Force fail, not cancel, when blocked. PR #113, thanks @pguinard-public-com
3.0.0: [BREAKING CHANGE] Use pipeline.number as authoritative comparison. Deep thanks to @PChambino
2.2.2: Docs clarity on token needs (@davidjb)
Expand Down
37 changes: 20 additions & 17 deletions src/commands/until_front_of_line.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,27 @@ parameters:


steps:
- run:
name: 'Queue - Import Parameters'
command: |
echo "export BLOCK_WORKFLOW=<<parameters.block-workflow>>" >> $BASH_ENV
echo "export CCI_API_KEY_NAME=<< parameters.circleci-api-key >>" >> $BASH_ENV
echo "export CIRCLECI_BASE_URL=https://<<parameters.circleci-hostname>>" >> $BASH_ENV
echo "export CONFIDENCE_THRESHOLD=<<parameters.confidence>>" >> $BASH_ENV
echo "export DEBUG=<<parameters.include-debug>>" >> $BASH_ENV
echo "export DONT_QUIT=<<parameters.dont-quit>>" >> $BASH_ENV
echo "export FAIL_INSTEAD_OF_CANCEL=<< parameters.fail-instead-of-cancel >>" >> $BASH_ENV
echo "export FILTER_BRANCH=<< parameters.this-branch-only >>" >> $BASH_ENV
echo "export FORCE_CANCEL_PREVIOUS=<<parameters.force-cancel-previous>>" >> $BASH_ENV
echo "export JOB_REGEXP=\"<<parameters.job-regex>>\"" >> $BASH_ENV
echo "export MAX_TIME='<<parameters.max-wait-time>>'" >> $BASH_ENV
echo "export MY_BRANCH="$CIRCLE_BRANCH"" >> $BASH_ENV
echo "export MY_PIPELINE_NUMBER=<<parameters.my-pipeline>>" >> $BASH_ENV
echo "export ONLY_ON_BRANCH=<<parameters.limit-branch-name>>" >> $BASH_ENV
echo "export ONLY_ON_WORKFLOW=<<parameters.limit-workflow-name>>" >> $BASH_ENV
echo "export TAG_PATTERN=\"<<parameters.tag-pattern>>\"" >> $BASH_ENV
- run:
name: Queue Until Front of Line
command: <<include(../scripts/loop.bash)>>
shell: bash
environment:
BLOCK_WORKFLOW: <<parameters.block-workflow>>
CCI_API_KEY_NAME: << parameters.circleci-api-key >>
CIRCLECI_BASE_URL: https://<<parameters.circleci-hostname>>
CONFIDENCE_THRESHOLD: <<parameters.confidence>>
DEBUG: <<parameters.include-debug>>
DONT_QUIT: <<parameters.dont-quit>>
FAIL_INSTEAD_OF_CANCEL: << parameters.fail-instead-of-cancel >>
FILTER_BRANCH: << parameters.this-branch-only >>
FORCE_CANCEL_PREVIOUS: <<parameters.force-cancel-previous>>
JOB_REGEXP: <<parameters.job-regex>>
MAX_TIME: '<<parameters.max-wait-time>>'
MY_BRANCH: "$CIRCLE_BRANCH"
MY_PIPELINE_NUMBER: <<parameters.my-pipeline>>
ONLY_ON_BRANCH: <<parameters.limit-branch-name>>
ONLY_ON_WORKFLOW: <<parameters.limit-workflow-name>>
TAG_PATTERN: <<parameters.tag-pattern>>
2 changes: 1 addition & 1 deletion test/api/jobs/nopreviousjobs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"testing-note":"This represents the current build, with a job that should be serial",
"build_num" : 2,
"build_num" : 3,
"committer_date": "2019-01-17T11:17:24-05:00",
"branch" : "master",
"build_parameters":{
Expand Down
13 changes: 11 additions & 2 deletions test/bats_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,16 @@ function assert_jq_contains {

function load_config_parameters {
NAME="${1:-build}"
jq -r '.jobs["'"${NAME}"'"].steps[0].run.environment | to_entries[] | "export "+(.key | ascii_upcase)+"="+(.value | @sh)' $JSON_PROJECT_CONFIG > $ENV_STAGING_PATH
source $ENV_STAGING_PATH
#echo $JSON_PROJECT_CONFIG > $ENV_STAGING_PATH
jq -r '.jobs["'"${NAME}"'"].steps[0].run.command' $JSON_PROJECT_CONFIG > $ENV_STAGING_PATH-input
>$ENV_STAGING_PATH
export BASH_ENV=$ENV_STAGING_PATH
export CIRCLE_BRANCH="main"
export CIRCLE_BUILD_NUM=3
export CIRCLE_PROJECT_USERNAME=eddie
export CIRCLE_PROJECT_REPONAME=queue
export CIRCLE_REPOSITORY_URL="https://github.com/somthh"
export CIRCLE_JOB=singlejob
bash "$ENV_STAGING_PATH-input"
}

11 changes: 11 additions & 0 deletions test/inputs/command-anybranch.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
jobs:
build:
docker:
- image: circleci/node:10
working_directory: ~/repo
steps:
- queue/until_front_of_line:
max-wait-time: "1/10"
my-pipeline: 2
include-debug: true
this-branch-only: false
Loading

0 comments on commit ff6b246

Please sign in to comment.