Possible to lock on branch OR tag?
Hi, first of all thanks for this little project. It's been very helpful for me. I'm trying to use do-exclusively to lock my deploy steps as follows:
do-exclusively --branch master --tag qa- ./deploy/staging.sh
I would like to prevent simultaneous deploys on the master branch AND for qa- tagged releases. However, there will never be a situation where both (CIRCLE_BRANCH=master and CIRCLE_TAG=qa-*) are true of a single build.
I modified do-exclusively, specifically should_skip() as follows:
should_skip() {
if [[ $branch ]] && [[ $tag ]]; then
if [[ "$CIRCLE_BRANCH" != "$branch" && "$CIRCLE_TAG" != $tag* ]]; then
echo "Branch/tag pair does not satisfy conditions. Skipping ..."
return 0
fi
return 1
fi
if [[ "$branch" && "$CIRCLE_BRANCH" != "$branch" ]]; then
echo "Not on branch $branch. Skipping..."
return 0
fi
if [[ "$tag" && "$CIRCLE_TAG" != $tag* ]]; then
echo "No [$tag] tag found. Skipping..."
return 0
fi
return 1
}
And make_jq_prog():
make_jq_prog() {
local jq_filters=""
if [[ $branch ]]; then
jq_filters+=" and .branch == \"$branch\""
fi
if [[ $tag ]]; then
jq_filters+=" and (.vcs_tag | contains(\"$tag\"))"
fi
# both --branch and --tag are used, but we want to check for either (or) as opposed to both (and)
if [[ $branch ]] && [[ $tag ]]; then
jq_filters=" and (.branch == \"$branch\" or (.vcs_tag | contains(\"$tag\")))"
fi
jq_prog=".[] | select(.build_num < $CIRCLE_BUILD_NUM and (.status | test(\"running|pending|queued\")) $jq_filters) | .build_num"
}
My output is the following:
Checking for running builds...
jq: error (at <stdin>:0): null (null) and string ("qa-") cannot have their containment checked
Exited with code 5
Any ideas on how to accomplish my use case?
At the moment both of these flags seem to be required, so we'd need to change the option parser
@zzak are you sure? From the readme:
The branch and tag arguments are both optional and limit the scope of the command and its lock to a given branch name or builds whose commit message contains a certain commit message.
@reedflinch I've been known to be wrong, but that was what I experienced when working on the option parsing earlier: https://github.com/bellkev/circle-lock-test/pull/5/files#diff-6a470a31c1369648e0477bc11e378e7aL6