Skip to content

Commit bb2aec2

Browse files
committed
Fix #4
1 parent 1d74104 commit bb2aec2

File tree

4 files changed

+166
-136
lines changed

4 files changed

+166
-136
lines changed

src/@orb.yml

Lines changed: 0 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,6 @@ executors:
1818
- image: gofunky/orbtools:alpine<< parameters.alpine_version >>
1919

2020
commands:
21-
env-publish:
22-
description: Uses the CLI to publish an orb to the registry.
23-
parameters:
24-
orb-path:
25-
description: The path to the orb file.
26-
type: string
27-
orb-ref:
28-
description: >
29-
A fully-qualified reference to an orb. This takes the form <namespace>/<orb-name>@<version>
30-
NOTE: To publish a dev version prefix the version with 'dev:' like this: <namespace>/<orb-name>@dev:<label>
31-
type: string
32-
token-variable:
33-
description: >
34-
The env var containing your token. Pass this as a literal string such
35-
as `$ORB_PUBLISHING_TOKEN`. Do not paste the actual token into your
36-
configuration. If omitted it's assumed the CLI has already been setup
37-
with a valid token.
38-
type: string
39-
default: ""
40-
steps:
41-
- run:
42-
name: >
43-
Publish orb at << parameters.orb-path >> to << parameters.orb-ref >>
44-
NOTE: this currently assumes you are publishing to the registry at circleci.com
45-
command: |
46-
source /usr/local/bin/envload
47-
export REPOSITORY_ORGANIZATION=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f3 | rev)
48-
echo "SET REPOSITORY_ORGANIZATION: ${REPOSITORY_ORGANIZATION}"
49-
export REPOSITORY_NAME=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f2 | rev)
50-
echo "SET REPOSITORY_NAME: ${REPOSITORY_NAME}"
51-
circleci orb publish << parameters.orb-path >> << parameters.orb-ref >> <<# parameters.token-variable >>--token << parameters.token-variable >> <</ parameters.token-variable >>
52-
5321
pack:
5422
description: >
5523
*Experimental*
@@ -413,107 +381,3 @@ jobs:
413381
steps:
414382
- store_artifacts:
415383
path: << parameters.destination-file >>
416-
417-
env-pack-publish:
418-
description: Pack the contents of an orb for publishing and publish it.
419-
parameters:
420-
<<: [*alpine_params]
421-
source-dir:
422-
description: >
423-
Path to the root of the orb source directory to be packed.
424-
By default, `src/` is assumed.
425-
type: string
426-
default: src/
427-
destination-file:
428-
description: Path including filename of where the packed orb will be written.
429-
type: string
430-
default: ./.orbspace/orb.yml
431-
validate:
432-
description: Boolean for whether or not to do validation on the orb. Default is true.
433-
type: boolean
434-
default: true
435-
checkout:
436-
description: Boolean for whether or not to checkout as a first step. Default is true.
437-
type: boolean
438-
default: true
439-
attach-at:
440-
description: >
441-
Workspace root path that is either an absolute path or a path relative
442-
to the working directory. Defaults to '.' (the working directory).
443-
type: string
444-
default: "."
445-
persist:
446-
description: If enabled, the destination-file will be persisted.
447-
type: boolean
448-
default: false
449-
store-artifact:
450-
description: If enabled, the destination-file will be stored as artifact.
451-
type: boolean
452-
default: true
453-
namespace:
454-
description: >
455-
The namespace of your orb.
456-
Environment variables from an envorb are accepted.
457-
By default, the git organization is assumed.
458-
type: string
459-
default: "${REPOSITORY_ORGANIZATION}"
460-
orb-name:
461-
description: >
462-
The name of your orb.
463-
Environment variables from an envorb are accepted.
464-
By default, the git repository name is assumed.
465-
type: string
466-
default: "${REPOSITORY_NAME}"
467-
version:
468-
description: >
469-
The publishing version of your orb.
470-
Either use an incrementing semantic version (e.g., 1.0.0), or a development version as `dev:<label>`,
471-
where `label` can be any alphanumeric string.
472-
Environment variables from an envorb are accepted.
473-
By default, the environment variable `$ORB_PUBLISHING_VERSION` is assumed.
474-
type: string
475-
default: "${ORB_PUBLISHING_VERSION}"
476-
publish-token-variable:
477-
description: >
478-
The env var containing your publish token. Pass this as a literal string such
479-
as `$ORB_PUBLISHING_TOKEN`. DO NOT paste the actual token into your
480-
configuration. If omitted it's assumed the CLI has already been setup
481-
with a valid token.
482-
By default, an environment variable `$ORB_PUBLISHING_TOKEN` is expected.
483-
Make sure to pass a context to this job that contains the variable.
484-
type: string
485-
default: "${ORB_PUBLISHING_TOKEN}"
486-
executor:
487-
name: default
488-
<<: *alpine_args
489-
steps:
490-
- when:
491-
condition: << parameters.checkout >>
492-
steps:
493-
- checkout
494-
- attach_workspace:
495-
at: << parameters.attach-at >>
496-
- pack:
497-
source: << parameters.source-dir >>
498-
destination: << parameters.destination-file >>
499-
- when:
500-
condition: << parameters.validate >>
501-
steps:
502-
- validate:
503-
orb-path: << parameters.destination-file >>
504-
- env-publish:
505-
orb-path: << parameters.destination-file >>
506-
orb-ref: "<< parameters.namespace >>/<< parameters.orb-name >>@<< parameters.version >>"
507-
token-variable: << parameters.publish-token-variable >>
508-
- when:
509-
condition: << parameters.persist >>
510-
steps:
511-
- persist_to_workspace:
512-
root: << parameters.attach-at >>
513-
paths:
514-
- << parameters.destination-file >>
515-
- when:
516-
condition: << parameters.store-artifact >>
517-
steps:
518-
- store_artifacts:
519-
path: << parameters.destination-file >>

src/commands/env-publish.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
description: Uses the CLI to publish an orb to the registry.
2+
parameters:
3+
orb-path:
4+
description: The path to the orb file.
5+
type: string
6+
orb-ref:
7+
description: >
8+
A fully-qualified reference to an orb. This takes the form <namespace>/<orb-name>@<version>
9+
NOTE: To publish a dev version prefix the version with 'dev:' like this: <namespace>/<orb-name>@dev:<label>
10+
type: string
11+
token-variable:
12+
description: >
13+
The env var containing your token. Pass this as a literal string such
14+
as `$ORB_PUBLISHING_TOKEN`. Do not paste the actual token into your
15+
configuration. If omitted it's assumed the CLI has already been setup
16+
with a valid token.
17+
type: string
18+
default: ""
19+
steps:
20+
- run:
21+
name: >
22+
Publish orb at << parameters.orb-path >> to << parameters.orb-ref >>
23+
NOTE: this currently assumes you are publishing to the registry at circleci.com
24+
command: |
25+
source /usr/local/bin/envload
26+
export REPOSITORY_ORGANIZATION=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f3 | rev)
27+
echo "SET REPOSITORY_ORGANIZATION: ${REPOSITORY_ORGANIZATION}"
28+
export REPOSITORY_NAME=$(git config --get remote.origin.url | rev | tr '.:' '/' | cut -d'/' -f2 | rev)
29+
echo "SET REPOSITORY_NAME: ${REPOSITORY_NAME}"
30+
circleci orb publish << parameters.orb-path >> << parameters.orb-ref >> <<# parameters.token-variable >>--token << parameters.token-variable >> <</ parameters.token-variable >>

src/commands/env-templater.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
description: Replaces all template variables with the respective environment variables.
2+
parameters:
3+
orb-path:
4+
description: The path to the orb file.
5+
type: string
6+
steps:
7+
- run:
8+
name: >
9+
Loads all environment variables from previous envorb calls and replaces all template variables `{{VAR}}` with
10+
the respective environment variables `${VAR}`.
11+
command: |
12+
source /usr/local/bin/envload
13+
templater << parameters.orb-path >>

src/jobs/env-pack-publish.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
alpine_params: &alpine_params
2+
alpine_version:
3+
description: >
4+
Alpine version
5+
type: string
6+
default: ""
7+
8+
alpine_args: &alpine_args
9+
alpine_version: << parameters.alpine_version >>
10+
11+
description: Pack the contents of an orb for publishing and publish it.
12+
parameters:
13+
<<: [*alpine_params]
14+
source-dir:
15+
description: >
16+
Path to the root of the orb source directory to be packed.
17+
By default, `src/` is assumed.
18+
type: string
19+
default: src/
20+
destination-file:
21+
description: Path including filename of where the packed orb will be written.
22+
type: string
23+
default: ./.orbspace/orb.yml
24+
validate:
25+
description: Boolean for whether or not to do validation on the orb. Default is true.
26+
type: boolean
27+
default: true
28+
checkout:
29+
description: Boolean for whether or not to checkout as a first step. Default is true.
30+
type: boolean
31+
default: true
32+
attach-at:
33+
description: >
34+
Workspace root path that is either an absolute path or a path relative
35+
to the working directory. Defaults to '.' (the working directory).
36+
type: string
37+
default: "."
38+
persist:
39+
description: If enabled, the destination-file will be persisted.
40+
type: boolean
41+
default: false
42+
store-artifact:
43+
description: If enabled, the destination-file will be stored as artifact.
44+
type: boolean
45+
default: true
46+
namespace:
47+
description: >
48+
The namespace of your orb.
49+
Environment variables from an envorb are accepted.
50+
By default, the git organization is assumed.
51+
type: string
52+
default: "${REPOSITORY_ORGANIZATION}"
53+
orb-name:
54+
description: >
55+
The name of your orb.
56+
Environment variables from an envorb are accepted.
57+
By default, the git repository name is assumed.
58+
type: string
59+
default: "${REPOSITORY_NAME}"
60+
version:
61+
description: >
62+
The publishing version of your orb.
63+
Either use an incrementing semantic version (e.g., 1.0.0), or a development version as `dev:<label>`,
64+
where `label` can be any alphanumeric string.
65+
Environment variables from an envorb are accepted.
66+
By default, the environment variable `$ORB_PUBLISHING_VERSION` is assumed.
67+
type: string
68+
default: "${ORB_PUBLISHING_VERSION}"
69+
publish-token-variable:
70+
description: >
71+
The env var containing your publish token. Pass this as a literal string such
72+
as `$ORB_PUBLISHING_TOKEN`. DO NOT paste the actual token into your
73+
configuration. If omitted it's assumed the CLI has already been setup
74+
with a valid token.
75+
By default, an environment variable `$ORB_PUBLISHING_TOKEN` is expected.
76+
Make sure to pass a context to this job that contains the variable.
77+
type: string
78+
default: "${ORB_PUBLISHING_TOKEN}"
79+
patch-environment-variables:
80+
description: >
81+
To replace all template variables with the respective environment variables.
82+
Variables have to be defined in the format `{{VAR}}`.
83+
type: boolean
84+
default: true
85+
executor:
86+
name: default
87+
<<: *alpine_args
88+
steps:
89+
- when:
90+
condition: << parameters.checkout >>
91+
steps:
92+
- checkout
93+
- attach_workspace:
94+
at: << parameters.attach-at >>
95+
- pack:
96+
source: << parameters.source-dir >>
97+
destination: << parameters.destination-file >>
98+
- when:
99+
condition: << parameters.patch-environment-variables >>
100+
steps:
101+
- env-templater:
102+
orb-path: << parameters.destination-file >>
103+
- when:
104+
condition: << parameters.validate >>
105+
steps:
106+
- validate:
107+
orb-path: << parameters.destination-file >>
108+
- env-publish:
109+
orb-path: << parameters.destination-file >>
110+
orb-ref: "<< parameters.namespace >>/<< parameters.orb-name >>@<< parameters.version >>"
111+
token-variable: << parameters.publish-token-variable >>
112+
- when:
113+
condition: << parameters.persist >>
114+
steps:
115+
- persist_to_workspace:
116+
root: << parameters.attach-at >>
117+
paths:
118+
- << parameters.destination-file >>
119+
- when:
120+
condition: << parameters.store-artifact >>
121+
steps:
122+
- store_artifacts:
123+
path: << parameters.destination-file >>

0 commit comments

Comments
 (0)