Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom publishing tag pattern #180

Merged
merged 1 commit into from
Dec 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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