Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,13 @@

func (c *Compiler) getSpecialVars(t *ast.Task, call *Call) (map[string]string, error) {
allVars := map[string]string{
"TASK_EXE": filepath.ToSlash(os.Args[0]),
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
"ROOT_DIR": c.Dir,
"USER_WORKING_DIR": c.UserWorkingDir,
"TASK_VERSION": version.GetVersion(),
"TASK_EXE": filepath.ToSlash(os.Args[0]),
"ROOT_TASKFILE": filepathext.SmartJoin(c.Dir, c.Entrypoint),
"ROOT_DIR": c.Dir,
"USER_WORKING_DIR": c.UserWorkingDir,
"TASK_VERSION": version.GetVersion(),
"PATH_LIST_SEPARATOR": os.PathListSeparator,

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Lint (1.24.x)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Lint (1.24.x)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Lint (1.24.x)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.24.x, ubuntu-latest)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.25.x, ubuntu-latest)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.24.x, macos-latest)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal

Check failure on line 206 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.25.x, macos-latest)

cannot use os.PathListSeparator (untyped rune constant 58) as string value in map literal
"FILE_PATH_SEPARATOR": os.PathSeparator,

Check failure on line 207 in compiler.go

View workflow job for this annotation

GitHub Actions / Lint (1.24.x)

cannot use os.PathSeparator (untyped rune constant 47) as string value in map literal (typecheck)

Check failure on line 207 in compiler.go

View workflow job for this annotation

GitHub Actions / Lint (1.24.x)

cannot use os.PathSeparator (untyped rune constant 47) as string value in map literal) (typecheck)

Check failure on line 207 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.24.x, ubuntu-latest)

cannot use os.PathSeparator (untyped rune constant 47) as string value in map literal

Check failure on line 207 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.25.x, ubuntu-latest)

cannot use os.PathSeparator (untyped rune constant 47) as string value in map literal

Check failure on line 207 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.24.x, macos-latest)

cannot use os.PathSeparator (untyped rune constant 47) as string value in map literal

Check failure on line 207 in compiler.go

View workflow job for this annotation

GitHub Actions / Test (1.25.x, macos-latest)

cannot use os.PathSeparator (untyped rune constant 47) as string value in map literal
}
if t != nil {
allVars["TASK"] = t.Task
Expand Down
20 changes: 16 additions & 4 deletions internal/templater/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package templater
import (
"maps"
"math/rand/v2"
"os"
"path"
"path/filepath"
"runtime"
"strings"
Expand All @@ -21,8 +23,8 @@ var templateFuncs template.FuncMap

func init() {
taskFuncs := template.FuncMap{
"OS": os,
"ARCH": arch,
"OS": goos,
"ARCH": goarch,
"numCPU": runtime.NumCPU,
"catLines": catLines,
"splitLines": splitLines,
Expand All @@ -33,6 +35,8 @@ func init() {
"splitArgs": splitArgs,
"IsSH": IsSH, // Deprecated
"joinPath": filepath.Join,
"joinEnv": joinEnv,
"joinUrl": joinUrl,
"relPath": filepath.Rel,
"merge": merge,
"spew": spew.Sdump,
Expand All @@ -56,11 +60,11 @@ func init() {
maps.Copy(templateFuncs, taskFuncs)
}

func os() string {
func goos() string {
return runtime.GOOS
}

func arch() string {
func goarch() string {
return runtime.GOARCH
}

Expand Down Expand Up @@ -94,6 +98,14 @@ func IsSH() bool {
return true
}

func joinEnv(elem ...string) string {
return strings.Join(elem, string(os.PathListSeparator))
}

func joinUrl(elem ...string) string {
return path.Join(elem...)
}

func merge(base map[string]any, v ...map[string]any) map[string]any {
cap := len(v)
for _, m := range v {
Expand Down
63 changes: 63 additions & 0 deletions website/src/docs/reference/templating.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,24 @@ tasks:
- echo "Working {{.USER_WORKING_DIR}}"
```

#### `FILE_PATH_SEPARATOR`

- **Type**: `string`
- **Description**: OS-specific path separator: Windows = `\`, others = `/`
-
> **Note**: See `joinPath` in [Path Functions](#path-functions) for joining filesystem paths for use with
> file system operations.

### Environment Variables

#### `PATH_LIST_SEPARATOR`

- **Type**: `string`
- **Description**: OS-specific path separator for environment variables: Windows = `;`, others = `:`

> **Note**: See `joinEnv` in [Environment Variable Functions](#environment-variable-functions) for joining
> paths for use in environment variables.

### Status

#### `CHECKSUM`
Expand Down Expand Up @@ -613,6 +631,51 @@ tasks:
- echo "Relative {{relPath .ROOT_DIR .TASKFILE_DIR}}" # Get relative path
```

#### Environment Variable Functions

```yaml
tasks:
paths:
vars:
WIN_PATH1: 'C:\Users\Person\bin'
WIN_PATH2: 'C:\Shared\bin'
cmds:
- echo "{{joinEnv .WIN_PATH1 .WIN_PATH2}}" # Join paths for windows env vars -> C:\Users\Person\bin;C:\Shared\bin
```

```yaml
tasks:
paths:
vars:
POSIX_PATH1: '/users/person/.local/bin'
POSIX_PATH2: '/usr/bin'
cmds:
- echo "{{joinEnv .POSIX_PATH1 .POSIX_PATH2}}" # Join paths for posix env vars -> /users/person/.local/bin:/usr/bin
```

#### URLs

```yaml
tasks:
paths:
vars:
SERVER: 'http://localhost'
PATH1: 'path1'
PATH2: 'path2'
cmds:
- echo "{{joinUrl .SERVER .PATH1 .PATH2}}" # Join paths for URL -> http://localhost/path1/path2
```

```yaml
tasks:
paths:
vars:
POSIX_PATH1: '/users/person/.local/bin'
POSIX_PATH2: '/usr/bin'
cmds:
- echo "{{joinEnv .POSIX_PATH1 .POSIX_PATH2}}" # Join paths for posix env vars -> /users/person/.local/bin:/usr/bin
```

### Data Structure Functions

#### Dictionary Operations
Expand Down
Loading