Skip to content

Commit 32b55ce

Browse files
committed
add env vars as script vars and prefix with "$".
1 parent f0386ac commit 32b55ce

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

README.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@ See the [example configuration](./templates/stackup.dist.yaml) for a more comple
172172

173173
Working on a standalone Laravel application? Check out the [example laravel configuration](./templates/stackup.laravel.yaml).
174174

175-
## Available Functions
175+
## Scripting
176+
177+
Many of the fields in a `Task` can be defined using javascript. To specify an expression to be evaluated, wrap the content in double braces: `{{ env("HOME") }}`.
178+
179+
### Available Functions
176180

177-
Many of the configuration fields can be defined using a javascript expression syntax.
178-
To specify an expression to be evaluated, wrap the content in double braces: `{{ env("HOME") }}`.
179181

180182
| Function | Arguments | Description |
181183
|----------- |------------------ |---------------------------------------------------------------------------- |
@@ -270,6 +272,23 @@ The `SemVer` class is returned by the `semver()` function And is used to parse a
270272
| `.Patch` | -- | value of the patch version number |
271273
| `.String` | -- | the original version string |
272274

275+
### Environment Variables
276+
277+
Environment variables can be accessed using the `env()` function or referenced directly as variables by prefixing the variable name with `$` (e.g. `$HOME`).
278+
279+
```yaml
280+
preconditions:
281+
- name: backend project has a docker-compose file
282+
check: exists($LOCAL_BACKEND_PROJECT_PATH + "/docker-compose.yml")
283+
284+
tasks:
285+
- name: horizon queue
286+
id: horizon-queue
287+
if: composerJson($LOCAL_BACKEND_PROJECT_PATH + "/composer.json").HasDependency("laravel/horizon");
288+
command: php artisan horizon
289+
path: '{{ env("LOCAL_BACKEND_PROJECT_PATH") }}'
290+
platforms: ['linux', 'darwin']
291+
```
273292
## Dynamic Tasks
274293

275294
You can create dynamic tasks using either the `selectTaskWhen()` or `task()` function:

lib/app/scriptEngine.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package app
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67

78
"github.com/robertkrimen/otto"
@@ -33,6 +34,14 @@ func (e *JavaScriptEngine) Init() {
3334
CreateScriptAppObject(e.Vm)
3435
CreateScriptVarsObject(e.Vm)
3536
CreateScriptDevObject(e.Vm)
37+
e.CreateEnvironmentVariables()
38+
}
39+
40+
func (e *JavaScriptEngine) CreateEnvironmentVariables() {
41+
for _, env := range os.Environ() {
42+
parts := strings.Split(env, "=")
43+
e.Vm.Set("$"+parts[0], parts[1])
44+
}
3645
}
3746

3847
func (e *JavaScriptEngine) ToValue(value otto.Value) any {

0 commit comments

Comments
 (0)