Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(platforms): do not run dynamic vars for other platforms #1377

Merged
merged 1 commit into from
Oct 22, 2023
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

- Fix bug where dynamic `vars:` and `env:` were being executed when they should
actually be skipped by `platforms:` (#1273, #1377 by @andreynering).

## v3.31.0 - 2023-10-07

- Enabled the `--yes` flag for the
Expand Down
1 change: 1 addition & 0 deletions internal/goext/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ var knownOS = map[string]struct{}{
"solaris": {},
"windows": {},
"zos": {},
"__test__": {},
}

var knownArch = map[string]struct{}{
Expand Down
16 changes: 10 additions & 6 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,16 @@ func (e *Executor) splitRegularAndWatchCalls(calls ...taskfile.Call) (regularCal

// RunTask runs a task by its name
func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
t, err := e.CompiledTask(call)
t, err := e.FastCompiledTask(call)
if err != nil {
return err
}
if !shouldRunOnCurrentPlatform(t.Platforms) {
e.Logger.VerboseOutf(logger.Yellow, `task: %q not for current platform - ignored\n`, call.Task)
return nil
}

t, err = e.CompiledTask(call)
if err != nil {
return err
}
Expand All @@ -185,11 +194,6 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
}

return e.startExecution(ctx, t, func(ctx context.Context) error {
if !shouldRunOnCurrentPlatform(t.Platforms) {
e.Logger.VerboseOutf(logger.Yellow, `task: %q not for current platform - ignored\n`, call.Task)
return nil
}

e.Logger.VerboseErrf(logger.Magenta, "task: %q started\n", call.Task)
if err := e.runDeps(ctx, t); err != nil {
return err
Expand Down
16 changes: 16 additions & 0 deletions testdata/platforms/Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,37 @@ version: '3'

tasks:
build-windows:
deps: [failed-var-other-platform]
platforms: [windows]
cmds:
- echo 'Running task on windows'

build-darwin:
deps: [failed-var-other-platform]
platforms: [darwin]
cmds:
- echo 'Running task on darwin'

build-linux:
deps: [failed-var-other-platform]
platforms: [linux]
cmds:
- echo 'Running task on linux'

build-freebsd:
deps: [failed-var-other-platform]
platforms: [freebsd]
cmds:
- echo 'Running task on freebsd'

build-blank-os:
deps: [failed-var-other-platform]
platforms: []
cmds:
- echo 'Running command'

build-multiple:
deps: [failed-var-other-platform]
platforms: []
cmds:
- cmd: echo 'Running command'
Expand All @@ -36,20 +42,30 @@ tasks:
platforms: [darwin]

build-amd64:
deps: [failed-var-other-platform]
platforms: [amd64]
cmds:
- echo "Running command on amd64"

build-arm64:
deps: [failed-var-other-platform]
platforms: [arm64]
cmds:
- echo "Running command on arm64"

build-mixed:
deps: [failed-var-other-platform]
cmds:
- cmd: echo 'building on windows/arm64'
platforms: [windows/arm64]
- cmd: echo 'building on linux/amd64'
platforms: [linux/amd64]
- cmd: echo 'building on darwin'
platforms: [darwin]

failed-var-other-platform:
platforms: [__test__]
env:
EXAMPLE_VAR: {sh: exit 1}
vars:
EXAMPLE_VAR: {sh: exit 2}