From 6b31771985f061fe51efda965f274c3feff59e12 Mon Sep 17 00:00:00 2001 From: Maxim Schuwalow Date: Fri, 11 Aug 2023 14:01:16 +0200 Subject: [PATCH] use custom lock command --- .circleci/config.yml | 53 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 89731663..f9833e9d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -84,6 +84,56 @@ references: name: Reset package-lock.json command: git checkout -- package-lock.json +commands: + # for of dynamo-lock/lock that specifies no_output_timeout + dynamo-lock_lock: + parameters: + ttl: + description: TTL of lock in seconds + type: integer + default: 600 + table: + description: DynamoDB table for locks + type: string + default: ci_locks + lock_name: + description: >- + Name of the lock to acquire + + This name affects which builds lock against each other. The default will + lock branches on the same project and the same branch. If you'd like to + lock all builds in a project, you could use + `${CIRCLE_PROJECT_USERNAME}_${CIRCLE_PROJECT_REPONAME}` + type: string + default: ${CIRCLE_PROJECT_USERNAME}_${CIRCLE_PROJECT_REPONAME}_${CIRCLE_BRANCH} + branches: + description: >- + Branch regex to limit locking on + + This is a bash regex, so keep in mind that short escape sequences won't + work (eg `\d` - use `[0-9]` instead). The lock commands will only be + effective on branches matching this regex. + type: string + default: master|develop + steps: + - run: + name: Acquire lock + no_output_timeout: << parameters.ttl >>s + command: |- + if [[ "$CIRCLE_BRANCH" =~ << parameters.branches >> ]]; then + [[ -x "/tmp/dynolocker_linux_amd64" ]] || echo 'Please call "setup" first' + + /tmp/dynolocker_linux_amd64 \ + --debug \ + --table "<< parameters.table >>" \ + --name "<< parameters.lock_name >>" \ + --ttl << parameters.ttl >> \ + lock + else + echo "Skipping lock due to excluded branch" + fi + + jobs: simple_test: parallelism: 1 @@ -126,10 +176,9 @@ jobs: - *npm_install - dynamo-lock/setup: branches: '.*' - - dynamo-lock/lock: + - dynamo-lock_lock: lock_name: << pipeline.parameters.browserstack_lock_name >> ttl: << pipeline.parameters.lock_timeout_seconds >> - no_output_timeout: << pipeline.parameters.lock_timeout_seconds >>s branches: '.*' - run: name: Run browserstack tests