Skip to content

Commit

Permalink
feat: Changes parameters to fix production publishing (#126)
Browse files Browse the repository at this point in the history
* fix: publish dev only first

* fix: only run prod publish on tag, no branches

* docs: update usage examples

* fix: get issue count directly
  • Loading branch information
KyleTryon authored Mar 11, 2022
1 parent 17ad1d6 commit 084cc91
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,13 @@ workflows:
- orb-tools-alpha/publish:
orb-name: circleci/orb-tools
vcs-type: <<pipeline.project.type>>
pub-type: production
requires:
[orb-tools-alpha/lint, orb-tools-alpha/review, orb-tools-alpha/pack]
context: orb-publisher
github-token: GHI_TOKEN
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
33 changes: 26 additions & 7 deletions src/examples/step1_lint-pack.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,32 @@ usage:
version: 2.1
setup: true
orbs:
orb-tools: circleci/orb-tools@11.0
shellcheck: circleci/shellcheck@3.0
orb-tools: circleci/orb-tools@11.1
shellcheck: circleci/shellcheck@3.1

workflows:
lint-pack:
jobs:
- orb-tools/lint
- orb-tools/pack
- orb-tools/review
- orb-tools/lint:
filters:
tags:
only: /.*/
- orb-tools/pack:
filters:
tags:
only: /.*/
- orb-tools/review:
filters:
tags:
only: /.*/
- shellcheck/check:
exclude: SC2148,SC2038,SC2086,SC2002,SC2016
- orb-tools-/publish-dev:
filters:
tags:
only: /.*/
- orb-tools-/publish:
orb-name: circleci/orb-tools
vcs-type: << pipeline.project.type >>
requires:
[
orb-tools/lint,
Expand All @@ -31,8 +44,14 @@ usage:
]
# Use a context to hold your publishing token.
context: publishing-context
filters:
tags:
only: /.*/
# Triggers the next workflow in the Orb Development Kit.
- orb-tools-/continue:
pipeline-number: << pipeline.number >>
vcs-type: << pipeline.project.type >>
requires: [orb-tools-/publish-dev]
requires: [orb-tools-/publish]
filters:
tags:
only: /.*/
8 changes: 5 additions & 3 deletions src/examples/step2_test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ description: |
usage:
version: 2.1
orbs:
orb-tools: circleci/orb-tools@11.0
orb-tools: circleci/orb-tools@11.1
my-orb: namespace/my-orb@dev:<<pipeline.git.revision>>
jobs:
# Create a job to test the commands of your orbs.
Expand All @@ -33,12 +33,14 @@ usage:
tags:
only: /.*/
# Because our publishing job has a tag filter, we must also apply a filter to each job it depends on.
- orb-tools/publish-release:
- orb-tools/publish:
orb-name: namespace/my-orb
pub-type: production
vcs-type: <<pipeline.project.type>>
requires: [command-tests, my-orb/my-job]
context: orb-publisher
filters:
tags:
only: /^v.*/
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
branches:
ignore: /.*/
15 changes: 12 additions & 3 deletions src/jobs/publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
description: |
Publish a new version of your orb.
This job will produce a development version of an orb by default or will produce a new production version if the $CIRCLE_TAG environment variable is set.
Push a new semantic version tag to the repository to publish a new production version of your orb.
This job will produce a development version of an orb by default or will produce a new production version if the $CIRCLE_TAG environment variable is , and the "pub-type" parameter is set to "production".
executor: cli/default

Expand Down Expand Up @@ -41,6 +40,16 @@ parameters:
For GitHub users, a $GITHUB_TOKEN environment variable must be set.
type: boolean
default: true
pub-type:
description: |
Select the publishing type. Available options are "dev" and "production".
If "production" is selected, the orb will be published to the orb registry only if the $CIRCLE_TAG environment variable is set. Publishing will be skipped otherwise.
If "dev" is selected, two tags will be created: "dev:alpha" and "dev:<SHA1>".
type: enum
enum:
- dev
- production
default: "dev"
steps:
- attach_workspace:
at: <<parameters.orb-dir>>
Expand All @@ -50,6 +59,7 @@ steps:
ORB_PARAM_ORB_PUB_TOKEN: <<parameters.circleci-token>>
ORB_PARAM_ORB_NAME: <<parameters.orb-name>>
ORB_PARAM_ORB_DIR: <<parameters.orb-dir>>
ORB_PARAM_PUB_TYPE: <<parameters.pub-type>>
PARAM_GH_TOKEN: <<parameters.github-token>>
command: <<include(scripts/publish.sh)>>
- when:
Expand All @@ -63,4 +73,3 @@ steps:
ORB_PARAM_ORB_PUB_TOKEN: <<parameters.circleci-token>>
PIPELINE_VCS_TYPE: <<parameters.vcs-type>>
command: <<include(scripts/comment-pr.sh)>>

3 changes: 2 additions & 1 deletion src/scripts/comment-pr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function mainGitHub() {
echo "Authenticated as: $(isAuthenticatedGitHub | jq -r '.data.viewer.login')"
FetchedPRData="$(getGithubPRFromCommit)"
# Fetch the PR ID from the commit
if [ "$(echo "$FetchedPRData" | jq -e '.data.search.issueCount | length > 0')" ]; then
if [ "$(echo "$FetchedPRData" | jq -e '.data.search.issueCount')" -gt 0 ]; then
# PR Found
PR_COUNT=$(echo "$FetchedPRData" | jq -e '.data.search.issueCount')
echo "$PR_COUNT PR(s) found!"
Expand All @@ -59,6 +59,7 @@ function mainGitHub() {
echo "It may be that the PR has not yet been created from this commit at the time of this build."
echo "If you have recently created a PR, subsequent code pushes should properly identify the PR."
echo "Skipping commenting..."
exit 0
fi

else
Expand Down
31 changes: 19 additions & 12 deletions src/scripts/publish.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
#!/bin/bash
PUBLISH_PRODUCTION_ORB=false
ORB_RELEASE_VERSION=""
ORB_PARAM_ORB_PUB_TOKEN=${!ORB_PARAM_ORB_PUB_TOKEN}
mkdir -p /tmp/orb_dev_kit/

function validateProdTag() {
if [[ ! "${CIRCLE_TAG}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Malformed tag detected."
Expand Down Expand Up @@ -49,23 +44,35 @@ function publishDevOrbs() {
function orbPublish() {
echo "Preparing to publish your orb."
validateOrbPubToken
if [ -n "${CIRCLE_TAG}" ]; then
PUBLISH_PRODUCTION_ORB=true

if [ "$ORB_PARAM_PUB_TYPE" == "production" ]; then
echo "Production release detected!"
if [ -z "$CIRCLE_TAG" ]; then
echo "No tag detected. Peacfully exiting."
echo "If you are trying to publish a production orb, you must push a semantically versioned tag."
exit 0
fi
validateProdTag
ORB_RELEASE_VERSION="${CIRCLE_TAG//v/}"
echo "Production version: ${ORB_RELEASE_VERSION}"
fi
printf "\n"
if [ "${PUBLISH_PRODUCTION_ORB}" = true ]; then
printf "\n"
publishOrb "${ORB_RELEASE_VERSION}"
else
elif [ "$ORB_PARAM_PUB_TYPE" == "dev" ]; then
echo "Development release detected!"
printf "\n"
publishDevOrbs
else
echo "No release type detected."
echo "Please report this error."
fi
# print out the orb publishing message

printf "\n\n"
echo "********************************************************************************"
cat /tmp/orb_dev_kit/publishing_message.txt

}

ORB_RELEASE_VERSION=""
ORB_PARAM_ORB_PUB_TOKEN=${!ORB_PARAM_ORB_PUB_TOKEN}
mkdir -p /tmp/orb_dev_kit/
orbPublish

0 comments on commit 084cc91

Please sign in to comment.