Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
136 lines (119 sloc) 4.37 KB
version: 2.1
refs:
workspace-root: &workspace-root
~/repo
orbs:
orb-tools: circleci/orb-tools@8.27.1
circle-compare-url: iynere/compare-url@1.2.0
executors:
circleci_cli:
working_directory: *workspace-root
docker:
- image: circleci/circleci-cli:0.1.5705
environment:
SRC_DIR: src
DIST_DIR: packed
jobs:
pack:
executor: circleci_cli
parameters:
dist-dir:
type: env_var_name
default: DIST_DIR
steps:
- checkout
- circle-compare-url/reconstruct:
project-path: *workspace-root
- run:
shell: /bin/bash -euo pipefail
command: |
CIRCLE_COMPARE_URL=$(cat CIRCLE_COMPARE_URL.txt)
COMMIT_RANGE=$(echo $CIRCLE_COMPARE_URL | sed 's:^.*/compare/::g')
echo "Commit range: $COMMIT_RANGE"
mkdir -pv $<< parameters.dist-dir >>
for ORB in ${SRC_DIR}/*/; do
orbname=$(basename $ORB)
if [[ $(git diff $COMMIT_RANGE --name-status | grep "$orbname") ]]; then
orbpath=${DIST_DIR}/${orbname}/orb.yml
mkdir -pv $(dirname $orbpath)
circleci config pack ${SRC_DIR}/${orbname} > ${orbpath}
circleci orb validate ${orbpath}
else
echo "${orbname} not modified; no need to packing"
fi
echo "------------------------------------------------------"
done
- persist_to_workspace:
root: *workspace-root
paths:
- packed
release_dev:
executor: circleci_cli
steps:
- checkout
- attach_workspace:
at: *workspace-root
- circle-compare-url/reconstruct:
project-path: *workspace-root
- run:
shell: /bin/bash -euo pipefail
command: |
CIRCLE_COMPARE_URL=$(cat CIRCLE_COMPARE_URL.txt)
COMMIT_RANGE=$(echo $CIRCLE_COMPARE_URL | sed 's:^.*/compare/::g')
echo "Commit range: $COMMIT_RANGE"
for ORB in ${SRC_DIR}/*/; do
orbname=$(basename $ORB)
namespace=sugarshin/${orbname}
set +e
result=$(circleci orb info $namespace)
set -e
if [[ -z $result ]]; then
echo "Create new Orb:"
(circleci orb create $namespace --no-prompt --token $CIRCLE_TOKEN) || echo "${namespace} already creaed."
fi
if [[ $(git diff $COMMIT_RANGE --name-status | grep "$orbname") ]]; then
orbfile=${DIST_DIR}/${orbname}/orb.yml
(ls ${orbfile} && echo "orb.yml found, attempting to publish...") || echo "No orb.yml file was found - the next line is expected to fail."
circleci orb publish ${orbfile} sugarshin/${orbname}@dev:${CIRCLE_BRANCH}-${CIRCLE_SHA1:0:7} --token $CIRCLE_TOKEN
else
echo "${orbname} not modified; no need to promote"
fi
echo "------------------------------------------------------"
done
dev_promote_prod_patch:
executor: circleci_cli
steps:
- checkout
- circle-compare-url/reconstruct
- run:
shell: /bin/bash -euo pipefail
command: |
CIRCLE_COMPARE_URL=$(cat CIRCLE_COMPARE_URL.txt)
COMMIT_RANGE=$(echo $CIRCLE_COMPARE_URL | sed 's:^.*/compare/::g')
echo "Commit range: $COMMIT_RANGE"
for ORB in ${SRC_DIR}/*/; do
orbname=$(basename $ORB)
if [[ $(git diff $COMMIT_RANGE --name-status | grep "$orbname") ]]; then
echo "promoting sugarshin/${orbname}@dev:${CIRCLE_BRANCH}-${CIRCLE_SHA1:0:7} as patch release"
circleci orb publish promote sugarshin/${orbname}@dev:${CIRCLE_BRANCH}-${CIRCLE_SHA1:0:7} patch --token $CIRCLE_TOKEN
else
echo "${orbname} not modified; no need to promote"
fi
echo "------------------------------------------------------"
done
workflows:
lint_pack_publish-dev_promote-prod:
jobs:
- orb-tools/lint:
lint-dir: src
- pack
- release_dev:
requires:
- orb-tools/lint
- pack
- dev_promote_prod_patch:
requires:
- release_dev
filters:
branches:
only: master
You can’t perform that action at this time.