circle-lock-test icon indicating copy to clipboard operation
circle-lock-test copied to clipboard

Possible to lock on branch OR tag?

Open reedflinch opened this issue 8 years ago • 3 comments

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?

reedflinch avatar May 02 '17 21:05 reedflinch

At the moment both of these flags seem to be required, so we'd need to change the option parser

zzak avatar May 05 '17 16:05 zzak

@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 avatar May 08 '17 13:05 reedflinch

@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

zzak avatar May 08 '17 16:05 zzak