From 084cc913590b9d60a509fe0452bbe82c84f073cf Mon Sep 17 00:00:00 2001 From: Kyle T <33272306+KyleTryon@users.noreply.github.com> Date: Fri, 11 Mar 2022 11:08:53 -0500 Subject: [PATCH] feat: Changes parameters to fix production publishing (#126) * fix: publish dev only first * fix: only run prod publish on tag, no branches * docs: update usage examples * fix: get issue count directly --- .circleci/test-deploy.yml | 4 ++++ src/examples/step1_lint-pack.yml | 33 +++++++++++++++++++++++------- src/examples/step2_test-deploy.yml | 8 +++++--- src/jobs/publish.yml | 15 +++++++++++--- src/scripts/comment-pr.sh | 3 ++- src/scripts/publish.sh | 31 +++++++++++++++++----------- 6 files changed, 68 insertions(+), 26 deletions(-) diff --git a/.circleci/test-deploy.yml b/.circleci/test-deploy.yml index fee3fc49..9e58f626 100755 --- a/.circleci/test-deploy.yml +++ b/.circleci/test-deploy.yml @@ -20,9 +20,13 @@ workflows: - orb-tools-alpha/publish: orb-name: circleci/orb-tools vcs-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]+$/ diff --git a/src/examples/step1_lint-pack.yml b/src/examples/step1_lint-pack.yml index ac91355b..7c7a1701 100644 --- a/src/examples/step1_lint-pack.yml +++ b/src/examples/step1_lint-pack.yml @@ -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, @@ -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: /.*/ diff --git a/src/examples/step2_test-deploy.yml b/src/examples/step2_test-deploy.yml index 3572e1db..9db5e7c4 100644 --- a/src/examples/step2_test-deploy.yml +++ b/src/examples/step2_test-deploy.yml @@ -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:<> jobs: # Create a job to test the commands of your orbs. @@ -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: <> requires: [command-tests, my-orb/my-job] context: orb-publisher filters: tags: - only: /^v.*/ + only: /^v[0-9]+\.[0-9]+\.[0-9]+$/ branches: ignore: /.*/ diff --git a/src/jobs/publish.yml b/src/jobs/publish.yml index 65dabfb0..42397e95 100644 --- a/src/jobs/publish.yml +++ b/src/jobs/publish.yml @@ -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 @@ -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:". + type: enum + enum: + - dev + - production + default: "dev" steps: - attach_workspace: at: <> @@ -50,6 +59,7 @@ steps: ORB_PARAM_ORB_PUB_TOKEN: <> ORB_PARAM_ORB_NAME: <> ORB_PARAM_ORB_DIR: <> + ORB_PARAM_PUB_TYPE: <> PARAM_GH_TOKEN: <> command: <> - when: @@ -63,4 +73,3 @@ steps: ORB_PARAM_ORB_PUB_TOKEN: <> PIPELINE_VCS_TYPE: <> command: <> - diff --git a/src/scripts/comment-pr.sh b/src/scripts/comment-pr.sh index ea8f7952..8454af4b 100644 --- a/src/scripts/comment-pr.sh +++ b/src/scripts/comment-pr.sh @@ -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!" @@ -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 diff --git a/src/scripts/publish.sh b/src/scripts/publish.sh index 6dbb78a0..63b210d8 100644 --- a/src/scripts/publish.sh +++ b/src/scripts/publish.sh @@ -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." @@ -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 \ No newline at end of file