Skip to content

Commit 2a94879

Browse files
committed
[carwow] Set pipeline number as integer
Fork of eddiewebb/queue v3 pre-release. The pipeline values are not passing thru the orb, so they need to be declared explicitly. Only the pipeline number is really neeed, but it needs to be of type integer as CircleCI can't cast pipeline values. https://discuss.circleci.com/t/pipeline-variables-not-valid-in-orbs/37221 https://discuss.circleci.com/t/unable-to-force-pipeline-number-to-be-type-string/40201 Also, set it up so we can publish a forked version within carwow namespace.
1 parent 4f39420 commit 2a94879

File tree

4 files changed

+65
-229
lines changed

4 files changed

+65
-229
lines changed

.circleci/config.yml

Lines changed: 30 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,172 +1,43 @@
1-
21
version: 2.1
32

4-
parameters:
5-
orbname:
6-
type: string
7-
default: "queue"
8-
description: Change this to whatever name is correct for your orb.
3+
orbs:
4+
orb-tools: circleci/orb-tools@12
95

106
workflows:
11-
build-deploy:
7+
version: 2
8+
build-and-publish:
129
jobs:
13-
- validate:
10+
- orb-tools/pack:
1411
filters:
1512
branches:
16-
ignore:
17-
- master
18-
- test:
19-
context: [orbs]
20-
requires:
21-
- validate
22-
filters:
23-
branches:
24-
only:
25-
- staging
26-
- trying
27-
- publish:
28-
context: [orbs]
29-
requires:
30-
- test
31-
filters:
32-
branches:
33-
only: staging
13+
only: carwow
14+
tags:
15+
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
3416

35-
jobs:
36-
validate:
37-
docker:
38-
- image: cimg/base:2019.08
39-
working_directory: ~/repo
40-
steps:
41-
- checkout
42-
- install-circleci
43-
- pack-and-validate
44-
test:
45-
docker:
46-
- image: cimg/base:2019.08
47-
working_directory: ~/repo
48-
steps:
49-
- checkout
50-
- install-circleci
51-
- pack-and-validate
52-
- pr-info
53-
- run:
54-
name: Publish Dev
55-
command: |
56-
PUBLISH_MESSAGE=`circleci orb publish packed.yml eddiewebb/<<pipeline.parameters.orbname>>@dev:<<pipeline.number>> --token ${CIRCLECI_API_KEY}`
57-
ORB_VERSION=$(echo $PUBLISH_MESSAGE | sed -n 's/Orb `\(.*\)` was published.*/\1/p')
58-
echo "export ORB_VERSION=\"${ORB_VERSION}\"" >> $BASH_ENV
59-
echo $ORB_VERSION
60-
echo "export PR_MESSAGE=\"BotComment: *Development* version of orb available for manual validation - \\\`${ORB_VERSION}\\\`\"" >> $BASH_ENV
61-
- install-bats
62-
- run:
63-
name: Import Tests using BATS
64-
command: |
65-
export BATS_IMPORT_DEV_ORB="eddiewebb/<<pipeline.parameters.orbname>>@dev:<<pipeline.number>>"
66-
bats --jobs 8 test
67-
- pr-comment
68-
- run:
69-
name: Check Semver
70-
command: |
71-
if [ "$PR_NUMBER" == "" ];then
72-
echo "No pr found, do nothing"
73-
exit 0
74-
fi
75-
TITLE=`curl -u eddiewebb:${GHI_TOKEN} "https://api.github.com/repos/${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME}/issues/${PR_NUMBER}" | jq '.title' `
76-
SEMVER_INCREMENT=`echo $TITLE | sed -En 's/.*\[semver:(major|minor|patch|skip)\].*/\1/p'`
77-
if [ -z ${SEMVER_INCREMENT} ];then
78-
echo "Merge commit did not indicate which SemVer increment to make. Please ammend commit with [semver:FOO] where FOO is major, minor, or patch"
79-
exit 1
80-
fi
17+
- orb-tools/publish:
18+
name: orb-tools/publish-dev
19+
context: org-global
20+
orb_name: carwow/queue
21+
vcs_type: <<pipeline.project.type>>
8122

82-
publish:
83-
docker:
84-
- image: cimg/base:2024.01
85-
working_directory: ~/repo
86-
steps:
87-
- checkout
88-
- install-circleci
89-
- pr-info
90-
- when:
91-
condition:
92-
or:
93-
- equal: [ trying, << pipeline.git.branch >> ]
94-
- equal: [ staging, << pipeline.git.branch >> ]
95-
steps:
96-
- run:
97-
name: Promote to prod
98-
command: |
99-
SEMVER_INCREMENT=`git log -1 --pretty=%B | sed -En 's/.*\[semver:(major|minor|patch|skip)\].*/\1/p'`
100-
if [ -z ${SEMVER_INCREMENT} ];then
101-
echo "Merge commit did not indicate which SemVer increment to make. Please ammend commit with [semver:FOO] where FOO is major, minor, or patch"
102-
exit 1
103-
elif [ "$SEMVER_INCREMENT" == "skip" ];then
104-
echo "SEMVER in commit indicated to skip orb release"
105-
echo "export PR_MESSAGE=\"Orb publish was skipped due to [semver:skip] in commit message.\"" >> $BASH_ENV
106-
exit 0
107-
else
108-
PUBLISH_MESSAGE=`circleci orb publish promote eddiewebb/<<pipeline.parameters.orbname>>@dev:<<pipeline.number>> ${SEMVER_INCREMENT} --token ${CIRCLECI_API_KEY}`
109-
echo $PUBLISH_MESSAGE
110-
ORB_VERSION=$(echo $PUBLISH_MESSAGE | sed -n 's/Orb .* was promoted to `\(.*\)`.*/\1/p')
111-
echo "export PR_MESSAGE=\"BotComment: *Production* version of orb available for use - \\\`${ORB_VERSION}\\\`\"" >> $BASH_ENV
112-
fi
113-
- pr-comment
23+
requires:
24+
- orb-tools/pack
11425

26+
filters:
27+
branches:
28+
only: carwow
11529

30+
- orb-tools/publish:
31+
context: org-global
32+
orb_name: carwow/queue
33+
vcs_type: <<pipeline.project.type>>
34+
pub_type: production
11635

36+
requires:
37+
- orb-tools/pack
11738

118-
commands:
119-
install-bats:
120-
description: installs the BATS bash testing tool
121-
steps:
122-
- run:
123-
name: Install BATS (bash testing)
124-
command: |
125-
cd /tmp && git clone https://github.com/bats-core/bats-core.git && cd bats-core
126-
./install.sh /usr/local
127-
- run:
128-
name: Install YQ
129-
command: |
130-
curl -L https://github.com/mikefarah/yq/releases/download/v4.14.1/yq_linux_amd64 -o yq
131-
chmod a+x yq
132-
mv yq /usr/local/bin/
133-
install-circleci:
134-
description: installs the new CIrcleCI CLI with orb support
135-
steps:
136-
- run:
137-
name: Install CircleCI CLI (the new one)
138-
command: |
139-
#curl https://raw.githubusercontent.com/CircleCI-Public/circleci-cli/master/install.sh --fail --show-error | bash
140-
circleci update
141-
circleci version
142-
echo "Run circleci help"
143-
circleci help
144-
echo -e "token: ${CIRCLECI_API_KEY}\nverbose: false" > ~/.circleci/cli.yml
145-
pack-and-validate:
146-
description: pack directory to single file and validate
147-
steps:
148-
- run:
149-
name: Pack and Validate
150-
command: |
151-
circleci orb pack src > packed.yml
152-
circleci orb validate packed.yml
153-
pr-comment:
154-
description: add message to pr this build originated from
155-
steps:
156-
- run:
157-
name: Publish Version to PR
158-
command: |
159-
if [ "$PR_NUMBER" == "" ];then
160-
echo "No pr found, do nothing"
161-
exit 0
162-
fi
163-
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}\"}"
164-
pr-info:
165-
description: get PR number this change originated from
166-
steps:
167-
- run:
168-
name: Get PR Info
169-
command: |
170-
PR_NUMBER=`git log -1 --pretty=%s | sed -En 's/(Try|Merge) #([0-9]*).*/\2/p'`
171-
echo "PR_NUMBER is ${PR_NUMBER}"
172-
echo "export PR_NUMBER=${PR_NUMBER}" >> $BASH_ENV
39+
filters:
40+
branches:
41+
ignore: /.*/
42+
tags:
43+
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/

src/@orb.yml

Lines changed: 22 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,40 @@
11
version: 2.1
22
description: |
3-
Allows jobs or entire workflows to be queued to ensure they run in serial.
3+
Allows jobs or entire workflows to be queued to ensure they run in serial.
44
This is ideal for deployments or other activities that must not run concurrently.
5-
May optionaly consider branch-level isolation if unique branches should run concurrently.
6-
This orb requires the project to have an **Personal** API key in order to query build states.
7-
It requires a single environment variable CIRCLECI_API_KEY which can be created in account settings - https://circleci.com/account/api.
85
9-
3.0.0: [BREAKING CHANGE] Use pipeline.number as authoritative comparison. Breaks many parameters.
10-
2.2.2: Docs clarity on token needs (@davidjb)
11-
2.2.1: fixes release version bug
12-
2.2.0: Adds 'filter-by-workflow' (@soniqua)
13-
2.0.0: Breaking change fixes dyanamic config, but may break Bitbucket users.
14-
1.12.0: Adds Server Support (@nanophate)
15-
1.9.0: Doc update
16-
1.8.4: Adds urlencode for branch names. (@andrew-barnett)
17-
1.8.1: Adds content-type header to API calls (@kevinr-electric) and prints message on error (@AlexMeuer)
18-
1.8.0: minor fix same as version 1.8.0 (missing docs)
19-
1.7.1: patch fix same as version 1.8.1 to catch folsk who dont update
20-
1.7.0: adds regexp for job names, collab with @jonesie100
21-
1.6.5: docs contribution by @pwilczynskiclearcode
22-
1.6.4: support slashes in Tags, thanks @dunial
23-
1.6.3: addresses API changes that broke branch-job queueing, adds more API checks
24-
1.6.1: fixes issue in tag matching , thanks @calvin-summer
25-
1.6.0: Support Tags, thanks @nikolaik, @dunial
26-
1.5.0: API variables name as parameter , thanks @philnielson
27-
1.4.4: Docs improvements, thanks @jordan-brough
28-
1.4.3: more confident confidence thanks @GreshamDanielStephens
29-
1.4.2: Doc improvements, thanks @olleolleolle
30-
1.4.1: fixes bug in block-workflow as job. thanks @mu-bro
31-
1.4.0: Adds confidence checks to avoid race condition
32-
1.3.0: use small resource class in job
6+
Fork of eddiewebb/queue v3 pre-release.
337
34-
35-
36-
378
display:
38-
home_url: https://eddiewebb.github.io/circleci-queue/
39-
source_url: https://github.com/eddiewebb/circleci-queue
9+
source_url: https://github.com/carwow/circleci-queue
4010

4111
examples:
4212
queue_workflow:
4313
description: Used typically as first job and will queue until no previous workflows are running
4414
usage:
4515
version: 2.1
4616
orbs:
47-
queue: eddiewebb/queue@volatile
17+
queue: carwow/queue@1
4818

4919
workflows:
5020
build_deploy:
5121
jobs:
5222
- queue/block_workflow:
53-
max-wait-time: "10" # max wait, in minutes (default 10)
54-
limit-branch-name: main # restrict queueing to a specific branch (default *)
23+
circleci-api-key: CIRCLE_TOKEN
24+
my-pipeline: <<pipeline.number>>
5525
- some_other_job:
5626
requires:
5727
- queue/block_workflow
58-
28+
5929
single_concurrency_job:
6030
description: |
61-
Used to ensure that a only single job (deploy) is not run concurrently.
62-
By default will only queue if the same job from previous worfklows is running on the same branch.
31+
Used to ensure that a only single job (deploy) is not run concurrently.
32+
By default will only queue if the same job from previous worfklows is running on the same branch.
6333
This allows safe jobs like build/test to overlap, minimizing overall queue times.
6434
usage:
6535
version: 2.1
6636
orbs:
67-
queue: eddiewebb/queue@volatile
37+
queue: carwow/queue@1
6838

6939
workflows:
7040
build_deploy:
@@ -76,25 +46,25 @@ examples:
7646
jobs:
7747
build:
7848
docker:
79-
- image: circleci/node:10
49+
- image: circleci/ruby
8050
steps:
8151
- run: echo "This job can overlap"
8252

8353
deploy:
8454
docker:
85-
- image: circleci/node:10
55+
- image: circleci/ruby
8656
steps:
8757
- queue/until_front_of_line:
88-
max-wait-time: "10" # max wait, in minutes (default 10)
89-
limit-branch-name: main # restrict queueing to a specific branch (default *)
58+
circleci-api-key: CIRCLE_TOKEN
59+
my-pipeline: <<pipeline.number>>
9060
- run: echo "This job will not overlap"
91-
61+
9262
multiple_job_names_regexp:
9363
description: Use regexp-jobname when you have multiple jobs to block order of.
9464
usage:
9565
version: 2.1
9666
orbs:
97-
queue: eddiewebb/queue@volatile
67+
queue: carwow/queue@1
9868

9969
workflows:
10070
build_deploy:
@@ -109,23 +79,23 @@ examples:
10979
jobs:
11080
build:
11181
docker:
112-
- image: circleci/node:10
82+
- image: circleci/ruby
11383
steps:
11484
- run: echo "This job can overlap"
11585

11686
DeployStep1:
11787
docker:
118-
- image: circleci/node:10
88+
- image: circleci/ruby
11989
steps:
12090
- queue/until_front_of_line:
121-
max-wait-time: "10" # max wait, in minutes (default 10)
122-
limit-branch-name: main # restrict queueing to a specific branch (default *)
123-
job-regex: "^DeployStep[0-9]$" #use extendex regexp pattern
91+
circleci-api-key: CIRCLE_TOKEN
92+
my-pipeline: <<pipeline.number>>
93+
job-regex: "^DeployStep[0-9]$"
12494
- run: echo "This job will not overlap with itself or next similar nameds job"
12595

12696
DeployStep2:
12797
docker:
128-
- image: circleci/node:10
98+
- image: circleci/ruby
12999
steps:
130100
- run: echo "This job will block step1 on any further workflows"
131101

src/commands/until_front_of_line.yml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -50,27 +50,18 @@ parameters:
5050
default: "circleci.com"
5151
description: "For server user to specifiy custom hostname for their server"
5252

53-
#
54-
# These a;l pass through from pipeline, but orb validator wont let us use them inline :(
55-
#
56-
my-pipeline:
57-
type: string
58-
default: "<<pipeline.number>>"
59-
trigger-source:
60-
type: string
61-
default: "<<pipeline.trigger_source>>"
6253
vcs-type:
6354
type: string
64-
default: "<<pipeline.project.type>>"
65-
my-branch:
66-
type: string
67-
default: "<<pipeline.git.branch>>"
55+
default: github
56+
my-pipeline:
57+
type: integer
58+
description: "Set as: <<pipeline.number>>"
6859

6960
steps:
7061
- run:
7162
name: Queue Until Front of Line
7263
command: <<include(../scripts/loop.bash)>>
73-
environment:
64+
environment:
7465
ONLY_ON_BRANCH: <<parameters.limit-branch-name>>
7566
BLOCK_WORKFLOW: <<parameters.block-workflow>>
7667
MAX_TIME: '<<parameters.max-wait-time>>'
@@ -84,6 +75,4 @@ steps:
8475
JOB_REGEXP: <<parameters.job-regex>>
8576
CIRCLECI_BASE_URL: https://<<parameters.circleci-hostname>>
8677
MY_PIPELINE_NUMBER: <<parameters.my-pipeline>>
87-
TRIGGER_SOURCE: <<parameters.trigger-source>>
8878
VCS_TYPE: <<parameters.vcs-type>>
89-
MY_BRANCH: <<parameters.my-branch>>

0 commit comments

Comments
 (0)