Skip to content

Commit c8dd47b

Browse files
authored
add test for multi-line config-env-vars (#22)
* add test for multi-line config-env-vars * fix for newlines in compose-files * Update README with details on config-env-vars input
1 parent 87ddad7 commit c8dd47b

File tree

3 files changed

+42
-34
lines changed

3 files changed

+42
-34
lines changed

.github/workflows/test.yaml

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ on:
66
- main
77
pull_request:
88
branches:
9-
- '**'
9+
- "**"
1010
workflow_dispatch:
11-
schedule:
12-
- cron: '0 0 * * *'
11+
# schedule:
12+
# - cron: "0 0 * * *" # daily at midnight
1313

1414
jobs:
1515
test:
@@ -19,31 +19,35 @@ jobs:
1919
id-token: write
2020

2121
steps:
22-
- name: Checkout Repo
23-
uses: actions/checkout@v4
22+
- name: Checkout Repo
23+
uses: actions/checkout@v4
2424

25-
- name: Deploy
26-
uses: ./
27-
continue-on-error: true # Ignore dry run error
28-
with:
29-
cli-version: v0.5.40
30-
config-env-vars: "DEFANG_GH_ACTION_TEST_MESSAGE"
31-
cwd: "./test"
32-
compose-files: "compose.yaml compose.prod.yaml"
33-
mode: ""
34-
command: "compose up --dry-run"
35-
env:
36-
DEFANG_GH_ACTION_TEST_MESSAGE: ${{ secrets.MESSAGE }}
25+
- name: Deploy
26+
uses: ./
27+
with:
28+
cli-version: v0.5.40
29+
config-env-vars: |
30+
DEFANG_GH_ACTION_TEST_ENV
31+
DEFANG_GH_ACTION_TEST_MESSAGE
32+
cwd: "./test"
33+
compose-files: |
34+
compose.yaml
35+
compose.prod.yaml
36+
mode: ""
37+
command: "compose help"
38+
env:
39+
DEFANG_GH_ACTION_TEST_ENV: "foo"
40+
DEFANG_GH_ACTION_TEST_MESSAGE: ${{ secrets.MESSAGE }}
3741

38-
- name: Deploy-Empty-Params
39-
uses: ./
40-
continue-on-error: true # Ignore dry run error
41-
with:
42-
config-env-vars: ""
43-
cwd: "./test"
44-
compose-files: ""
45-
mode: "staging"
46-
command: "compose up --dry-run --project-name github-action-test"
42+
- name: Deploy-Empty-Params
43+
uses: ./
44+
continue-on-error: true # Ignore dry run error
45+
with:
46+
config-env-vars: ""
47+
cwd: "./test"
48+
compose-files: ""
49+
mode: "staging"
50+
command: "compose up --dry-run --project-name github-action-test"
4751

48-
- name: Teardown
49-
run: defang config rm DEFANG_GH_ACTION_TEST_MESSAGE
52+
- name: Teardown
53+
run: defang config rm DEFANG_GH_ACTION_TEST_MESSAGE

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Defang allows you to [securely manage configuration values](https://docs.defang.
3131
To publish a secret stored in GitHub to the cloud as a secure config value with defang, you need to do two things:
3232
3333
1. Use the `env` section of the step to pass the value of the secrets to environment variables that match the names of the config values in your Compose file.
34-
2. Specify the names of the environment variables you want to push to the cloud as config values in the `config-env-vars` input.
34+
2. Specify the names of the environment variables you want to push to the cloud as config values in the `config-env-vars` input, either whitespace delimited or as a YAML literal block scalar (`|`).
3535

3636
The second step is to make sure that we only publish the secrets you explicitly tell us to. For example, you could have a secret in an env var at the job level, instead of the step level that you might not want to push to the cloud, even if it is in a secure store.
3737

@@ -45,7 +45,9 @@ jobs:
4545
uses: DefangLabs/[email protected]
4646
with:
4747
# Note: you need to tell Defang which env vars to push to the cloud as config values here. Only these ones will be pushed up.
48-
config-env-vars: "API_KEY DB_CONNECTION_STRING"
48+
config-env-vars: |
49+
API_KEY
50+
DB_CONNECTION_STRING
4951
env:
5052
API_KEY: ${{ secrets.API_KEY }}
5153
DB_CONNECTION_STRING: ${{ secrets.DB_CONNECTION_STRING }}

action.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ branding:
77

88
inputs:
99
cli-version:
10-
description: "The version of the Defang CLI to use."
10+
description: "The version of the Defang CLI to use. Defaults to the latest stable release."
1111
required: false
1212
default: ""
1313
config-env-vars:
@@ -27,7 +27,7 @@ inputs:
2727
required: false
2828
default: ""
2929
provider:
30-
description: "The cloud provider to deploy to. Options: 'aws', 'defang', 'digitalocean'"
30+
description: "The cloud provider to deploy to. Options: 'aws', 'defang', 'digitalocean', 'gcp'"
3131
required: false
3232
default: "defang"
3333
command:
@@ -63,7 +63,7 @@ runs:
6363
run: |
6464
# Iterate over the sources and set the environment variables
6565
params=()
66-
for filename in ${{ inputs['compose-files'] }}; do
66+
for filename in $COMPOSE_FILES; do
6767
params+=("-f")
6868
params+=("$filename")
6969
done
@@ -74,6 +74,7 @@ runs:
7474
done
7575
working-directory: ${{ inputs.cwd }}
7676
env:
77+
COMPOSE_FILES: ${{ inputs['compose-files'] }}
7778
CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }}
7879

7980
- name: Defang ${{ inputs['command'] }}
@@ -82,7 +83,7 @@ runs:
8283
working-directory: ${{ inputs.cwd }}
8384
run: |
8485
params=()
85-
for filename in ${{ inputs['compose-files'] }}; do
86+
for filename in $COMPOSE_FILES; do
8687
params+=("-f")
8788
params+=("$filename")
8889
done
@@ -94,3 +95,4 @@ runs:
9495
defang $COMMAND "${params[@]}"
9596
env:
9697
COMMAND: ${{ inputs['command'] }}
98+
COMPOSE_FILES: ${{ inputs['compose-files'] }}

0 commit comments

Comments
 (0)