Last active
July 5, 2021 06:57
-
-
Save yusukegoto/10eb16dcff82bd4ec88e5cb9dd385548 to your computer and use it in GitHub Desktop.
Approval CircleCI config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: 2.1 | |
orbs: | |
queue: eddiewebb/queue@1.5.0 | |
parameters: | |
is_deploying: | |
default: false | |
type: boolean | |
build_python: | |
default: false | |
type: boolean | |
build_nodejs: | |
default: false | |
type: boolean | |
build_ruby: | |
default: false | |
type: boolean | |
workflows: | |
version: 2 | |
repeatedly: | |
triggers: | |
- schedule: | |
cron: '0 0 * * *' | |
filters: | |
branches: | |
only: | |
- master | |
jobs: | |
- build_python | |
develop: | |
unless: << pipeline.parameters.is_deploying >> | |
jobs: | |
- tests | |
- trigger_deploy: | |
filters: | |
branches: | |
only: | |
- master | |
requires: | |
- tests | |
deploy: | |
when: << pipeline.parameters.is_deploying >> | |
jobs: | |
- request_approval: | |
build_python: << pipeline.parameters.build_python >> | |
build_nodejs: << pipeline.parameters.build_nodejs >> | |
build_ruby: << pipeline.parameters.build_ruby >> | |
- hold: | |
type: approval | |
requires: | |
- request_approval | |
- queue/block_workflow: | |
time: '60' | |
requires: | |
- hold | |
- increment_version: | |
requires: | |
- queue/block_workflow | |
- setup_deploy: | |
requires: | |
- increment_version | |
- build_python: | |
requires: | |
- setup_deploy | |
build: << pipeline.parameters.build_python >> | |
- build_nodejs: | |
requires: | |
- setup_deploy | |
build: << pipeline.parameters.build_nodejs >> | |
- build_ruby: | |
requires: | |
- setup_deploy | |
build: << pipeline.parameters.build_ruby >> | |
- finish_deploy: | |
requires: | |
- build_python | |
- build_nodejs | |
- build_ruby | |
jobs: | |
build_python: | |
parameters: | |
build: | |
type: boolean | |
default: false | |
executor: python | |
steps: | |
- unless: | |
condition: << parameters.build >> | |
steps: | |
- run: echo "Nothing to do" | |
- when: | |
condition: << parameters.build >> | |
steps: | |
- setup_python | |
- run: python -V | |
- run: sleep 10 | |
- run: pip list | |
build_nodejs: | |
parameters: | |
build: | |
type: boolean | |
default: false | |
executor: nodejs | |
steps: | |
- unless: | |
condition: << parameters.build >> | |
steps: | |
- run: echo 'Nothing to do' | |
- when: | |
condition: << parameters.build >> | |
steps: | |
- setup_nodejs | |
- run: sleep 10 | |
- run: npm list | |
build_ruby: | |
parameters: | |
build: | |
type: boolean | |
default: false | |
executor: ruby | |
steps: | |
- unless: | |
condition: << parameters.build >> | |
steps: | |
- run: echo 'Nothing to do' | |
- when: | |
condition: << parameters.build >> | |
steps: | |
- setup_ruby | |
- run: sleep 10 | |
- run: bundle exec gem list | |
tests: | |
executor: python | |
parameters: | |
circleci-api-key: | |
type: env_var_name | |
default: CIRCLECI_API_KEY | |
steps: | |
- run: | | |
echo "This will be masked: ${<< parameters.circleci-api-key >>}." | |
- run: sleep 10 | |
increment_version: | |
machine: true | |
parameters: | |
github_api_token: | |
type: env_var_name | |
default: GITHUB_API_TOKEN | |
steps: | |
- checkout | |
- run: | |
name: update version | |
command: | | |
if [ "$CIRCLE_BRANCH" = 'master' ]; then | |
git config user.name 'circleci' | |
git config user.email 'circleci@yusuke-goto.info' | |
VERSION=$(cat ./version.txt) | |
NEW_VERSION=$(expr ${VERSION} + 1) | |
echo ${NEW_VERSION} > ./version.txt | |
git commit -a -m 'Increment version [skip ci]' | |
git tag v$(date '+%Y%m%d%H%M') | |
REPO_URL="https://${<< parameters.github_api_token >>}@github.com/yusukegoto/deployment.git" | |
git push ${REPO_URL} | |
git push ${REPO_URL} --tags | |
else | |
echo 'NOT INCREMENT!!!' | |
fi | |
request_approval: | |
machine: true | |
parameters: | |
build_python: | |
type: boolean | |
default: false | |
build_nodejs: | |
type: boolean | |
default: false | |
build_ruby: | |
type: boolean | |
default: false | |
steps: | |
- run: | |
name: Notify slack | |
command: | | |
echo 'Hey' > slack_content.txt | |
if << parameters.build_python >>; then | |
echo 'python' >> slack_content.txt | |
fi | |
if << parameters.build_nodejs >>; then | |
echo 'nodejs' >> slack_content.txt | |
fi | |
if << parameters.build_ruby >>; then | |
echo 'ruby' >> slack_content.txt | |
fi | |
echo "will deploy! | |
Please approve workflow from <https://circleci.com/workflow-run/${CIRCLE_WORKFLOW_ID}|here>. | |
" >> slack_content.txt | |
curl -X POST -H 'Content-type: application/json' \ | |
--data "{\"text\": \"$(cat ./slack_content.txt)\"}" \ | |
$SLACK_WEBHOOK_URL | |
trigger_deploy: | |
machine: true | |
parameters: | |
circleci_token: | |
type: env_var_name | |
default: CIRCLECI_API_KEY | |
steps: | |
- run: | |
name: Generate deploying components | |
command: | | |
[ -f deploying.txt ] && rm deploying.txt | |
if [ $(($RANDOM % 2)) = 0 ]; then | |
echo '"build_python": true,' >> deploying.txt | |
else | |
echo '"build_python": false,' >> deploying.txt | |
fi | |
if [ $(($RANDOM % 2)) = 0 ]; then | |
echo '"build_nodejs": true,' >> deploying.txt | |
else | |
echo '"build_nodejs": false,' >> deploying.txt | |
fi | |
if [ $(($RANDOM % 2)) = 0 ]; then | |
echo '"build_ruby": true,' >> deploying.txt | |
else | |
echo '"build_ruby": false,' >> deploying.txt | |
fi | |
cat ./deploying.txt | |
- run: | |
name: Call api with parameters | |
command: | | |
curl -X POST \ | |
-u ${<< parameters.circleci_token >>}: \ | |
--header "Content-Type: application/json" \ | |
--header "Accept: text/plain" \ | |
-d "{ | |
\"branch\": \"<< pipeline.git.branch >>\", | |
\"parameters\": { | |
$(cat ./deploying.txt) | |
\"is_deploying\": true | |
} | |
}" https://circleci.com/api/v2/project/gh/yusukegoto/deployment/pipeline | |
setup_deploy: | |
machine: true | |
steps: | |
- run: echo "Start setup" | |
finish_deploy: | |
machine: true | |
steps: | |
- run: | | |
echo "DEPLOYMENT FINISHED!" | |
executors: | |
python: | |
docker: | |
- image: python:3.8.8 | |
nodejs: | |
docker: | |
- image: node:16.2.0 | |
ruby: | |
docker: | |
- image: ruby:3.0.1-alpine3.12 | |
commands: | |
setup_python: | |
steps: | |
- checkout | |
- run: pip install -U pip pipenv | |
- run: pipenv sync -d | |
setup_nodejs: | |
steps: | |
- checkout | |
- run: npm install | |
setup_ruby: | |
steps: | |
- checkout | |
- run: bundle install --path=vendor/bundle |
I added them to confirm queue orb behavior with assuming long task.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's the purpose of
- run: sleep 10
on L109, L127 and L145?