Skip to content

Commit

Permalink
Fix #4
Browse files Browse the repository at this point in the history
  • Loading branch information
matfax committed Nov 15, 2018
1 parent 1d74104 commit bb2aec2
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 136 deletions.
136 changes: 0 additions & 136 deletions src/@orb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,6 @@ executors:
- image: gofunky/orbtools:alpine<< parameters.alpine_version >>

commands:
env-publish:
description: Uses the CLI to publish an orb to the registry.
parameters:
orb-path:
description: The path to the orb file.
type: string
orb-ref:
description: >
A fully-qualified reference to an orb. This takes the form <namespace>/<orb-name>@<version>
NOTE: To publish a dev version prefix the version with 'dev:' like this: <namespace>/<orb-name>@dev:<label>
type: string
token-variable:
description: >
The env var containing your token. Pass this as a literal string such
as `$ORB_PUBLISHING_TOKEN`. Do not paste the actual token into your
configuration. If omitted it's assumed the CLI has already been setup
with a valid token.
type: string
default: ""
steps:
- run:
name: >
Publish orb at << parameters.orb-path >> to << parameters.orb-ref >>
NOTE: this currently assumes you are publishing to the registry at circleci.com
command: |
source /usr/local/bin/envload
export REPOSITORY_ORGANIZATION=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f3 | rev)
echo "SET REPOSITORY_ORGANIZATION: ${REPOSITORY_ORGANIZATION}"
export REPOSITORY_NAME=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f2 | rev)
echo "SET REPOSITORY_NAME: ${REPOSITORY_NAME}"
circleci orb publish << parameters.orb-path >> << parameters.orb-ref >> <<# parameters.token-variable >>--token << parameters.token-variable >> <</ parameters.token-variable >>
pack:
description: >
*Experimental*
Expand Down Expand Up @@ -413,107 +381,3 @@ jobs:
steps:
- store_artifacts:
path: << parameters.destination-file >>

env-pack-publish:
description: Pack the contents of an orb for publishing and publish it.
parameters:
<<: [*alpine_params]
source-dir:
description: >
Path to the root of the orb source directory to be packed.
By default, `src/` is assumed.
type: string
default: src/
destination-file:
description: Path including filename of where the packed orb will be written.
type: string
default: ./.orbspace/orb.yml
validate:
description: Boolean for whether or not to do validation on the orb. Default is true.
type: boolean
default: true
checkout:
description: Boolean for whether or not to checkout as a first step. Default is true.
type: boolean
default: true
attach-at:
description: >
Workspace root path that is either an absolute path or a path relative
to the working directory. Defaults to '.' (the working directory).
type: string
default: "."
persist:
description: If enabled, the destination-file will be persisted.
type: boolean
default: false
store-artifact:
description: If enabled, the destination-file will be stored as artifact.
type: boolean
default: true
namespace:
description: >
The namespace of your orb.
Environment variables from an envorb are accepted.
By default, the git organization is assumed.
type: string
default: "${REPOSITORY_ORGANIZATION}"
orb-name:
description: >
The name of your orb.
Environment variables from an envorb are accepted.
By default, the git repository name is assumed.
type: string
default: "${REPOSITORY_NAME}"
version:
description: >
The publishing version of your orb.
Either use an incrementing semantic version (e.g., 1.0.0), or a development version as `dev:<label>`,
where `label` can be any alphanumeric string.
Environment variables from an envorb are accepted.
By default, the environment variable `$ORB_PUBLISHING_VERSION` is assumed.
type: string
default: "${ORB_PUBLISHING_VERSION}"
publish-token-variable:
description: >
The env var containing your publish token. Pass this as a literal string such
as `$ORB_PUBLISHING_TOKEN`. DO NOT paste the actual token into your
configuration. If omitted it's assumed the CLI has already been setup
with a valid token.
By default, an environment variable `$ORB_PUBLISHING_TOKEN` is expected.
Make sure to pass a context to this job that contains the variable.
type: string
default: "${ORB_PUBLISHING_TOKEN}"
executor:
name: default
<<: *alpine_args
steps:
- when:
condition: << parameters.checkout >>
steps:
- checkout
- attach_workspace:
at: << parameters.attach-at >>
- pack:
source: << parameters.source-dir >>
destination: << parameters.destination-file >>
- when:
condition: << parameters.validate >>
steps:
- validate:
orb-path: << parameters.destination-file >>
- env-publish:
orb-path: << parameters.destination-file >>
orb-ref: "<< parameters.namespace >>/<< parameters.orb-name >>@<< parameters.version >>"
token-variable: << parameters.publish-token-variable >>
- when:
condition: << parameters.persist >>
steps:
- persist_to_workspace:
root: << parameters.attach-at >>
paths:
- << parameters.destination-file >>
- when:
condition: << parameters.store-artifact >>
steps:
- store_artifacts:
path: << parameters.destination-file >>
30 changes: 30 additions & 0 deletions src/commands/env-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
description: Uses the CLI to publish an orb to the registry.
parameters:
orb-path:
description: The path to the orb file.
type: string
orb-ref:
description: >
A fully-qualified reference to an orb. This takes the form <namespace>/<orb-name>@<version>
NOTE: To publish a dev version prefix the version with 'dev:' like this: <namespace>/<orb-name>@dev:<label>
type: string
token-variable:
description: >
The env var containing your token. Pass this as a literal string such
as `$ORB_PUBLISHING_TOKEN`. Do not paste the actual token into your
configuration. If omitted it's assumed the CLI has already been setup
with a valid token.
type: string
default: ""
steps:
- run:
name: >
Publish orb at << parameters.orb-path >> to << parameters.orb-ref >>
NOTE: this currently assumes you are publishing to the registry at circleci.com
command: |
source /usr/local/bin/envload
export REPOSITORY_ORGANIZATION=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f3 | rev)
echo "SET REPOSITORY_ORGANIZATION: ${REPOSITORY_ORGANIZATION}"
export REPOSITORY_NAME=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f2 | rev)
echo "SET REPOSITORY_NAME: ${REPOSITORY_NAME}"
circleci orb publish << parameters.orb-path >> << parameters.orb-ref >> <<# parameters.token-variable >>--token << parameters.token-variable >> <</ parameters.token-variable >>
13 changes: 13 additions & 0 deletions src/commands/env-templater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
description: Replaces all template variables with the respective environment variables.
parameters:
orb-path:
description: The path to the orb file.
type: string
steps:
- run:
name: >
Loads all environment variables from previous envorb calls and replaces all template variables `{{VAR}}` with
the respective environment variables `${VAR}`.
command: |
source /usr/local/bin/envload
templater << parameters.orb-path >>
123 changes: 123 additions & 0 deletions src/jobs/env-pack-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
alpine_params: &alpine_params
alpine_version:
description: >
Alpine version
type: string
default: ""

alpine_args: &alpine_args
alpine_version: << parameters.alpine_version >>

description: Pack the contents of an orb for publishing and publish it.
parameters:
<<: [*alpine_params]
source-dir:
description: >
Path to the root of the orb source directory to be packed.
By default, `src/` is assumed.
type: string
default: src/
destination-file:
description: Path including filename of where the packed orb will be written.
type: string
default: ./.orbspace/orb.yml
validate:
description: Boolean for whether or not to do validation on the orb. Default is true.
type: boolean
default: true
checkout:
description: Boolean for whether or not to checkout as a first step. Default is true.
type: boolean
default: true
attach-at:
description: >
Workspace root path that is either an absolute path or a path relative
to the working directory. Defaults to '.' (the working directory).
type: string
default: "."
persist:
description: If enabled, the destination-file will be persisted.
type: boolean
default: false
store-artifact:
description: If enabled, the destination-file will be stored as artifact.
type: boolean
default: true
namespace:
description: >
The namespace of your orb.
Environment variables from an envorb are accepted.
By default, the git organization is assumed.
type: string
default: "${REPOSITORY_ORGANIZATION}"
orb-name:
description: >
The name of your orb.
Environment variables from an envorb are accepted.
By default, the git repository name is assumed.
type: string
default: "${REPOSITORY_NAME}"
version:
description: >
The publishing version of your orb.
Either use an incrementing semantic version (e.g., 1.0.0), or a development version as `dev:<label>`,
where `label` can be any alphanumeric string.
Environment variables from an envorb are accepted.
By default, the environment variable `$ORB_PUBLISHING_VERSION` is assumed.
type: string
default: "${ORB_PUBLISHING_VERSION}"
publish-token-variable:
description: >
The env var containing your publish token. Pass this as a literal string such
as `$ORB_PUBLISHING_TOKEN`. DO NOT paste the actual token into your
configuration. If omitted it's assumed the CLI has already been setup
with a valid token.
By default, an environment variable `$ORB_PUBLISHING_TOKEN` is expected.
Make sure to pass a context to this job that contains the variable.
type: string
default: "${ORB_PUBLISHING_TOKEN}"
patch-environment-variables:
description: >
To replace all template variables with the respective environment variables.
Variables have to be defined in the format `{{VAR}}`.
type: boolean
default: true
executor:
name: default
<<: *alpine_args
steps:
- when:
condition: << parameters.checkout >>
steps:
- checkout
- attach_workspace:
at: << parameters.attach-at >>
- pack:
source: << parameters.source-dir >>
destination: << parameters.destination-file >>
- when:
condition: << parameters.patch-environment-variables >>
steps:
- env-templater:
orb-path: << parameters.destination-file >>
- when:
condition: << parameters.validate >>
steps:
- validate:
orb-path: << parameters.destination-file >>
- env-publish:
orb-path: << parameters.destination-file >>
orb-ref: "<< parameters.namespace >>/<< parameters.orb-name >>@<< parameters.version >>"
token-variable: << parameters.publish-token-variable >>
- when:
condition: << parameters.persist >>
steps:
- persist_to_workspace:
root: << parameters.attach-at >>
paths:
- << parameters.destination-file >>
- when:
condition: << parameters.store-artifact >>
steps:
- store_artifacts:
path: << parameters.destination-file >>

0 comments on commit bb2aec2

Please sign in to comment.