Skip to content

Commit

Permalink
Add --environ-file default for env (using dotenvx).
Browse files Browse the repository at this point in the history
If the --environ-file option is used then dotenvx is used to load and
parse the environment file to use a defaults env values.

Add an example suite examples/03-env.yaml that is designed to be used
with --environ-file examples/03-env-file.

Add tests to test/runexamples that tests examples/03-env.yaml with and
without the the examples/03-env-file.

NOTE: It would be preferable to have the option be named `--env-file`
since this is more common. However, when running in nbb with node
earlier than 22, node intercepts the --env-file option. And for some
reason, node refused absoluate paths with --env-file. In node v22 it is
possible to avoid the issue by using a "--" parameter before the
regular nbb script parameters. But node 22 is not in standard GHA runner
configs so for now we will use "--environ-file".
  • Loading branch information
kanaka committed Nov 15, 2024
1 parent febad03 commit f94c528
Show file tree
Hide file tree
Showing 7 changed files with 618 additions and 14 deletions.
4 changes: 4 additions & 0 deletions examples/03-env-file
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
BAR=x
BAR=${BAR:+c}
BAR="b${BAR:-C}d"
BAR="a${BAR:-SEE}e"
64 changes: 64 additions & 0 deletions examples/03-env.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: Example Suite - Environment variables

# requires use of `--environ-file examples/03-env-file` to succeed

env:
FOO: p1-${{ env.FOO || "foo" }}-s1
BAR: p1-${{ env.BAR || "bar" }}-s1

tests:

env-depth-inside-FOO:
name: multiple levels, FOO inside
env:
FOO: p2-${{ env.FOO }}-s2
steps:
- exec: node1
env:
FOO: p3-${{ env.FOO }}-s3
run: |
FOO="p4-${FOO:-invaid}-s4"
echo "inside FOO: '${FOO}'"
[ "p4-p3-p2-p1-foo-s1-s2-s3-s4" = "${FOO}" ]
env-depth-inside-BAR:
name: multiple levels, BAR inside
env:
BAR: p2-${{ env.BAR }}-s2
steps:
- exec: node1
env:
BAR: p3-${{ env.BAR }}-s3
run: |
BAR="p4-${BAR:-invaid}-s4"
echo "inside BAR: '${BAR}'"
[ "p4-p3-p2-p1-abcde-s1-s2-s3-s4" = "${BAR}" ]
env-depth-outside-FOO:
name: multiple levels, FOO outside
env:
FOO: p2-${{ env.FOO }}-s2
steps:
- name: FOO outside
exec: :host
env:
FOO: p3-${{ env.FOO }}-s3
run: |
FOO="p4-${FOO:-invalid}-s4"
echo "outside FOO: '${FOO}'"
[ "p4-p3-p2-p1-foo-s1-s2-s3-s4" = "${FOO}" ]
env-depth-outside-BAR:
name: multiple levels, BAR outside
env:
FOO: p2-${{ env.FOO }}-s2
BAR: p2-${{ env.BAR }}-s2
steps:
- name: BAR outside
exec: :host
env:
BAR: p3-${{ env.BAR }}-s3
run: |
BAR="p4-${BAR:-invalid}-s4"
echo "outside BAR: '${BAR}'"
[ "p4-p3-p2-p1-abcde-s1-s2-s3-s4" = "${BAR}" ]
Loading

0 comments on commit f94c528

Please sign in to comment.