Skip to content

Commit 6468405

Browse files
Refactor scripts to use environment variables and best practices (#4)
* add param to config * fix build scripts * remove spaces * add missing params * remove extra tag * refactor to use env vars * remove redundant error check * add shebangs * remove unused params and fix validation errors * uncomment command-test * add some more tests and call bats in ci script * update tests * Commit message * Commit message * Commit message * Commit message * Commit message * try tests again * add pwds * fix * add failing cd mock * fix mock * check for missing files * add logs * fix * use grep for matching * add logs * set shebangs * fix mocks * encapsulate functions for testing * wrap function calls to prevent calls when sourced * fix test syntax * use grep instead of pattern matching * try different matching * fix name of file and use regex to match * add verbose logs * fix extraction * refactor to atomize to enable testing * add shebang * fix env vars for scripts * env vars * fix regex. remove unneeded var * more fixes * finally fix regex * add orb prefix * pass in commit message * fix commit message and unset vars after tests * fix expected output
1 parent 3f16e07 commit 6468405

35 files changed

+658
-549
lines changed

.circleci/config.yml

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,13 @@ setup: true
33
orbs:
44
orb-tools: circleci/[email protected]
55
shellcheck: circleci/[email protected]
6+
bats: circleci/[email protected]
67

78
filters: &filters
89
tags:
910
only: /.*/
1011

1112
workflows:
12-
# Prior to producing a development orb (which requires credentials) basic validation, linting, and even unit testing can be performed.
13-
# This workflow will run on every commit
14-
test-pack:
15-
unless: << pipeline.parameters.run-integration-tests >>
16-
jobs:
17-
- orb-tools/lint # Lint Yaml files
18-
- orb-tools/pack # Pack orb source
19-
# Publish development version(s) of the orb.
20-
- orb-tools/publish-dev:
21-
orb-name: infinitered/publish-docs
22-
context: orb-publishing # A restricted context containing your private publishing credentials. Will only execute if approved by an authorized user.
23-
requires:
24-
- orb-tools/lint
25-
- orb-tools/pack
26-
- bats/run
27-
- shellcheck/check
28-
# Trigger an integration workflow to test the
29-
# dev:${CIRCLE_SHA1:0:7} version of your orb
30-
- orb-tools/trigger-integration-tests-workflow:
31-
name: trigger-integration-dev
32-
context: orb-publishing
33-
requires:
34-
- orb-tools/publish-dev
3513
lint-pack:
3614
jobs:
3715
- orb-tools/lint:
@@ -44,8 +22,8 @@ workflows:
4422
filters: *filters
4523
# Triggers the next workflow in the Orb Development Kit.
4624
- orb-tools/continue:
47-
pipeline_number: << pipeline.number >>
25+
pipeline_number: << pipeline.number >>
4826
vcs_type: << pipeline.project.type >>
49-
orb_name: <orb-name>
50-
requires: [orb-tools/lint, orb-tools/pack, orb-tools/review, shellcheck/check]
27+
orb_name: infinitered/docs-publish
28+
requires: [ orb-tools/lint, orb-tools/pack, orb-tools/review, shellcheck/check ]
5129
filters: *filters

.circleci/test-deploy.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ orbs:
44
# Reference your orb's jobs and commands below as they will exist when built.
55
orb-tools: circleci/[email protected]
66
# The orb definition is intentionally not included here. It will be injected into the pipeline.
7-
<orb-name>: {}
7+
<orb-name>: { }
88

99
# Use this tag to ensure test jobs always run,
1010
# even though the downstream publish job will only run on release tags.
@@ -27,8 +27,25 @@ jobs:
2727
- image: cimg/base:current
2828
steps:
2929
- checkout
30-
# Run your orb's commands to validate them.
31-
- <orb-name>/greet
30+
- run:
31+
name: Set Environment Variables
32+
environment:
33+
USE_MOCKS: "true"
34+
command: echo "Environment variables set."
35+
- run:
36+
name: Run BATS tests
37+
command: |
38+
# Install Bats if needed
39+
if ! command -v bats &> /dev/null
40+
then
41+
echo "Installing Bats"
42+
git clone https://github.com/bats-core/bats-core.git
43+
cd bats-core
44+
sudo ./install.sh /usr/local
45+
cd ..
46+
fi
47+
# Run Bats tests
48+
bats ./src/tests/*.bats
3249
workflows:
3350
test-deploy:
3451
jobs:
@@ -40,12 +57,12 @@ workflows:
4057
- orb-tools/pack:
4158
filters: *release-filters
4259
- orb-tools/publish:
43-
orb_name: <namespace>/<orb-name>
60+
orb_name: infinitered/docs-publish
4461
vcs_type: << pipeline.project.type >>
4562
pub_type: production
4663
# Ensure this job requires all test jobs and the pack job.
4764
requires:
4865
- orb-tools/pack
4966
- command-test
50-
context: <publishing-context>
67+
context: orb-publishing
5168
filters: *release-filters

.idea/codeStyles/Project.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/yamllint.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.yamllint

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ rules:
44
line-length:
55
max: 200
66
allow-non-breakable-inline-mappings: true
7-
7+
new-line-at-end-of-file: enable

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ repository.
4242
| `description` | String | Short description of the package used in indexes etc. Default is an empty string. |
4343
| `label` | String | The label that will appear in the sidebar of the docs site. Default is "package-name". |
4444
| `project_name` | String | The path where these documents will be located on the docs site. Default is an empty string. |
45-
| `source_docs_path`| String | The path to the directory containing the source markdown files. Default is "./docs". |
45+
| `source_docs_dir`| String | The path to the directory containing the source markdown files. Default is "./docs". |
4646

4747
## Basic Example
4848

@@ -64,7 +64,7 @@ workflows:
6464
description: "An example package."
6565
label: "Example Package"
6666
project_name: "example-package"
67-
source_docs_path: "./example-docs"
67+
source_docs_dir: "./example-docs"
6868
```
6969
7070
### Handling Static Files
@@ -152,7 +152,7 @@ Clones a Docusaurus repo and adds the docs from the current repo to the target r
152152
| `description` | String | Short description of the package. Default is an empty string. |
153153
| `label` | String | The label for the sidebar. Default is "package-name". |
154154
| `project_name` | String | The path where the documents will be located on the docs site. |
155-
| `source_docs_path`| String | The path to the directory containing the source markdown files. Default is "./docs".|
155+
| `source_docs_dir`| String | The path to the directory containing the source markdown files. Default is "./docs".|
156156
| `target_docs_path`| String | The path to the directory in the target repo where docs will be copied. Default is "./docs".|
157157
158158
---

0 commit comments

Comments
 (0)