diff --git a/.circleci/config.yml b/.circleci/config.yml index 205e29d..e577364 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,172 +1,43 @@ - version: 2.1 -parameters: - orbname: - type: string - default: "queue" - description: Change this to whatever name is correct for your orb. +orbs: + orb-tools: circleci/orb-tools@12 workflows: - build-deploy: + version: 2 + build-and-publish: jobs: - - validate: + - orb-tools/pack: filters: branches: - ignore: - - master - - test: - context: [orbs] - requires: - - validate - filters: - branches: - only: - - staging - - trying - - publish: - context: [orbs] - requires: - - test - filters: - branches: - only: staging + only: carwow + tags: + only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ -jobs: - validate: - docker: - - image: cimg/base:2019.08 - working_directory: ~/repo - steps: - - checkout - - install-circleci - - pack-and-validate - test: - docker: - - image: cimg/base:2019.08 - working_directory: ~/repo - steps: - - checkout - - install-circleci - - pack-and-validate - - pr-info - - run: - name: Publish Dev - command: | - PUBLISH_MESSAGE=`circleci orb publish packed.yml eddiewebb/<>@dev:<> --token ${CIRCLECI_API_KEY}` - ORB_VERSION=$(echo $PUBLISH_MESSAGE | sed -n 's/Orb `\(.*\)` was published.*/\1/p') - echo "export ORB_VERSION=\"${ORB_VERSION}\"" >> $BASH_ENV - echo $ORB_VERSION - echo "export PR_MESSAGE=\"BotComment: *Development* version of orb available for manual validation - \\\`${ORB_VERSION}\\\`\"" >> $BASH_ENV - - install-bats - - run: - name: Import Tests using BATS - command: | - export BATS_IMPORT_DEV_ORB="eddiewebb/<>@dev:<>" - bats --jobs 8 test - - pr-comment - - run: - name: Check Semver - command: | - if [ "$PR_NUMBER" == "" ];then - echo "No pr found, do nothing" - exit 0 - fi - TITLE=`curl -u eddiewebb:${GHI_TOKEN} "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${PR_NUMBER}" | jq '.title' ` - SEMVER_INCREMENT=`echo $TITLE | sed -En 's/.*\[semver:(major|minor|patch|skip)\].*/\1/p'` - if [ -z ${SEMVER_INCREMENT} ];then - echo "Merge commit did not indicate which SemVer increment to make. Please ammend commit with [semver:FOO] where FOO is major, minor, or patch" - exit 1 - fi + - orb-tools/publish: + name: orb-tools/publish-dev + context: org-global + orb_name: carwow/queue + vcs_type: <> - publish: - docker: - - image: cimg/base:2024.01 - working_directory: ~/repo - steps: - - checkout - - install-circleci - - pr-info - - when: - condition: - or: - - equal: [ trying, << pipeline.git.branch >> ] - - equal: [ staging, << pipeline.git.branch >> ] - steps: - - run: - name: Promote to prod - command: | - SEMVER_INCREMENT=`git log -1 --pretty=%B | sed -En 's/.*\[semver:(major|minor|patch|skip)\].*/\1/p'` - if [ -z ${SEMVER_INCREMENT} ];then - echo "Merge commit did not indicate which SemVer increment to make. Please ammend commit with [semver:FOO] where FOO is major, minor, or patch" - exit 1 - elif [ "$SEMVER_INCREMENT" == "skip" ];then - echo "SEMVER in commit indicated to skip orb release" - echo "export PR_MESSAGE=\"Orb publish was skipped due to [semver:skip] in commit message.\"" >> $BASH_ENV - exit 0 - else - PUBLISH_MESSAGE=`circleci orb publish promote eddiewebb/<>@dev:<> ${SEMVER_INCREMENT} --token ${CIRCLECI_API_KEY}` - echo $PUBLISH_MESSAGE - ORB_VERSION=$(echo $PUBLISH_MESSAGE | sed -n 's/Orb .* was promoted to `\(.*\)`.*/\1/p') - echo "export PR_MESSAGE=\"BotComment: *Production* version of orb available for use - \\\`${ORB_VERSION}\\\`\"" >> $BASH_ENV - fi - - pr-comment + requires: + - orb-tools/pack + filters: + branches: + only: carwow + - orb-tools/publish: + context: org-global + orb_name: carwow/queue + vcs_type: <> + pub_type: production + requires: + - orb-tools/pack -commands: - install-bats: - description: installs the BATS bash testing tool - steps: - - run: - name: Install BATS (bash testing) - command: | - cd /tmp && git clone https://github.com/bats-core/bats-core.git && cd bats-core - ./install.sh /usr/local - - run: - name: Install YQ - command: | - curl -L https://github.com/mikefarah/yq/releases/download/v4.14.1/yq_linux_amd64 -o yq - chmod a+x yq - mv yq /usr/local/bin/ - install-circleci: - description: installs the new CIrcleCI CLI with orb support - steps: - - run: - name: Install CircleCI CLI (the new one) - command: | - #curl https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh --fail --show-error | bash - circleci update - circleci version - echo "Run circleci help" - circleci help - echo -e "token: ${CIRCLECI_API_KEY}\nverbose: false" > ~/.circleci/cli.yml - pack-and-validate: - description: pack directory to single file and validate - steps: - - run: - name: Pack and Validate - command: | - circleci orb pack src > packed.yml - circleci orb validate packed.yml - pr-comment: - description: add message to pr this build originated from - steps: - - run: - name: Publish Version to PR - command: | - if [ "$PR_NUMBER" == "" ];then - echo "No pr found, do nothing" - exit 0 - fi - curl -X POST -u eddiewebb:${GHI_TOKEN} "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${PR_NUMBER}/comments" -d "{\"body\":\"${PR_MESSAGE}\"}" - pr-info: - description: get PR number this change originated from - steps: - - run: - name: Get PR Info - command: | - PR_NUMBER=`git log -1 --pretty=%s | sed -En 's/(Try|Merge) #([0-9]*).*/\2/p'` - echo "PR_NUMBER is ${PR_NUMBER}" - echo "export PR_NUMBER=${PR_NUMBER}" >> $BASH_ENV + filters: + branches: + ignore: /.*/ + tags: + only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ diff --git a/src/@orb.yml b/src/@orb.yml index f259b4b..46a30f5 100644 --- a/src/@orb.yml +++ b/src/@orb.yml @@ -1,42 +1,12 @@ version: 2.1 description: | - Allows jobs or entire workflows to be queued to ensure they run in serial. + Allows jobs or entire workflows to be queued to ensure they run in serial. This is ideal for deployments or other activities that must not run concurrently. - May optionaly consider branch-level isolation if unique branches should run concurrently. - 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.0.0: [BREAKING CHANGE] Use pipeline.number as authoritative comparison. Breaks many parameters. - 2.2.2: Docs clarity on token needs (@davidjb) - 2.2.1: fixes release version bug - 2.2.0: Adds 'filter-by-workflow' (@soniqua) - 2.0.0: Breaking change fixes dyanamic config, but may break Bitbucket users. - 1.12.0: Adds Server Support (@nanophate) - 1.9.0: Doc update - 1.8.4: Adds urlencode for branch names. (@andrew-barnett) - 1.8.1: Adds content-type header to API calls (@kevinr-electric) and prints message on error (@AlexMeuer) - 1.8.0: minor fix same as version 1.8.0 (missing docs) - 1.7.1: patch fix same as version 1.8.1 to catch folsk who dont update - 1.7.0: adds regexp for job names, collab with @jonesie100 - 1.6.5: docs contribution by @pwilczynskiclearcode - 1.6.4: support slashes in Tags, thanks @dunial - 1.6.3: addresses API changes that broke branch-job queueing, adds more API checks - 1.6.1: fixes issue in tag matching , thanks @calvin-summer - 1.6.0: Support Tags, thanks @nikolaik, @dunial - 1.5.0: API variables name as parameter , thanks @philnielson - 1.4.4: Docs improvements, thanks @jordan-brough - 1.4.3: more confident confidence thanks @GreshamDanielStephens - 1.4.2: Doc improvements, thanks @olleolleolle - 1.4.1: fixes bug in block-workflow as job. thanks @mu-bro - 1.4.0: Adds confidence checks to avoid race condition - 1.3.0: use small resource class in job + Fork of eddiewebb/queue v3 pre-release. - - - display: - home_url: https://eddiewebb.github.io/circleci-queue/ - source_url: https://github.com/eddiewebb/circleci-queue + source_url: https://github.com/carwow/circleci-queue examples: queue_workflow: @@ -44,27 +14,27 @@ examples: usage: version: 2.1 orbs: - queue: eddiewebb/queue@volatile + queue: carwow/queue@1 workflows: build_deploy: jobs: - queue/block_workflow: - max-wait-time: "10" # max wait, in minutes (default 10) - limit-branch-name: main # restrict queueing to a specific branch (default *) + circleci-api-key: CIRCLE_TOKEN + my-pipeline: <> - some_other_job: requires: - queue/block_workflow - + single_concurrency_job: description: | - Used to ensure that a only single job (deploy) is not run concurrently. - By default will only queue if the same job from previous worfklows is running on the same branch. + Used to ensure that a only single job (deploy) is not run concurrently. + By default will only queue if the same job from previous worfklows is running on the same branch. This allows safe jobs like build/test to overlap, minimizing overall queue times. usage: version: 2.1 orbs: - queue: eddiewebb/queue@volatile + queue: carwow/queue@1 workflows: build_deploy: @@ -76,25 +46,25 @@ examples: jobs: build: docker: - - image: circleci/node:10 + - image: circleci/ruby steps: - run: echo "This job can overlap" deploy: docker: - - image: circleci/node:10 + - image: circleci/ruby steps: - queue/until_front_of_line: - max-wait-time: "10" # max wait, in minutes (default 10) - limit-branch-name: main # restrict queueing to a specific branch (default *) + circleci-api-key: CIRCLE_TOKEN + my-pipeline: <> - run: echo "This job will not overlap" - + multiple_job_names_regexp: description: Use regexp-jobname when you have multiple jobs to block order of. usage: version: 2.1 orbs: - queue: eddiewebb/queue@volatile + queue: carwow/queue@1 workflows: build_deploy: @@ -109,23 +79,23 @@ examples: jobs: build: docker: - - image: circleci/node:10 + - image: circleci/ruby steps: - run: echo "This job can overlap" DeployStep1: docker: - - image: circleci/node:10 + - image: circleci/ruby steps: - queue/until_front_of_line: - max-wait-time: "10" # max wait, in minutes (default 10) - limit-branch-name: main # restrict queueing to a specific branch (default *) - job-regex: "^DeployStep[0-9]$" #use extendex regexp pattern + circleci-api-key: CIRCLE_TOKEN + my-pipeline: <> + job-regex: "^DeployStep[0-9]$" - run: echo "This job will not overlap with itself or next similar nameds job" DeployStep2: docker: - - image: circleci/node:10 + - image: circleci/ruby steps: - run: echo "This job will block step1 on any further workflows" diff --git a/src/commands/until_front_of_line.yml b/src/commands/until_front_of_line.yml index 0e1b5a5..11d9a7d 100644 --- a/src/commands/until_front_of_line.yml +++ b/src/commands/until_front_of_line.yml @@ -50,27 +50,18 @@ parameters: default: "circleci.com" description: "For server user to specifiy custom hostname for their server" - # - # These a;l pass through from pipeline, but orb validator wont let us use them inline :( - # - my-pipeline: - type: string - default: "<>" - trigger-source: - type: string - default: "<>" vcs-type: type: string - default: "<>" - my-branch: - type: string - default: "<>" + default: github + my-pipeline: + type: integer + description: "Set as: <>" steps: - run: name: Queue Until Front of Line command: <> - environment: + environment: ONLY_ON_BRANCH: <> BLOCK_WORKFLOW: <> MAX_TIME: '<>' @@ -84,6 +75,4 @@ steps: JOB_REGEXP: <> CIRCLECI_BASE_URL: https://<> MY_PIPELINE_NUMBER: <> - TRIGGER_SOURCE: <> VCS_TYPE: <> - MY_BRANCH: <> \ No newline at end of file diff --git a/src/jobs/block_workflow.yml b/src/jobs/block_workflow.yml index b7443ef..bd3948f 100644 --- a/src/jobs/block_workflow.yml +++ b/src/jobs/block_workflow.yml @@ -28,7 +28,6 @@ parameters: type: string default: "*" description: "Only queue on a specified workflow. Consider combining this with `consider-branch`:`false`." - # vcs-type --> pipeline.project.type confidence: type: string default: "1" @@ -50,7 +49,12 @@ parameters: default: "circleci.com" description: "For server user to specifiy custom hostname for their server" - + vcs-type: + type: string + default: github + my-pipeline: + type: integer + description: "Set as: <>" docker: - image: cimg/base:stable @@ -68,3 +72,5 @@ steps: tag-pattern: <> job-regex: <> circleci-hostname: <> + vcs-type: <> + my-pipeline: <>