Skip to content

Commit

Permalink
feat: custom publishing tag pattern (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleTryon authored Dec 19, 2022
1 parent b2058d6 commit fbf8a7e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
9 changes: 9 additions & 0 deletions src/jobs/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ parameters:
description: Directory containing packed orb source. Path must be absolute or relative to the working directory. Should match the "output-dir" of the "pack" job.
type: string
default: ./dist/
tag-pattern:
description: |
A Regular Expression to compare against `$CIRCLE_TAG` when publishing a production version of an orb.
Your tag must include a full semantic version number, which will be used to automatically version the published orb.
Ensure you CircleCI config is also properly configured to trigger for this tag pattern.
It is recommended to prefix or suffix around this pattern: '[0-9]+\.[0-9]+\.[0-9]'.
default: '^v[0-9]+\.[0-9]+\.[0-9]+$'
type: string
circleci-token:
description: |
Enter the name of the environment variable containing your CircleCI API Token.
Expand Down Expand Up @@ -84,6 +92,7 @@ steps:
ORB_PARAM_ORB_NAME: <<parameters.orb-name>>
ORB_PARAM_ORB_DIR: <<parameters.orb-dir>>
ORB_PARAM_PUB_TYPE: <<parameters.pub-type>>
ORB_PARAM_TAG_PATTERN: <<parameters.tag-pattern>>
PARAM_GH_TOKEN: <<parameters.github-token>>
CIRCLECI_API_HOST: <<parameters.circleci-api-host>>
command: <<include(scripts/publish.sh)>>
Expand Down
7 changes: 4 additions & 3 deletions src/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/bin/bash
function validateProdTag() {
if [[ ! "${CIRCLE_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
if [[ ! "${CIRCLE_TAG}" =~ $ORB_PARAM_TAG_PATTERN ]]; then
echo "Malformed tag detected."
echo "Tag: $CIRCLE_TAG"
echo
echo "Ensure your tag fits the standard semantic version form. Example: v1.0.0"
echo "A production release has attempted to occur, but the tag does not match the expected pattern."
echo "Aborting deployment. Push a new tag with the compatible form."
echo "Current tag pattern: $ORB_PARAM_TAG_PATTERN"
exit 1
fi
}
Expand Down Expand Up @@ -53,7 +54,7 @@ function orbPublish() {
exit 0
fi
validateProdTag
ORB_RELEASE_VERSION="${CIRCLE_TAG//v/}"
ORB_RELEASE_VERSION="$(echo "${CIRCLE_TAG}" | grep -Eo "[0-9]+\.[0-9]+\.[0-9]")"
echo "Production version: ${ORB_RELEASE_VERSION}"
printf "\n"
publishOrb "${ORB_RELEASE_VERSION}"
Expand Down

0 comments on commit fbf8a7e

Please sign in to comment.