Skip to content

Commit

Permalink
feat: initial working version with job (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Xavientois authored Feb 27, 2023
1 parent f73ec84 commit f9c5a33
Show file tree
Hide file tree
Showing 18 changed files with 343 additions and 118 deletions.
7 changes: 3 additions & 4 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ filters: &filters
only: /.*/

workflows:
lint-pack:
validate-publish-dev-orb:
jobs:
- orb-tools/lint:
filters: *filters
Expand All @@ -22,12 +22,11 @@ workflows:
- orb-tools/publish:
orb-name: xavientois/gomplate
vcs-type: << pipeline.project.type >>
requires:
[orb-tools/lint, orb-tools/review, orb-tools/pack, shellcheck/check]
requires: [orb-tools/pack]
context: orb-publishing
pub-type: dev
filters: *filters
# Triggers the test-deploy workflow in the Orb Development Kit.
# Triggers the test-deploy workflow
- orb-tools/continue:
pipeline-number: << pipeline.number >>
vcs-type: << pipeline.project.type >>
Expand Down
43 changes: 27 additions & 16 deletions .circleci/test-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,41 @@ filters: &filters
tags:
only: /.*/

tag-filters: &tag-filters
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/

jobs:
# Create a job to test the commands of your orbs.
# You may want to add additional validation steps to ensure the commands are working as expected.
command-tests:
docker:
- image: cimg/base:current
executor: gomplate/gomplate
steps:
- checkout
# Run your orb's commands to validate them.
- gomplate/greet
- run:
name: "Generate test template"
command: |
echo "Hello, {{ .Values.name }}!" > test.txt.tmpl
echo "name: CircleCI" > Values.yaml
- gomplate/render-template:
template-file: test.txt.tmpl
output-file: test.txt
contexts: Values.yaml
- run:
name: "Check test template output"
command: |
cat test.txt
if [ "$(cat test.txt)" != "Hello, CircleCI!" ]; then
echo "Test failed"
exit 1
fi
workflows:
test-deploy:
jobs:
# Make sure to include "filters: *filters" in every test job you want to run as part of your deployment.
- command-tests:
filters: *filters
- orb-tools/pack:
filters: *filters
filters: *tag-filters
- orb-tools/publish:
orb-name: xavientois/gomplate
vcs-type: << pipeline.project.type >>
Expand All @@ -33,10 +50,4 @@ workflows:
- orb-tools/pack
- command-tests
context: orb-publishing
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+$/

# VS Code Extension Version: 1.4.0
filters: *tag-filters
90 changes: 78 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,105 @@
# Orb Template
# Gomplate Orb

<!---
[![CircleCI Build Status](https://circleci.com/gh/<organization>/<project-name>.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/<organization>/<project-name>) [![CircleCI Orb Version](https://badges.circleci.com/orbs/<namespace>/<orb-name>.svg)](https://circleci.com/orbs/registry/orb/<namespace>/<orb-name>) [![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/<organization>/<project-name>/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)
[![CircleCI Build Status](https://circleci.com/gh/Xavientois/gomplate-orb.svg?style=shield "CircleCI Build Status")](https://circleci.com/gh/Xavientois/gomplate-orb) [![CircleCI Orb Version](https://badges.circleci.com/orbs/xavientois/gomplate.svg)](https://circleci.com/orbs/registry/orb/xavientois/gomplate) [![GitHub License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://raw.githubusercontent.com/Xavientois/gomplate-orb/master/LICENSE) [![CircleCI Community](https://img.shields.io/badge/community-CircleCI%20Discuss-343434.svg)](https://discuss.circleci.com/c/ecosystem/orbs)

--->
_**An orb to render Go templates in CircleCI using Gomplate**_

A project template for Orbs.
## Usage

This repository is designed to be automatically ingested and modified by the CircleCI CLI's `orb init` command.
In order to use this orb, just add it under the `orbs` section of your CircleCI `.circleci/config.yml`:

_**Edit this area to include a custom title and description.**_
```yaml
orbs:
gomplate: xaventois/[email protected]
```
## Examples
### `render-template` command

This command takes a template file and the input contexts/datasources and renders the template.

```yaml
version: 2.1
orbs:
gomplate: xaventois/[email protected]
jobs:
render-greeting:
executor: gomplate/gomplate
steps:
- run:
name: "Generate greeting template and input values"
command: |
echo "Hello, {{ .values.name }}!" > greet.txt.tmpl
echo "name: CircleCI" > values.yaml
- gomplate/render-template:
template-file: greet.txt.tmpl
output-file: greet.txt
contexts: values.yaml
- run:
name: "Output greeting"
command: |
cat test.txt
workflows:
greeting:
jobs:
- render-greeting
```

### `render-config` job

This job is designed to be used as part of a Dynamic Config setup workflow. It automatically calls the `continuation/continue` job upon rendering the template.

```yaml
version: 2.1
setup: true
orbs:
gomplate: xaventois/[email protected]
workflows:
use-my-orb:
jobs:
- gomplate/render-config:
template-file: .circleci/continue_config.yml.tmpl
output-file: .circleci/continue_config.yml
pre-steps:
- run:
command: |
echo '{ "a": "b", list: ["x", "y", "z"] }' > values.yaml
contexts: values.yaml
```

---

## Resources

[CircleCI Orb Registry Page](https://circleci.com/orbs/registry/orb/<namespace>/<orb-name>) - The official registry page of this orb for all versions, executors, commands, and jobs described.
[Documentation for this orb](https://circleci.com/orbs/registry/orb/xavientois/gomplate) - The official registry page of this orb for all versions, executors, commands, and jobs described.

[CircleCI Orb Docs](https://circleci.com/docs/2.0/orb-intro/#section=configuration) - Docs for using, creating, and publishing CircleCI Orbs.

### How to Contribute

We welcome [issues](https://github.com/<organization>/<project-name>/issues) to and [pull requests](https://github.com/<organization>/<project-name>/pulls) against this repository!
We welcome [issues](https://github.com/Xavientois/gomplate-orb/issues) to and [pull requests](https://github.com/Xavientois/gomplate-orb/pulls) against this repository!

### How to Publish An Update
1. Merge pull requests with desired changes to the main branch.
- For the best experience, squash-and-merge and use [Conventional Commit Messages](https://conventionalcommits.org/).
2. Find the current version of the orb.
- You can run `circleci orb info <namespace>/<orb-name> | grep "Latest"` to see the current version.
3. Create a [new Release](https://github.com/<organization>/<project-name>/releases/new) on GitHub.
- You can run `circleci orb info xavientois/gomplate | grep "Latest"` to see the current version.
3. Create a [new Release](https://github.com/Xavientois/gomplate-orb/releases/new) on GitHub.
- Click "Choose a tag" and _create_ a new [semantically versioned](http://semver.org/) tag. (ex: v1.0.0)
- We will have an opportunity to change this before we publish if needed after the next step.
4. Click _"+ Auto-generate release notes"_.
- This will create a summary of all of the merged pull requests since the previous release.
- If you have used _[Conventional Commit Messages](https://conventionalcommits.org/)_ it will be easy to determine what types of changes were made, allowing you to ensure the correct version tag is being published.
5. Now ensure the version tag selected is semantically accurate based on the changes included.
6. Click _"Publish Release"_.
- This will push a new tag and trigger your publishing pipeline on CircleCI.
- This will push a new tag and trigger your publishing pipeline on CircleCI.

## Licence

MIT
15 changes: 6 additions & 9 deletions src/@orb.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
version: 2.1

description: >
Sample orb description
What will your orb allow users to accomplish?
Descriptions should be short, simple, and informative.
This orb provides a command to render Go templates using Gomplate and store the output in a file.
This is useful to generate dynamic configuration files for CircleCI pipelines.
# This information will be displayed in the orb registry and is not mandatory.
display:
home_url: "https://github.com/xavientois/gomplate-orb"
source_url: "https://github.com/xavientois/gomplate-orb"
home_url: "https://github.com/Xavientois/gomplate-orb"
source_url: "https://github.com/Xavientois/gomplate-orb"

# If your orb requires other orbs, you can import them like this. Otherwise remove the "orbs" stanza.
# orbs:
# hello: circleci/[email protected]
orbs:
continuation: circleci/[email protected]
26 changes: 0 additions & 26 deletions src/README.md

This file was deleted.

15 changes: 0 additions & 15 deletions src/commands/greet.yml

This file was deleted.

23 changes: 23 additions & 0 deletions src/commands/install-gomplate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
description: Uses curl to install the specified version of Gomplate

parameters:
version:
type: string
default: "v3.11.4"
description: Version of Gomplate to install
os:
type: string
default: "linux"
description: Operating system to install Gomplate for
arch:
type: string
default: "amd64"
description: Architecture to install Gomplate for
steps:
- run:
name: Install Gomplate
environment:
VERSION: << parameters.version >>
OS: << parameters.os >>
ARCH: << parameters.arch >>
command: << include(scripts/install-gomplate.sh) >>
31 changes: 31 additions & 0 deletions src/commands/render-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
description: Renders the provided template and stores the output in the provided path

parameters:
template-file:
type: string
description: Template file to render as continuation pipeline
output-file:
type: string
description: Path to write the rendered template to
gomplate-config:
type: string
default: ""
description: Path to Gomplate config file
contexts:
type: string
default: ""
description: Space-separated list of Gomplate contexts. The format for each context corresponds to the format here https://docs.gomplate.ca/usage/#context-c
datasources:
type: string
default: ""
description: Space-separated list of Gomplate data sources. The format for each datasource corresponds to the format here https://docs.gomplate.ca/usage/#datasource-d
steps:
- run:
name: Render template
environment:
GOMPLATE_CONFIG: << parameters.gomplate-config >>
CONTEXTS: << parameters.contexts >>
DATASOURCES: << parameters.datasources >>
TEMPLATE_FILE: << parameters.template-file >>
OUTPUT_FILE: << parameters.output-file >>
command: << include(scripts/render-template.sh) >>
20 changes: 20 additions & 0 deletions src/examples/dynamic-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
description: This shows the example usage of the orb in order to generate a pipeline for dynamic config

usage:
version: 2.1
setup: true

orbs:
gomplate: xaventois/[email protected]

workflows:
use-my-orb:
jobs:
- gomplate/render-config:
template-file: .circleci/continue_config.yml.tmpl
output-file: .circleci/continue_config.yml
pre-steps:
- run:
command: |
echo '{ "a": "b", list: ["x", "y", "z"] }' > values.yaml
contexts: values.yaml
13 changes: 0 additions & 13 deletions src/examples/example.yml

This file was deleted.

30 changes: 30 additions & 0 deletions src/examples/render-template.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
description: This shows the example usage of the orb in order to render an arbitrary template

usage:
version: 2.1

orbs:
gomplate: xaventois/[email protected]

jobs:
render-greeting:
executor: gomplate/gomplate
steps:
- run:
name: "Generate greeting template and input values"
command: |
echo "Hello, {{ .values.name }}!" > greet.txt.tmpl
echo "name: CircleCI" > values.yaml
- gomplate/render-template:
template-file: greet.txt.tmpl
output-file: greet.txt
contexts: values.yaml
- run:
name: "Output greeting"
command: |
cat test.txt
workflows:
greeting:
jobs:
- render-greeting
Loading

0 comments on commit f9c5a33

Please sign in to comment.