Skip to content

feat!: migrate to orb tools 11 | 2.0 release #42

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

Merged
merged 25 commits into from
Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
160 changes: 25 additions & 135 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,145 +1,35 @@
version: 2.1

# add your orb below, to be used in integration tests (note: a @dev:alpha
# release must exist.);
setup: true
orbs:
heroku: circleci/heroku@<<pipeline.parameters.dev-orb-version>>
orb-tools: circleci/orb-tools@10

# Pipeline parameters
parameters:
run-integration-tests:
description: An internal flag to prevent integration test from running before a development version has been created.
type: boolean
default: false
dev-orb-version:
description: >
The development version of the orb to test.
This value is automatically adjusted by the "trigger-integration-tests-workflow" job to correspond with the specific version created by the commit and should not be edited.
A "dev:alpha" version must exist for the initial pipeline run.
type: string
default: "dev:alpha"
orb-tools: circleci/[email protected]
shellcheck: circleci/[email protected]

jobs:
# This job is an example of an integration testing job.
# This job should execute a command from your orb and verify
# the output is as expected, otherwise the job should fail.
#
# Rename this job and add more as needed.
#
integration-test-1:
executor: heroku/default
steps:
- checkout
- heroku/install
- run:
name: Check if Heroku is installed
command: |
if [[ $(command -v heroku) == "" ]]; then
echo " Heroku is not installed! "; exit 1;
else
echo Heroku successfully installed.
fi
integration-test-review:
executor: heroku/default
steps:
- run:
name: Setup sample project
command: |
git clone --depth 1 https://github.com/CircleCI-Public/sample-python-cfd.git --branch main ~/project
git branch $CIRCLE_BRANCH
- run:
name: Bundle sample project
working_directory: ~/
command: tar -czvf sample-python-cfd.tar.gz ~/project
- store_artifacts:
path: ~/sample-python-cfd.tar.gz
- heroku/create-review:
artifact-pattern: "*.tar.gz"
pipeline: 389303dc-8a12-4f25-b943-8f7c6dbbdcaa
circleci-api-key: CIRCLE_TOKEN
integration-test-deploy:
executor: heroku/default
steps:
- run:
name: Setup sample project
command: |
git clone --depth 1 https://github.com/CircleCI-Public/sample-python-cfd.git --branch main ~/project
git branch $CIRCLE_BRANCH
- heroku/install
- heroku/check-authentication
- heroku/deploy-via-git:
force: true
app-name: sample-python-cfd
filters: &filters
tags:
only: /.*/

workflows:
# This `lint-pack_validate_publish-dev` workflow will run on any commit.
lint_pack-validate_publish-dev:
unless: << pipeline.parameters.run-integration-tests >>
lint-pack:
jobs:
- orb-tools/lint
# pack your orb YAML files to a single orb.yml
# validate the orb.yml file to ensure it is well-formed
- orb-tools/lint:
filters: *filters
- orb-tools/pack:
requires:
- orb-tools/lint

# release dev version of orb, for testing & possible publishing.
# orb will be published as dev:alpha and dev:${CIRCLE_SHA1:0:7}.
# requires a CircleCI API token to be stored as CIRCLE_TOKEN (default)
# https://circleci.com/docs/2.0/managing-api-tokens
# store CIRCLE_TOKEN as a project env var or Contexts resource
# if using Contexts, add your context below
- orb-tools/publish-dev:
filters: *filters
- orb-tools/review:
filters: *filters
- shellcheck/check:
filters: *filters
- orb-tools/publish:
orb-name: circleci/heroku
context: orb-publisher
vcs-type: << pipeline.project.type >>
requires:
- orb-tools/pack

# trigger an integration workflow to test the
# dev:${CIRCLE_SHA1:0:7} version of your orb
- orb-tools/trigger-integration-tests-workflow:
name: trigger-integration-dev
[orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check]
# Use a context to hold your publishing token.
context: orb-publisher
requires:
- orb-tools/publish-dev

# This `integration-tests_prod-release` workflow will only run
# when the run-integration-tests pipeline parameter is set to true.
# It is meant to be triggered by the "trigger-integration-tests-workflow"
# job, and run tests on <your orb>@dev:${CIRCLE_SHA1:0:7}.
integration-tests_prod-release:
when: << pipeline.parameters.run-integration-tests >>
jobs:
# your integration test jobs go here: essentially, run all your orb's
# jobs and commands to ensure they behave as expected. or, run other
# integration tests of your choosing

# an example job
- integration-test-1
- integration-test-deploy:
context: heroku-orb
- integration-test-review:
context:
- heroku-orb
- orb-publisher
# publish a semver version of the orb. relies on
# the commit subject containing the text "[semver:patch|minor|major|skip]"
# as that will determine whether a patch, minor or major
# version will be published or if publishing should
# be skipped.
# e.g. [semver:patch] will cause a patch version to be published.
- orb-tools/dev-promote-prod-from-commit-subject:
orb-name: circleci/heroku
context: orb-publisher
add-pr-comment: true
bot-token-variable: GHI_TOKEN
bot-user: orb-publisher
fail-if-semver-not-indicated: true
publish-version-tag: false
requires:
- integration-test-1
- integration-test-deploy
filters:
branches:
only: master
filters: *filters
# 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]
filters: *filters
86 changes: 86 additions & 0 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
version: 2.1
orbs:
heroku: circleci/heroku@dev:<<pipeline.git.revision>>
orb-tools: circleci/[email protected]
filters: &filters
tags:
only: /.*/
jobs:
# This job is an example of an integration testing job.
# This job should execute a command from your orb and verify
# the output is as expected, otherwise the job should fail.
#
# Rename this job and add more as needed.
#
integration-test-1:
executor: heroku/default
steps:
- checkout
- heroku/install
- run:
name: Check if Heroku is installed
command: |
if [[ $(command -v heroku) == "" ]]; then
echo " Heroku is not installed! "; exit 1;
else
echo Heroku successfully installed.
fi
integration-test-review:
executor: heroku/default
steps:
- run:
name: Setup sample project
command: |
git clone https://github.com/CircleCI-Public/sample-python-cfd.git --branch main ~/project
git branch $CIRCLE_BRANCH
- run:
name: Bundle sample project
working_directory: ~/
command: tar -czvf sample-python-cfd.tar.gz ~/project
- store_artifacts:
path: ~/sample-python-cfd.tar.gz
- heroku/create-review:
artifact-pattern: "*.tar.gz"
pipeline: 389303dc-8a12-4f25-b943-8f7c6dbbdcaa
circleci-api-key: CIRCLE_TOKEN
integration-test-deploy:
executor: heroku/default
steps:
- run:
name: Setup sample project
command: |
git clone https://github.com/CircleCI-Public/sample-python-cfd.git --branch main ~/project
git branch $CIRCLE_BRANCH
- heroku/install
- heroku/check-authentication
- heroku/deploy-via-git:
force: true
app-name: sample-python-cfd
workflows:
test-deploy:
jobs:
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
- integration-test-1:
filters: *filters
- integration-test-review:
filters: *filters
context: orb-publisher
- integration-test-deploy:
filters: *filters
- orb-tools/pack:
filters: *filters
- orb-tools/publish:
orb-name: circleci/heroku
vcs-type: << pipeline.project.type >>
pub-type: production
requires:
- orb-tools/pack
- integration-test-1
- integration-test-review
- integration-test-deploy
context: orb-publisher
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extends: relaxed

rules:
line-length:
max: 200
allow-non-breakable-inline-mappings: true

14 changes: 3 additions & 11 deletions src/commands/check-authentication.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ parameters:

steps:
- run:
environment:
PARAM_WHOAMI: <<parameters.print-whoami>>
name: Verify HEROKU_API_KEY is set
command: |
if [[ $HEROKU_API_KEY == "" ]]; then
echo "No Heroku API key set, please set the HEROKU_API_KEY environment variable."
echo "This can be found by running the `heroku auth:token` command locally."
exit 1
else
echo "Heroku API key found."
<<#parameters.print-whoami>>
heroku auth:whoami
<</parameters.print-whoami>>
fi
command: <<include(scripts/check-auth.sh)>>
14 changes: 7 additions & 7 deletions src/commands/create-review.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ parameters:
description: RegEx or filename of artifact to deploy to Heroku.
pipeline:
type: string
description: Heroku pipeline to dpeloy with (UUID).
description: Heroku pipeline to deploy with (UUID).
heroku-api-key:
type: env_var_name
description: Environment variable containing the Heroku API key
description: The name of the environment variable containing your Heroku API Key.
default: HEROKU_API_KEY
circleci-api-key:
type: env_var_name
description: Environment variable containing the Heroku API key
default: CIRCLECI_API_KEY
default: CIRCLE_TOKEN
steps:
- run:
command: <<include(scripts/create-review.sh)>>
name: Create new Heroku Review app
environment:
C_API_KEY: $<<parameters.circleci-api-key>>
API_KEY: $<<parameters.heroku-api-key>>
ARTIFACT_PATTERN: <<parameters.artifact-pattern>>
HEROKU_PIPELINE: <<parameters.pipeline>>
PARAM_CIRCLE_TOKEN: <<parameters.circleci-api-key>>
PARAM_HEROKU_KEY: <<parameters.heroku-api-key>>
PARAM_ARTIFACT_PATTERN: <<parameters.artifact-pattern>>
PARAM_HEROKU_PIPELINE: <<parameters.pipeline>>
40 changes: 14 additions & 26 deletions src/commands/deploy-via-git.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,9 @@
description: >
Replace this text with a description for this command.
# What will this command do?
# Descriptions should be short, simple, and clear.
Use Git to push the changes of the current tag or branch to Heroku for deployment.
parameters:
app-name:
description:
"The name of your Heroku App.
For backwards compatibility the literal value
`$HEROKU_APP_NAME` is the default, so you can
easily use this command by setting an environment
variable called HEROKU_APP_NAME"
The name of your Heroku app. May also refer to an environment variable.
type: string
default: $HEROKU_APP_NAME
maintenance-mode:
Expand All @@ -22,12 +16,12 @@ parameters:
default: HEROKU_API_KEY
branch:
type: string
description: Deploy the given branch. The default value is your current branch.
default: "$CIRCLE_BRANCH"
description: Deploy the given branch. The default value is your current branch. Accepts strings which may contain an environment variable.
default: $CIRCLE_BRANCH
tag:
type: string
description: Deploy the given tag. The default value is your current tag.
default: "$CIRCLE_TAG"
default: $CIRCLE_TAG
force:
type: boolean
description: Whether or not to force the git push (i.e. `git push -f`). Defaults to false.
Expand All @@ -47,21 +41,15 @@ steps:
- run:
no_output_timeout: << parameters.no_output_timeout >>
name: Deploy branch or tag to Heroku via git push
command: |
if << parameters.force >>;then
force="-f"
fi

heroku_url="https://heroku:$<< parameters.api-key >>@git.heroku.com/<< parameters.app-name >>.git"

if [ -n "<< parameters.branch >>" ]; then
git push $force $heroku_url << parameters.branch >>:main
elif [ -n "<< parameters.tag >>" ]; then
git push $force $heroku_url << parameters.tag >>^{}:main
else
echo "No branch or tag found."
exit 1
fi
environment:
PARAM_APP_NAME: <<parameters.app-name>>
PARAM_MAINTENANCE_MODE: <<parameters.maintenance-mode>>
PARAM_HEROKU_API_KEY: <<parameters.api-key>>
PARAM_DEPLOY_BRANCH: <<parameters.branch>>
PARAM_DEPLOY_TAG: <<parameters.tag>>
PARAM_FORCE_PUSH: <<parameters.force>>
PARAM_NO_OUTPUT_TIMEOUT: <<parameters.no_output_timeout>>
command: <<include(scripts/deploy-via-git.sh)>>
- when:
condition: << parameters.maintenance-mode >>
steps:
Expand Down
7 changes: 1 addition & 6 deletions src/commands/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,4 @@ description: >
steps:
- run:
name: Install Heroku CLI (If not installed)
command: |
if [[ $(command -v heroku) == "" ]]; then
curl https://cli-assets.heroku.com/install.sh | sh
else
echo "Heroku is already installed. No operation was performed."
fi
command: <<include(scripts/install.sh)>>
Loading