mirror of
https://github.com/go-task/task.git
synced 2026-06-16 04:11:40 +00:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
47d3011c85 | ||
|
|
cec713a47a | ||
|
|
bf6d0c0a74 | ||
|
|
c11672fca3 | ||
|
|
e086b654aa | ||
|
|
1107f691ea |
13
CHANGELOG.md
13
CHANGELOG.md
@@ -1,5 +1,18 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v3.2.2
|
||||||
|
|
||||||
|
- Improve performance of `--list` and `--summary` by skipping running shell
|
||||||
|
variables for these flags
|
||||||
|
([#332](https://github.com/go-task/task/issues/332)).
|
||||||
|
- Fixed a bug where an environment in a Taskfile was not always overridable
|
||||||
|
by the system environment
|
||||||
|
([#425](https://github.com/go-task/task/issues/425)).
|
||||||
|
- Fixed environment from .env files not being available as variables
|
||||||
|
([#379](https://github.com/go-task/task/issues/379)).
|
||||||
|
- The install script is now working for ARM platforms
|
||||||
|
([#428](https://github.com/go-task/task/pull/428)).
|
||||||
|
|
||||||
## v3.2.1
|
## v3.2.1
|
||||||
|
|
||||||
- Fixed some bugs and regressions regarding dynamic variables and directories
|
- Fixed some bugs and regressions regarding dynamic variables and directories
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
# Code generated by godownloader on 2018-04-07T17:47:38Z. DO NOT EDIT.
|
# Code generated by godownloader on 2021-01-12T13:40:40Z. DO NOT EDIT.
|
||||||
#
|
#
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@@ -27,11 +27,12 @@ parse_args() {
|
|||||||
# over-ridden by flag below
|
# over-ridden by flag below
|
||||||
|
|
||||||
BINDIR=${BINDIR:-./bin}
|
BINDIR=${BINDIR:-./bin}
|
||||||
while getopts "b:dh?" arg; do
|
while getopts "b:dh?x" arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
b) BINDIR="$OPTARG" ;;
|
b) BINDIR="$OPTARG" ;;
|
||||||
d) log_set_priority 10 ;;
|
d) log_set_priority 10 ;;
|
||||||
h | \?) usage "$0" ;;
|
h | \?) usage "$0" ;;
|
||||||
|
x) set -x ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
@@ -42,46 +43,41 @@ parse_args() {
|
|||||||
# network, either nothing will happen or will syntax error
|
# network, either nothing will happen or will syntax error
|
||||||
# out preventing half-done work
|
# out preventing half-done work
|
||||||
execute() {
|
execute() {
|
||||||
tmpdir=$(mktmpdir)
|
tmpdir=$(mktemp -d)
|
||||||
log_debug "downloading files into ${tmpdir}"
|
log_debug "downloading files into ${tmpdir}"
|
||||||
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
|
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
|
||||||
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
|
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
|
||||||
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
|
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
|
||||||
srcdir="${tmpdir}"
|
srcdir="${tmpdir}"
|
||||||
(cd "${tmpdir}" && untar "${TARBALL}")
|
(cd "${tmpdir}" && untar "${TARBALL}")
|
||||||
install -d "${BINDIR}"
|
test ! -d "${BINDIR}" && install -d "${BINDIR}"
|
||||||
for binexe in "task" ; do
|
for binexe in $BINARIES; do
|
||||||
if [ "$OS" = "windows" ]; then
|
if [ "$OS" = "windows" ]; then
|
||||||
binexe="${binexe}.exe"
|
binexe="${binexe}.exe"
|
||||||
fi
|
fi
|
||||||
install "${srcdir}/${binexe}" "${BINDIR}/"
|
install "${srcdir}/${binexe}" "${BINDIR}/"
|
||||||
log_info "installed ${BINDIR}/${binexe}"
|
log_info "installed ${BINDIR}/${binexe}"
|
||||||
done
|
done
|
||||||
|
rm -rf "${tmpdir}"
|
||||||
}
|
}
|
||||||
is_supported_platform() {
|
get_binaries() {
|
||||||
platform=$1
|
case "$PLATFORM" in
|
||||||
found=1
|
darwin/amd64) BINARIES="task" ;;
|
||||||
case "$platform" in
|
darwin/arm64) BINARIES="task" ;;
|
||||||
windows/386) found=0 ;;
|
darwin/armv6) BINARIES="task" ;;
|
||||||
windows/amd64) found=0 ;;
|
linux/386) BINARIES="task" ;;
|
||||||
darwin/386) found=0 ;;
|
linux/amd64) BINARIES="task" ;;
|
||||||
darwin/amd64) found=0 ;;
|
linux/arm64) BINARIES="task" ;;
|
||||||
linux/386) found=0 ;;
|
linux/armv6) BINARIES="task" ;;
|
||||||
linux/amd64) found=0 ;;
|
windows/386) BINARIES="task" ;;
|
||||||
|
windows/amd64) BINARIES="task" ;;
|
||||||
|
windows/arm64) BINARIES="task" ;;
|
||||||
|
windows/armv6) BINARIES="task" ;;
|
||||||
|
*)
|
||||||
|
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
case "$platform" in
|
|
||||||
darwin/386) found=1 ;;
|
|
||||||
esac
|
|
||||||
return $found
|
|
||||||
}
|
|
||||||
check_platform() {
|
|
||||||
if is_supported_platform "$PLATFORM"; then
|
|
||||||
# optional logging goes here
|
|
||||||
true
|
|
||||||
else
|
|
||||||
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
tag_to_version() {
|
tag_to_version() {
|
||||||
if [ -z "${TAG}" ]; then
|
if [ -z "${TAG}" ]; then
|
||||||
@@ -99,8 +95,8 @@ tag_to_version() {
|
|||||||
VERSION=${TAG#v}
|
VERSION=${TAG#v}
|
||||||
}
|
}
|
||||||
adjust_format() {
|
adjust_format() {
|
||||||
# change format (tar.gz or zip) based on ARCH
|
# change format (tar.gz or zip) based on OS
|
||||||
case ${ARCH} in
|
case ${OS} in
|
||||||
windows) FORMAT=zip ;;
|
windows) FORMAT=zip ;;
|
||||||
esac
|
esac
|
||||||
true
|
true
|
||||||
@@ -174,7 +170,9 @@ log_crit() {
|
|||||||
uname_os() {
|
uname_os() {
|
||||||
os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
case "$os" in
|
case "$os" in
|
||||||
msys_nt) os="windows" ;;
|
cygwin_nt*) os="windows" ;;
|
||||||
|
mingw*) os="windows" ;;
|
||||||
|
msys_nt*) os="windows" ;;
|
||||||
esac
|
esac
|
||||||
echo "$os"
|
echo "$os"
|
||||||
}
|
}
|
||||||
@@ -186,9 +184,9 @@ uname_arch() {
|
|||||||
i686) arch="386" ;;
|
i686) arch="386" ;;
|
||||||
i386) arch="386" ;;
|
i386) arch="386" ;;
|
||||||
aarch64) arch="arm64" ;;
|
aarch64) arch="arm64" ;;
|
||||||
armv5*) arch="arm5" ;;
|
armv5*) arch="armv5" ;;
|
||||||
armv6*) arch="arm6" ;;
|
armv6*) arch="armv6" ;;
|
||||||
armv7*) arch="arm7" ;;
|
armv7*) arch="armv7" ;;
|
||||||
esac
|
esac
|
||||||
echo ${arch}
|
echo ${arch}
|
||||||
}
|
}
|
||||||
@@ -234,8 +232,8 @@ uname_arch_check() {
|
|||||||
untar() {
|
untar() {
|
||||||
tarball=$1
|
tarball=$1
|
||||||
case "${tarball}" in
|
case "${tarball}" in
|
||||||
*.tar.gz | *.tgz) tar -xzf "${tarball}" ;;
|
*.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;;
|
||||||
*.tar) tar -xf "${tarball}" ;;
|
*.tar) tar --no-same-owner -xf "${tarball}" ;;
|
||||||
*.zip) unzip "${tarball}" ;;
|
*.zip) unzip "${tarball}" ;;
|
||||||
*)
|
*)
|
||||||
log_err "untar unknown archive format for ${tarball}"
|
log_err "untar unknown archive format for ${tarball}"
|
||||||
@@ -243,11 +241,6 @@ untar() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
mktmpdir() {
|
|
||||||
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
|
|
||||||
mkdir -p "${TMPDIR}"
|
|
||||||
echo "${TMPDIR}"
|
|
||||||
}
|
|
||||||
http_download_curl() {
|
http_download_curl() {
|
||||||
local_file=$1
|
local_file=$1
|
||||||
source_url=$2
|
source_url=$2
|
||||||
@@ -368,7 +361,7 @@ uname_arch_check "$ARCH"
|
|||||||
|
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
|
||||||
check_platform
|
get_binaries
|
||||||
|
|
||||||
tag_to_version
|
tag_to_version
|
||||||
|
|
||||||
|
|||||||
2
help.go
2
help.go
@@ -30,7 +30,7 @@ func (e *Executor) tasksWithDesc() (tasks []*taskfile.Task) {
|
|||||||
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
tasks = make([]*taskfile.Task, 0, len(e.Taskfile.Tasks))
|
||||||
for _, task := range e.Taskfile.Tasks {
|
for _, task := range e.Taskfile.Tasks {
|
||||||
if task.Desc != "" {
|
if task.Desc != "" {
|
||||||
compiledTask, err := e.CompiledTask(taskfile.Call{Task: task.Task})
|
compiledTask, err := e.FastCompiledTask(taskfile.Call{Task: task.Task})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
task = compiledTask
|
task = compiledTask
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
# Code generated by godownloader on 2018-04-07T17:47:38Z. DO NOT EDIT.
|
# Code generated by godownloader on 2021-01-12T13:40:40Z. DO NOT EDIT.
|
||||||
#
|
#
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
@@ -27,11 +27,12 @@ parse_args() {
|
|||||||
# over-ridden by flag below
|
# over-ridden by flag below
|
||||||
|
|
||||||
BINDIR=${BINDIR:-./bin}
|
BINDIR=${BINDIR:-./bin}
|
||||||
while getopts "b:dh?" arg; do
|
while getopts "b:dh?x" arg; do
|
||||||
case "$arg" in
|
case "$arg" in
|
||||||
b) BINDIR="$OPTARG" ;;
|
b) BINDIR="$OPTARG" ;;
|
||||||
d) log_set_priority 10 ;;
|
d) log_set_priority 10 ;;
|
||||||
h | \?) usage "$0" ;;
|
h | \?) usage "$0" ;;
|
||||||
|
x) set -x ;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
shift $((OPTIND - 1))
|
shift $((OPTIND - 1))
|
||||||
@@ -42,46 +43,41 @@ parse_args() {
|
|||||||
# network, either nothing will happen or will syntax error
|
# network, either nothing will happen or will syntax error
|
||||||
# out preventing half-done work
|
# out preventing half-done work
|
||||||
execute() {
|
execute() {
|
||||||
tmpdir=$(mktmpdir)
|
tmpdir=$(mktemp -d)
|
||||||
log_debug "downloading files into ${tmpdir}"
|
log_debug "downloading files into ${tmpdir}"
|
||||||
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
|
http_download "${tmpdir}/${TARBALL}" "${TARBALL_URL}"
|
||||||
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
|
http_download "${tmpdir}/${CHECKSUM}" "${CHECKSUM_URL}"
|
||||||
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
|
hash_sha256_verify "${tmpdir}/${TARBALL}" "${tmpdir}/${CHECKSUM}"
|
||||||
srcdir="${tmpdir}"
|
srcdir="${tmpdir}"
|
||||||
(cd "${tmpdir}" && untar "${TARBALL}")
|
(cd "${tmpdir}" && untar "${TARBALL}")
|
||||||
install -d "${BINDIR}"
|
test ! -d "${BINDIR}" && install -d "${BINDIR}"
|
||||||
for binexe in "task" ; do
|
for binexe in $BINARIES; do
|
||||||
if [ "$OS" = "windows" ]; then
|
if [ "$OS" = "windows" ]; then
|
||||||
binexe="${binexe}.exe"
|
binexe="${binexe}.exe"
|
||||||
fi
|
fi
|
||||||
install "${srcdir}/${binexe}" "${BINDIR}/"
|
install "${srcdir}/${binexe}" "${BINDIR}/"
|
||||||
log_info "installed ${BINDIR}/${binexe}"
|
log_info "installed ${BINDIR}/${binexe}"
|
||||||
done
|
done
|
||||||
|
rm -rf "${tmpdir}"
|
||||||
}
|
}
|
||||||
is_supported_platform() {
|
get_binaries() {
|
||||||
platform=$1
|
case "$PLATFORM" in
|
||||||
found=1
|
darwin/amd64) BINARIES="task" ;;
|
||||||
case "$platform" in
|
darwin/arm64) BINARIES="task" ;;
|
||||||
windows/386) found=0 ;;
|
darwin/armv6) BINARIES="task" ;;
|
||||||
windows/amd64) found=0 ;;
|
linux/386) BINARIES="task" ;;
|
||||||
darwin/386) found=0 ;;
|
linux/amd64) BINARIES="task" ;;
|
||||||
darwin/amd64) found=0 ;;
|
linux/arm64) BINARIES="task" ;;
|
||||||
linux/386) found=0 ;;
|
linux/armv6) BINARIES="task" ;;
|
||||||
linux/amd64) found=0 ;;
|
windows/386) BINARIES="task" ;;
|
||||||
|
windows/amd64) BINARIES="task" ;;
|
||||||
|
windows/arm64) BINARIES="task" ;;
|
||||||
|
windows/armv6) BINARIES="task" ;;
|
||||||
|
*)
|
||||||
|
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
case "$platform" in
|
|
||||||
darwin/386) found=1 ;;
|
|
||||||
esac
|
|
||||||
return $found
|
|
||||||
}
|
|
||||||
check_platform() {
|
|
||||||
if is_supported_platform "$PLATFORM"; then
|
|
||||||
# optional logging goes here
|
|
||||||
true
|
|
||||||
else
|
|
||||||
log_crit "platform $PLATFORM is not supported. Make sure this script is up-to-date and file request at https://github.com/${PREFIX}/issues/new"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
tag_to_version() {
|
tag_to_version() {
|
||||||
if [ -z "${TAG}" ]; then
|
if [ -z "${TAG}" ]; then
|
||||||
@@ -99,8 +95,8 @@ tag_to_version() {
|
|||||||
VERSION=${TAG#v}
|
VERSION=${TAG#v}
|
||||||
}
|
}
|
||||||
adjust_format() {
|
adjust_format() {
|
||||||
# change format (tar.gz or zip) based on ARCH
|
# change format (tar.gz or zip) based on OS
|
||||||
case ${ARCH} in
|
case ${OS} in
|
||||||
windows) FORMAT=zip ;;
|
windows) FORMAT=zip ;;
|
||||||
esac
|
esac
|
||||||
true
|
true
|
||||||
@@ -174,7 +170,9 @@ log_crit() {
|
|||||||
uname_os() {
|
uname_os() {
|
||||||
os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
os=$(uname -s | tr '[:upper:]' '[:lower:]')
|
||||||
case "$os" in
|
case "$os" in
|
||||||
msys_nt) os="windows" ;;
|
cygwin_nt*) os="windows" ;;
|
||||||
|
mingw*) os="windows" ;;
|
||||||
|
msys_nt*) os="windows" ;;
|
||||||
esac
|
esac
|
||||||
echo "$os"
|
echo "$os"
|
||||||
}
|
}
|
||||||
@@ -186,9 +184,9 @@ uname_arch() {
|
|||||||
i686) arch="386" ;;
|
i686) arch="386" ;;
|
||||||
i386) arch="386" ;;
|
i386) arch="386" ;;
|
||||||
aarch64) arch="arm64" ;;
|
aarch64) arch="arm64" ;;
|
||||||
armv5*) arch="arm5" ;;
|
armv5*) arch="armv5" ;;
|
||||||
armv6*) arch="arm6" ;;
|
armv6*) arch="armv6" ;;
|
||||||
armv7*) arch="arm7" ;;
|
armv7*) arch="armv7" ;;
|
||||||
esac
|
esac
|
||||||
echo ${arch}
|
echo ${arch}
|
||||||
}
|
}
|
||||||
@@ -234,8 +232,8 @@ uname_arch_check() {
|
|||||||
untar() {
|
untar() {
|
||||||
tarball=$1
|
tarball=$1
|
||||||
case "${tarball}" in
|
case "${tarball}" in
|
||||||
*.tar.gz | *.tgz) tar -xzf "${tarball}" ;;
|
*.tar.gz | *.tgz) tar --no-same-owner -xzf "${tarball}" ;;
|
||||||
*.tar) tar -xf "${tarball}" ;;
|
*.tar) tar --no-same-owner -xf "${tarball}" ;;
|
||||||
*.zip) unzip "${tarball}" ;;
|
*.zip) unzip "${tarball}" ;;
|
||||||
*)
|
*)
|
||||||
log_err "untar unknown archive format for ${tarball}"
|
log_err "untar unknown archive format for ${tarball}"
|
||||||
@@ -243,11 +241,6 @@ untar() {
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
mktmpdir() {
|
|
||||||
test -z "$TMPDIR" && TMPDIR="$(mktemp -d)"
|
|
||||||
mkdir -p "${TMPDIR}"
|
|
||||||
echo "${TMPDIR}"
|
|
||||||
}
|
|
||||||
http_download_curl() {
|
http_download_curl() {
|
||||||
local_file=$1
|
local_file=$1
|
||||||
source_url=$2
|
source_url=$2
|
||||||
@@ -368,7 +361,7 @@ uname_arch_check "$ARCH"
|
|||||||
|
|
||||||
parse_args "$@"
|
parse_args "$@"
|
||||||
|
|
||||||
check_platform
|
get_binaries
|
||||||
|
|
||||||
tag_to_version
|
tag_to_version
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
// E.g. variable merger, template processing, etc.
|
// E.g. variable merger, template processing, etc.
|
||||||
type Compiler interface {
|
type Compiler interface {
|
||||||
GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error)
|
GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error)
|
||||||
|
FastGetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error)
|
||||||
HandleDynamicVar(v taskfile.Var, dir string) (string, error)
|
HandleDynamicVar(v taskfile.Var, dir string) (string, error)
|
||||||
ResetCache()
|
ResetCache()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,11 @@ type CompilerV2 struct {
|
|||||||
muDynamicCache sync.Mutex
|
muDynamicCache sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FastGetVariables is a no-op on v2
|
||||||
|
func (c *CompilerV2) FastGetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
||||||
|
return c.GetVariables(t, call)
|
||||||
|
}
|
||||||
|
|
||||||
// GetVariables returns fully resolved variables following the priority order:
|
// GetVariables returns fully resolved variables following the priority order:
|
||||||
// 1. Task variables
|
// 1. Task variables
|
||||||
// 2. Call variables
|
// 2. Call variables
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ var _ compiler.Compiler = &CompilerV3{}
|
|||||||
type CompilerV3 struct {
|
type CompilerV3 struct {
|
||||||
Dir string
|
Dir string
|
||||||
|
|
||||||
|
TaskfileEnv *taskfile.Vars
|
||||||
TaskfileVars *taskfile.Vars
|
TaskfileVars *taskfile.Vars
|
||||||
|
|
||||||
Logger *logger.Logger
|
Logger *logger.Logger
|
||||||
@@ -29,6 +30,14 @@ type CompilerV3 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
||||||
|
return c.getVariables(t, call, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CompilerV3) FastGetVariables(t *taskfile.Task, call taskfile.Call) (*taskfile.Vars, error) {
|
||||||
|
return c.getVariables(t, call, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *CompilerV3) getVariables(t *taskfile.Task, call taskfile.Call, evaluateShVars bool) (*taskfile.Vars, error) {
|
||||||
result := compiler.GetEnviron()
|
result := compiler.GetEnviron()
|
||||||
result.Set("TASK", taskfile.Var{Static: t.Task})
|
result.Set("TASK", taskfile.Var{Static: t.Task})
|
||||||
|
|
||||||
@@ -36,6 +45,11 @@ func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi
|
|||||||
return func(k string, v taskfile.Var) error {
|
return func(k string, v taskfile.Var) error {
|
||||||
tr := templater.Templater{Vars: result, RemoveNoValue: true}
|
tr := templater.Templater{Vars: result, RemoveNoValue: true}
|
||||||
|
|
||||||
|
if !evaluateShVars {
|
||||||
|
result.Set(k, taskfile.Var{Static: tr.Replace(v.Static)})
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
v = taskfile.Var{
|
v = taskfile.Var{
|
||||||
Static: tr.Replace(v.Static),
|
Static: tr.Replace(v.Static),
|
||||||
Sh: tr.Replace(v.Sh),
|
Sh: tr.Replace(v.Sh),
|
||||||
@@ -54,6 +68,9 @@ func (c *CompilerV3) GetVariables(t *taskfile.Task, call taskfile.Call) (*taskfi
|
|||||||
}
|
}
|
||||||
rangeFunc := getRangeFunc(c.Dir)
|
rangeFunc := getRangeFunc(c.Dir)
|
||||||
|
|
||||||
|
if err := c.TaskfileEnv.Range(rangeFunc); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
if err := c.TaskfileVars.Range(rangeFunc); err != nil {
|
if err := c.TaskfileVars.Range(rangeFunc); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
16
task.go
16
task.go
@@ -71,7 +71,7 @@ func (e *Executor) Run(ctx context.Context, calls ...taskfile.Call) error {
|
|||||||
|
|
||||||
if e.Summary {
|
if e.Summary {
|
||||||
for i, c := range calls {
|
for i, c := range calls {
|
||||||
compiledTask, err := e.CompiledTask(c)
|
compiledTask, err := e.FastCompiledTask(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -168,6 +168,7 @@ func (e *Executor) Setup() error {
|
|||||||
} else {
|
} else {
|
||||||
e.Compiler = &compilerv3.CompilerV3{
|
e.Compiler = &compilerv3.CompilerV3{
|
||||||
Dir: e.Dir,
|
Dir: e.Dir,
|
||||||
|
TaskfileEnv: e.Taskfile.Env,
|
||||||
TaskfileVars: e.Taskfile.Vars,
|
TaskfileVars: e.Taskfile.Vars,
|
||||||
Logger: e.Logger,
|
Logger: e.Logger,
|
||||||
}
|
}
|
||||||
@@ -396,10 +397,19 @@ func getEnviron(t *taskfile.Task) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
environ := os.Environ()
|
environ := os.Environ()
|
||||||
|
|
||||||
for k, v := range t.Env.ToCacheMap() {
|
for k, v := range t.Env.ToCacheMap() {
|
||||||
if s, ok := v.(string); ok {
|
str, isString := v.(string)
|
||||||
environ = append(environ, fmt.Sprintf("%s=%s", k, s))
|
if !isString {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if _, alreadySet := os.LookupEnv(k); alreadySet {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
environ = append(environ, fmt.Sprintf("%s=%s", k, str))
|
||||||
}
|
}
|
||||||
|
|
||||||
return environ
|
return environ
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,6 +126,7 @@ func TestVarsV3(t *testing.T) {
|
|||||||
"var-order.txt": "ABCDEF\n",
|
"var-order.txt": "ABCDEF\n",
|
||||||
"dependent-sh.txt": "123456\n",
|
"dependent-sh.txt": "123456\n",
|
||||||
"with-call.txt": "Hi, ABC123!\n",
|
"with-call.txt": "Hi, ABC123!\n",
|
||||||
|
"from-dot-env.txt": "From .env file\n",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tt.Run(t)
|
tt.Run(t)
|
||||||
|
|||||||
1
testdata/vars/v3/.env
vendored
Normal file
1
testdata/vars/v3/.env
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
DOT_ENV_VAR=From .env file
|
||||||
5
testdata/vars/v3/Taskfile.yml
vendored
5
testdata/vars/v3/Taskfile.yml
vendored
@@ -1,5 +1,7 @@
|
|||||||
version: '3'
|
version: '3'
|
||||||
|
|
||||||
|
dotenv: [.env]
|
||||||
|
|
||||||
vars:
|
vars:
|
||||||
VAR_A: A
|
VAR_A: A
|
||||||
VAR_B: '{{.VAR_A}}B'
|
VAR_B: '{{.VAR_A}}B'
|
||||||
@@ -15,6 +17,7 @@ tasks:
|
|||||||
- task: var-order
|
- task: var-order
|
||||||
- task: dependent-sh
|
- task: dependent-sh
|
||||||
- task: with-call
|
- task: with-call
|
||||||
|
- task: from-dot-env
|
||||||
|
|
||||||
missing-var: echo '{{.NON_EXISTING_VAR}}' > missing-var.txt
|
missing-var: echo '{{.NON_EXISTING_VAR}}' > missing-var.txt
|
||||||
|
|
||||||
@@ -44,3 +47,5 @@ tasks:
|
|||||||
MESSAGE: Hi, {{.ABC123}}!
|
MESSAGE: Hi, {{.ABC123}}!
|
||||||
cmds:
|
cmds:
|
||||||
- echo "{{.MESSAGE}}" > with-call.txt
|
- echo "{{.MESSAGE}}" > with-call.txt
|
||||||
|
|
||||||
|
from-dot-env: echo '{{.DOT_ENV_VAR}}' > from-dot-env.txt
|
||||||
|
|||||||
35
variables.go
35
variables.go
@@ -13,12 +13,27 @@ import (
|
|||||||
// CompiledTask returns a copy of a task, but replacing variables in almost all
|
// CompiledTask returns a copy of a task, but replacing variables in almost all
|
||||||
// properties using the Go template package.
|
// properties using the Go template package.
|
||||||
func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||||
|
return e.compiledTask(call, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
// FastCompiledTask is like CompiledTask, but it skippes dynamic variables.
|
||||||
|
func (e *Executor) FastCompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
||||||
|
return e.compiledTask(call, false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *Executor) compiledTask(call taskfile.Call, evaluateShVars bool) (*taskfile.Task, error) {
|
||||||
origTask, ok := e.Taskfile.Tasks[call.Task]
|
origTask, ok := e.Taskfile.Tasks[call.Task]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, &taskNotFoundError{call.Task}
|
return nil, &taskNotFoundError{call.Task}
|
||||||
}
|
}
|
||||||
|
|
||||||
vars, err := e.Compiler.GetVariables(origTask, call)
|
var vars *taskfile.Vars
|
||||||
|
var err error
|
||||||
|
if evaluateShVars {
|
||||||
|
vars, err = e.Compiler.GetVariables(origTask, call)
|
||||||
|
} else {
|
||||||
|
vars, err = e.Compiler.FastGetVariables(origTask, call)
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -59,16 +74,18 @@ func (e *Executor) CompiledTask(call taskfile.Call) (*taskfile.Task, error) {
|
|||||||
new.Env = &taskfile.Vars{}
|
new.Env = &taskfile.Vars{}
|
||||||
new.Env.Merge(r.ReplaceVars(e.Taskfile.Env))
|
new.Env.Merge(r.ReplaceVars(e.Taskfile.Env))
|
||||||
new.Env.Merge(r.ReplaceVars(origTask.Env))
|
new.Env.Merge(r.ReplaceVars(origTask.Env))
|
||||||
err = new.Env.Range(func(k string, v taskfile.Var) error {
|
if evaluateShVars {
|
||||||
static, err := e.Compiler.HandleDynamicVar(v, new.Dir)
|
err = new.Env.Range(func(k string, v taskfile.Var) error {
|
||||||
|
static, err := e.Compiler.HandleDynamicVar(v, new.Dir)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
new.Env.Set(k, taskfile.Var{Static: static})
|
||||||
|
return nil
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
new.Env.Set(k, taskfile.Var{Static: static})
|
|
||||||
return nil
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(origTask.Cmds) > 0 {
|
if len(origTask.Cmds) > 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user