CircleCIのOrbをPublishする
circleciCircleCI CLIをインストールする。
$ brew install circleci
マニュアルで circleci orb pack して circleci orb publish
することもできるが、
Orb development kitを使うのが推奨されているのでそうする。
$ circleci orb pack ./src
version: 2.1
description: |
Sample orb description
display:
home_url: https://www.website.com/docs
source_url: https://www.github.com/EXAMPLE_ORG/EXAMPLE_PROJECT
commands:
greet:
description: |
This command echos "Hello World" using file inclusion.
parameters:
to:
default: World
description: Hello to whom?
type: string
steps:
- run:
command: |
Greet() {
echo Hello "${PARAM_TO}"
}
# Will not run if sourced for bats-core tests.
# View src/tests for more information.
ORB_TEST_ENV="bats-core"
if [ "${0#*$ORB_TEST_ENV}" == "$0" ]; then
Greet
fi
environment:
PARAM_TO: <<parameters.to>>
name: Hello Greeting
executors:
default:
...
jobs:
...
examples:
...
circleci orb init
でテンプレートを持ってきてOrbのnamespaceや名前などを設定する。
Personal API TokensはUser Settingsから発行できて、CIRCLE_TOKEN入りのorb-publishing contextが作られる。
$ circleci orb init test-orb
Note: This command is in preview. Please report any bugs! https://github.com/CircleCI-Public/circleci-cli/issues/new/choose
? Would you like to perform an automated setup of this orb? Yes, walk me through the process.
Downloading Orb Project Template into test-orb
A few questions to get you up and running.
? Are you using GitHub or Bitbucket? GitHub
? Enter your github username or organization sambaiz
? Enter the namespace to use for this orb sambaiz
Saving namespace sambaiz as default
? Orb name test-orb
? What categories will this orb belong to?
? Automatically set up a publishing context for your orb? Yes, set up a publishing context with my API key.
? Would you like to set up your git project? Yes
? Enter your primary git branch. main
? Enter the remote git repository git@github.com:sambaiz/circleci-orb-test.git
Thank you! Setting up your orb...
An initial commit has been created - please run 'git push origin main' to publish your first commit!
? I have pushed to my git repository using the above command No
Your orb project is building here: https://circleci.com/gh/sambaiz/circleci-orb-test
You are now working in the alpha branch.
Once the first public version is published, you'll be able to see it here: https://circleci.com/developer/orbs/orb/sambaiz/test-orb
View orb publishing doc: https://circleci.com/docs/2.0/orb-author
pushすると @dev:alpha
で publishされる。dev:から始まるバージョンは上書きできて90日で無効になる。
$ cat test-orb/.circleci/config.yml
version: 2.1
orbs:
# Replace this with your own!
test-orb: sambaiz/test-orb@<<pipeline.parameters.dev-orb-version>>
orb-tools: circleci/[email protected]
bats: circleci/[email protected]
shellcheck: circleci/[email protected]
# Pipeline Parameters
## These parameters are used internally by orb-tools. Skip to the Jobs section.
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"
jobs:
# Define one or more jobs which will utilize your orb's commands and parameters to validate your changes.
integration-test-1:
docker:
- image: cimg/base:stable
steps:
- checkout
# "greet" is a sample command packaged with this orb config.
# This sample integration test will run as long as the greet command exists. Once you remove the greet command you should remove this line.
# Push new changes first, before adding new tests to your config.
- test-orb/greet
workflows:
# Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed.
# This workflow will run on every commit
test-pack:
unless: << pipeline.parameters.run-integration-tests >>
jobs:
- orb-tools/lint # Lint Yaml files
- orb-tools/pack # Pack orb source
- shellcheck/check:
dir: ./src/scripts
exclude: SC2148
# optional: Run BATS tests against your scripts
- bats/run:
path: ./src/tests
# Publish development version(s) of the orb.
- orb-tools/publish-dev:
orb-name: sambaiz/test-orb
context: orb-publishing # A restricted context containing your private publishing credentials. Will only execute if approved by an authorized user.
requires:
- orb-tools/lint
- orb-tools/pack
- bats/run
- shellcheck/check
# 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
context: orb-publishing
requires:
- orb-tools/publish-dev
# This `integration-test_deploy` 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-test_deploy:
when: << pipeline.parameters.run-integration-tests >>
jobs:
# Run any integration tests defined within the `jobs` key.
- integration-test-1
# 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: sambaiz/test-orb
context: orb-publishing
add-pr-comment: false
fail-if-semver-not-indicated: true
publish-version-tag: false
requires:
- integration-test-1
filters:
branches:
only:
- master
- main
commitのタイトルに [semver:patch|minor|major|skip]
を含めるとdevでないバージョンがpublishされる。