Skip to content

Commit b6d06a0

Browse files
authored
Merge pull request #17 from DefangLabs/lio/add-command-arg
Add command input param
2 parents 0ea1c89 + 004dcfa commit b6d06a0

File tree

3 files changed

+34
-17
lines changed

3 files changed

+34
-17
lines changed

.github/workflows/test.yaml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,22 +30,20 @@ jobs:
3030
config-env-vars: "DEFANG_GH_ACTION_TEST_MESSAGE"
3131
cwd: "./test"
3232
compose-files: "compose.yaml compose.prod.yaml"
33-
mode: "staging"
33+
mode: ""
34+
command: "compose up --dry-run"
3435
env:
3536
DEFANG_GH_ACTION_TEST_MESSAGE: ${{ secrets.MESSAGE }}
36-
DEFANG_INTERNAL_TEST: dfng-test
3737

3838
- name: Deploy-Empty-Params
3939
uses: ./
4040
continue-on-error: true # Ignore dry run error
4141
with:
42-
cli-version: v0.5.40
4342
config-env-vars: ""
4443
cwd: "./test"
4544
compose-files: ""
46-
mode: ""
47-
env:
48-
DEFANG_INTERNAL_TEST: dfng-test
45+
mode: "staging"
46+
command: "compose up --dry-run --project-name github-action-test"
4947

5048
- name: Teardown
5149
run: defang config rm DEFANG_GH_ACTION_TEST_MESSAGE

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
2727
### Managing Config Values
2828
29-
Defang allows you to [securely manage configuration values](https://docs.defang.io/docs/concepts/configuration). You can store your config using [GitHub Actions Secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) and then pass them through to the Defang action.
29+
Defang allows you to [securely manage configuration values](https://docs.defang.io/docs/concepts/configuration). You can store your config using [GitHub Actions Secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions) and then pass them through to the Defang action.
3030
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
@@ -83,6 +83,23 @@ jobs:
8383
cli-version: v0.5.38
8484
```
8585

86+
### Customizing the Defang Command
87+
88+
If you want to customize the Defang command that is run, you can specify it using the `command` input.
89+
This is useful if you want to run a command other than `compose up` or if you want to pass additional arguments to the command.
90+
91+
```yaml
92+
jobs:
93+
test:
94+
# [...]
95+
steps:
96+
# [...]
97+
- name: Deploy
98+
uses: DefangLabs/[email protected]
99+
with:
100+
command: "compose up --project-name my-project"
101+
```
102+
86103
### Full Example
87104

88105
Here is a full example of a GitHub workflow that does everything we've discussed so far:

action.yaml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,13 @@ inputs:
2727
required: false
2828
default: ""
2929
provider:
30-
description: "The cloud provider to deploy to. Options: 'aws', 'defang'"
30+
description: "The cloud provider to deploy to. Options: 'aws', 'defang', 'digitalocean'"
3131
required: false
3232
default: "defang"
33+
command:
34+
description: "The command to run."
35+
required: false
36+
default: "compose up"
3337

3438
runs:
3539
using: "composite"
@@ -55,6 +59,7 @@ runs:
5559
5660
- name: Defang Config Set
5761
shell: bash
62+
if: ${{ inputs['config-env-vars'] != '' }}
5863
run: |
5964
# Iterate over the sources and set the environment variables
6065
params=()
@@ -71,7 +76,8 @@ runs:
7176
env:
7277
CONFIG_ENV_VARS: ${{ inputs['config-env-vars'] }}
7378

74-
- name: Defang Compose Up
79+
- name: Defang ${{ inputs['command'] }}
80+
if: ${{ inputs['command'] != '' }}
7581
shell: bash
7682
working-directory: ${{ inputs.cwd }}
7783
run: |
@@ -84,11 +90,7 @@ runs:
8490
params+=("--mode=${{ inputs['mode'] }}")
8591
fi
8692
87-
if [[ "${DEFANG_INTERNAL_TEST}" == "dfng-test" ]]; then
88-
# `defang compose up --dry-run` is used for testing as --mode flag is only available to the "compose up" command
89-
echo defang compose "${params[@]}" up --dry-run
90-
defang compose "${params[@]}" up --dry-run
91-
else
92-
echo defang compose "${params[@]}" up
93-
defang compose "${params[@]}" up
94-
fi
93+
echo defang $COMMAND "${params[@]}"
94+
defang $COMMAND "${params[@]}"
95+
env:
96+
COMMAND: ${{ inputs['command'] }}

0 commit comments

Comments
 (0)