### Taskfile Configuration Structure Source: https://github.com/go-task/task/blob/main/website/src/docs/getting-started.md Example of a standard Taskfile.yml structure defining global variables and task commands. ```yaml version: '3' vars: GREETING: Hello, World! tasks: default: desc: Print a greeting message cmds: - echo "{{.GREETING}}" silent: true build: cmds: - go build ./cmd/main.go ``` -------------------------------- ### Run Task Website Locally Source: https://github.com/go-task/task/blob/main/website/src/docs/contributing.md This command starts the local documentation server using Vitepress. Ensure you have Node.js and pnpm installed. ```bash task website ``` -------------------------------- ### Execute Tasks via CLI Source: https://github.com/go-task/task/blob/main/website/src/docs/getting-started.md Commands to trigger task execution. Includes running default tasks, targeting specific directories, and specifying custom Taskfile names. ```shell task default task --dir ./subdirectory task --taskfile Custom.yml task build ``` -------------------------------- ### Install Task via APK Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Set up the repository and install Task on Alpine Linux. ```shell curl -1sLf 'https://dl.cloudsmith.io/public/task/task/setup.alpine.sh' | sudo -E bash ``` ```shell apk add task ``` -------------------------------- ### Short Task Syntax Example Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Starting on Task v3, tasks with default settings can be written with a shorter syntax. This example shows a 'build' task and a 'run' task using this syntax. ```yaml version: '3' tasks: build: go build -v -o ./app{{exeExt}} . run: - task: build - ./app{{exeExt}} -h localhost -p 8080 ``` -------------------------------- ### Initialize Taskfile via CLI Source: https://github.com/go-task/task/blob/main/website/src/docs/getting-started.md Commands to generate a new Taskfile. Supports default initialization, specifying a target directory, or defining a custom filename. ```shell task --init task --init ./subdirectory task --init Custom.yml ``` -------------------------------- ### Install Task via APT Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Set up the repository and install Task on Ubuntu, Debian, or Linux Mint systems. ```shell curl -1sLf 'https://dl.cloudsmith.io/public/task/task/setup.deb.sh' | sudo -E bash ``` ```shell apt install task ``` -------------------------------- ### Install Task via Go Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task using the Go toolchain globally or into a specific directory. ```shell go install github.com/go-task/task/v3/cmd/task@latest ``` ```shell env GOBIN=/bin go install github.com/go-task/task/v3/cmd/task@latest ``` -------------------------------- ### Install Task via Snap Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task using Snapcraft, ensuring classic confinement is enabled. ```shell sudo snap install task --classic ``` -------------------------------- ### Install Task via Shell Script Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Use the install script for CI scenarios. Parameters are order-specific. ```shell sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d ``` ```shell sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin ``` ```shell sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d v3.36.0 ``` ```shell sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin v3.42.1 ``` -------------------------------- ### Install Task via Nix Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task using the Nix package manager. ```shell nix-env -iA nixpkgs.go-task ``` -------------------------------- ### Install Task via DNF Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Set up the repository and install Task on Fedora, CentOS, or Red Hat systems. ```shell curl -1sLf 'https://dl.cloudsmith.io/public/task/task/setup.rpm.sh' | sudo -E bash ``` ```shell dnf install task ``` -------------------------------- ### Install Task via pip Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install the Task binary package using pip. ```shell pip install go-task-bin ``` -------------------------------- ### Install Task via GitHub Actions Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Use the official setup-task action in GitHub workflows. ```yaml - name: Install Task uses: go-task/setup-task@v1 ``` -------------------------------- ### Install Task via WinGet Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on Windows using the WinGet community repository. ```shell winget install Task.Task ``` -------------------------------- ### Install Development Dependencies with Mise Source: https://github.com/go-task/task/blob/main/website/src/docs/contributing.md Installs the required Go, Node.js, pnpm, and development tools using Mise, based on versions specified in mise.toml. ```shell mise install ``` -------------------------------- ### Install Task via Scoop Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on Windows using the Scoop package manager. ```shell scoop install task ``` -------------------------------- ### Install Task via Homebrew Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task using the official tap or the Homebrew core repository. ```shell brew install go-task/tap/go-task ``` ```shell brew install go-task ``` -------------------------------- ### Install Task via dnf Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on Fedora using the dnf package manager. ```shell dnf install go-task ``` -------------------------------- ### Install Task via Mise Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Use the aqua or ubi backends to install Task directly from GitHub releases. ```shell mise use -g aqua:go-task/task@latest mise install ``` ```shell mise use -g ubi:go-task/task mise install ``` -------------------------------- ### Install Task via pacstall Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on Debian or Ubuntu using the pacstall package manager. ```shell pacstall -I go-task-deb ``` -------------------------------- ### Install Task via FreeBSD Ports Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on FreeBSD using the pkg package manager. ```shell pkg install task ``` -------------------------------- ### Install Task via Chocolatey Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on Windows using the Chocolatey package manager. ```shell choco install go-task ``` -------------------------------- ### Install Task via pacman Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task on Arch Linux using the pacman package manager. ```shell pacman -S go-task ``` -------------------------------- ### Install Task via NPM Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install Task globally using the npm package manager. ```shell npm install -g @go-task/cli ``` -------------------------------- ### Install Task via pkgx Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Run Task using the pkgx package manager. ```shell pkgx task ``` ```shell task ``` -------------------------------- ### Install Task via Macports Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Install the Task package using the Macports package manager. ```shell port install go-task ``` -------------------------------- ### JSON Output Example Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md An example of the JSON output format when using the --json flag with --list or --list-all. This structure provides detailed information about each task, including its name, description, and file location. ```json { "tasks": [ { "name": "build", "task": "build", "desc": "Build the application", "summary": "Compiles the source code and generates binaries", "up_to_date": false, "location": { "line": 12, "column": 3, "taskfile": "/path/to/Taskfile.yml" } } ], "location": "/path/to/Taskfile.yml" } ``` -------------------------------- ### Task Summary Output Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Example output when viewing a task's summary using `task --summary `. It includes the task name, summary, dependencies, and commands. ```text task: release Release your project to github It will build your project before starting the release. Please make sure that you have set GITHUB_TOKEN before starting. dependencies: - build commands: - your-release-tool ``` -------------------------------- ### Shell Prompt Confirmation Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Example of how the prompt appears in the shell and how a user might respond. ```shell ❯ task dangerous task: "This is a dangerous command... Do you want to continue?" [y/N] ``` -------------------------------- ### Example Taskfile Configuration Source: https://github.com/go-task/task/blob/main/website/src/docs/experiments/remote-taskfiles.md A sample YAML configuration for a Taskfile, demonstrating the version declaration and basic task definitions. ```yaml version: '3' tasks: default: cmds: - task: hello hello: cmds: - echo "Hello Task!" ``` -------------------------------- ### Regular Expression Functions Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Provides examples for using regex functions: regexMatch, regexFind, regexFindAll, and regexReplaceAll. ```yaml tasks: regex: vars: EMAIL: 'user@example.com' TEXT: 'abc123def456' cmds: - echo "{{regexMatch "@" .EMAIL}}" # true - echo "{{regexFind "[0-9]+" .TEXT}}" # "123" - echo "{{regexFindAll "[0-9]+" .TEXT -1}}" # ["123", "456"] - echo "{{regexReplaceAll "[0-9]+" .TEXT "X"}}" # "abcXdefX" ``` -------------------------------- ### Show Task Version Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md Displays the installed version of Task. ```bash task --version ``` -------------------------------- ### Flattened Includes with Task Execution Example Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Demonstrates running a flattened task directly and within another task. ```text task: Available tasks for this project: * greet: * foo ``` -------------------------------- ### Combined Status and Generation Checks Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md This example combines 'sources', 'generates', and 'status' to ensure a production build task runs only when necessary. It executes if source files change, if generated files are missing, or if the last build was not for production. ```yaml version: '3' tasks: build:prod: desc: Build for production usage. cmds: - composer install # Run this task if source files changes. sources: - composer.json - composer.lock generates: - ./vendor/composer/installed.json - ./vendor/autoload.php # But also run the task if the last build was not a production build. status: - grep -q '"dev"{{:}} false' ./vendor/composer/installed.json ``` -------------------------------- ### Date and Time Formatting Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Get the current time, convert strings to dates, and format dates using date/time functions. ```yaml tasks: date-time: vars: BUILD_DATE: "2023-12-25" cmds: - echo "Now {{now | date "2006-01-02 15:04:05"}}" - echo {{ toDate "2006-01-02" .BUILD_DATE }} - echo "Build {{.BUILD_DATE | toDate "2006-01-02" | date "Jan 2, 2006"}}" - echo "Unix timestamp {{now | unixEpoch}}" - echo "Duration ago {{now | ago}}" ``` -------------------------------- ### Basic Task Definition Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Defines a simple task that echoes a string. This is a basic example to show command execution. ```yaml version: '3' tasks: echo: cmds: - echo "Print something" ``` -------------------------------- ### Taskfile.yml Formatting Conventions Source: https://github.com/go-task/task/blob/main/website/src/docs/styleguide.md Demonstrates standard indentation, spacing between sections, and task separation practices for improved YAML readability. ```yaml # Good indentation tasks: foo: cmds: - echo 'foo' # Good section separation version: '3' includes: docker: ./docker/Taskfile.yml vars: FOO: bar tasks: foo: cmds: - echo 'foo' bar: cmds: - echo 'bar' ``` -------------------------------- ### Taskfile.yml Naming and Templating Source: https://github.com/go-task/task/blob/main/website/src/docs/styleguide.md Guidelines for variable naming (uppercase), template syntax (no whitespace), and task naming (kebab-case with namespaces). ```yaml vars: BINARY_NAME: myapp tasks: greet: cmds: - echo '{{.MESSAGE}}' docker:build: cmds: - docker build . ``` -------------------------------- ### Taskfile.yml Section Ordering Source: https://github.com/go-task/task/blob/main/website/src/docs/styleguide.md Defines the recommended sequence for top-level keys in a Taskfile.yml to maintain a consistent project structure. ```yaml version: includes: # optional configurations (output, silent, method, run, etc.) vars: env: # followed or replaced by dotenv tasks: ``` -------------------------------- ### Get Help Information Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md Displays help information for the Task CLI. This includes a list of available commands and options. ```bash task --help ``` -------------------------------- ### Enable Experiment in .env file Source: https://github.com/go-task/task/blob/main/website/src/docs/experiments/index.md This example shows how to enable a Task experiment by setting an environment variable in a .env file. This approach is useful for project-level configuration and can be used in conjunction with or as an alternative to .taskrc.yml. The variable name follows the 'TASK_X_{FEATURE}' pattern, and '1' indicates enablement. ```shell TASK_X_FEATURE=1 ``` -------------------------------- ### Define a complete Task configuration file Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/config.md A comprehensive example of a .taskrc.yml file demonstrating the structure for global settings and experimental feature activation. ```yaml # Global settings verbose: true silent: false color: true disable-fuzzy: false concurrency: 2 # Enable experimental features experiments: REMOTE_TASKFILES: 1 ``` -------------------------------- ### Externalizing Complex Logic Source: https://github.com/go-task/task/blob/main/website/src/docs/styleguide.md Recommends moving complex multi-line inline commands into external shell scripts for better maintainability. ```yaml tasks: build: cmds: - ./scripts/my_complex_script.sh ``` -------------------------------- ### Load Shell Completions via Startup Config Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Recommended method to load completions dynamically in shell startup files. ```shell # ~/.bashrc # export TASK_EXE='go-task' if needed eval "$(task --completion bash)" ``` ```shell # ~/.zshrc # export TASK_EXE='go-task' if needed eval "$(task --completion zsh)" ``` ```shell # ~/.config/fish/config.fish # export TASK_EXE='go-task' if needed task --completion fish | source ``` ```powershell # $PROFILE\Microsoft.PowerShell_profile.ps1 Invoke-Expression (&task --completion powershell | Out-String) ``` -------------------------------- ### Control Core Utilities on Windows (Bash) Source: https://github.com/go-task/task/blob/main/website/src/docs/faq.md Provides examples of how to enable or disable the built-in Go-compiled core utilities on Windows using the TASK_CORE_UTILS environment variable. This allows for greater control over compatibility when running Task on different platforms. ```bash # Enable, even on non-Windows platforms env TASK_CORE_UTILS=1 task ... # Disable, even on Windows env TASK_CORE_UTILS=0 task ... ``` -------------------------------- ### Taskfile with Task Descriptions Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md A sample Taskfile defining build, test, js, and css tasks with descriptions for some. ```yaml version: '3' tasks: build: desc: Build the go binary. cmds: - go build -v -i main.go test: desc: Run all the go tests. cmds: - go test -race ./... js: cmds: - esbuild --bundle --minify js/index.js > public/bundle.js css: cmds: - esbuild --bundle --minify css/index.css > public/bundle.css ``` -------------------------------- ### Task Execution with Prompts and User Approval Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Demonstrates the output flow when a task with prompts is executed and the user approves. ```shell ❯ task example not dangerous command task: "This is a dangerous command. Do you want to continue?" [y/N] y dangerous command another not dangerous command ``` -------------------------------- ### Task Listing with Descriptions Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Demonstrates how `task --list` displays tasks and their descriptions from a Taskfile. ```shell * build: Build the go binary. * test: Run all the go tests. ``` -------------------------------- ### Read and Merge Taskfiles in Go Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/package.md Demonstrates the complete workflow for reading a Taskfile from the local filesystem using a FileNode, initializing a Reader with debug options, and merging the resulting Taskfile graph into a single Taskfile object. ```go import ( "context" "log/slog" "github.com/go-task/task/v3/taskfile" ) // Create a node for the local file node := taskfile.NewFileNode("Taskfile.yml", "./path/to/dir") // Initialize the reader with optional debug function reader := taskfile.NewReader( taskfile.WithDebugFunc(func(s string) { slog.Debug(s) }), ) // Read the taskfile graph ctx := context.Background() tfg, err := reader.Read(ctx, node) if err != nil { // handle error } // Merge the graph into a single Taskfile tf, err := tfg.Merge() if err != nil { // handle error } ``` -------------------------------- ### Getting Length with LEN Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Demonstrates using the LEN function to get the number of items in arrays/maps or characters in strings. ```yaml tasks: length: vars: ITEMS: [a, b, c, d] TEXT: "Hello World" cmds: - echo "Found {{len .ITEMS}} items" - echo "Text has {{len .TEXT}} characters" ``` -------------------------------- ### Basic Taskfile Includes Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Include other Taskfiles by specifying their paths. Tasks from included files are accessed using a namespace. ```yaml version: '3' includes: docs: ./documentation # will look for ./documentation/Taskfile.yml docker: ./DockerTasks.yml ``` -------------------------------- ### Included Taskfile with Excluded Task Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Example of an included Taskfile where a task is explicitly excluded. ```yaml version: '3' tasks: foo: echo "Foo" bar: echo "Bar" ``` -------------------------------- ### Checksum Status with Timestamp Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Example of using the CHECKSUM method with a timestamp to compare file checksums. ```yaml tasks: build: method: checksum sources: ['**/*.go'] status: - test "{{.CHECKSUM}}" = "$(cat .last-checksum)" cmds: - go build ./... - echo "{{.CHECKSUM}}" > .last-checksum ``` -------------------------------- ### Run Task via Go Tool Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Add Task as a tool to a Go project and execute it using go tool. ```bash go get -tool github.com/go-task/task/v3/cmd/task@latest ``` ```bash go tool task {arguments...} ``` -------------------------------- ### Slicing Arrays or Strings with SLICE Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Example of using the SLICE function to extract a portion of an array or string. ```yaml tasks: slice-demo: vars: ITEMS: [a, b, c, d, e] cmds: - echo "{{slice .ITEMS 1 3}}" # [b c] ``` -------------------------------- ### Initialize Taskfile Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md Creates a new Taskfile.yml in the current directory. Short-hand aliases are also provided. ```bash task --init task -i ``` -------------------------------- ### Global and Working Directory Tasks Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Demonstrates two tasks: one that runs in the home directory (default for global tasks) and another that runs in the user's working directory using the 'dir' attribute. ```yaml version: '3' tasks: from-home: cmds: - pwd from-working-directory: dir: '{{.USER_WORKING_DIR}}' cmds: - pwd ``` -------------------------------- ### Deferring Actions with EXIT_CODE Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Example of using the EXIT_CODE variable within a defer block to handle command failures. ```yaml tasks: deploy: cmds: - ./deploy.sh - defer: | {{if .EXIT_CODE}} echo "Deployment failed with code {{.EXIT_CODE}}" ./rollback.sh {{end}} ``` -------------------------------- ### Run Development Build with Test Taskfile Source: https://github.com/go-task/task/blob/main/website/src/docs/contributing.md Execute a development build of Task against a specific test Taskfile in the testdata directory. Replace `` and `` with your specific test details. ```bash go run ./cmd/task --dir ./testdata/ ``` -------------------------------- ### Execute Task via go tool Source: https://github.com/go-task/task/blob/main/website/src/blog/go-tool-task.md Use this command prefix to run Task using the version managed by the Go toolchain. ```bash go tool task {arguments...} ``` -------------------------------- ### Task with Silent Dependencies Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Mark a dependency as silent to prevent its output from being displayed. Useful for setup tasks that don't need user visibility. ```yaml tasks: main: deps: - task: setup silent: true cmds: - echo "Main task" ``` -------------------------------- ### Call Task with Multiple Wildcard Arguments Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Illustrates calling a task that accepts multiple wildcard arguments. The arguments are captured and used to set service and replica variables. ```shell $ task start:foo:3 Starting foo with 3 replicas ``` -------------------------------- ### List All Tasks Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md Lists all available tasks along with their descriptions. Short-hand aliases are also provided. ```bash task --list task -l ``` -------------------------------- ### View tool entry in go.mod Source: https://github.com/go-task/task/blob/main/website/src/blog/go-tool-task.md The tool dependency will appear in your go.mod file in the following format. ```text tool github.com/go-task/task/v3/cmd/task ``` -------------------------------- ### Pin Remote Taskfile Checksums Source: https://github.com/go-task/task/blob/main/website/src/docs/experiments/remote-taskfiles.md Provides an example of manually pinning a checksum for a remote Taskfile to ensure security and prevent unexpected changes. ```yaml version: '3' includes: included: taskfile: https://taskfile.dev checksum: c153e97e0b3a998a7ed2e61064c6ddaddd0de0c525feefd6bba8569827d8efe9 ``` -------------------------------- ### Basic String Manipulations Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Illustrates common string operations like trim, title, upper, lower, repeat, and substr. ```yaml tasks: string-basic: vars: MESSAGE: ' Hello World ' NAME: 'john doe' TEXT: "Hello World" cmds: - echo "{{.MESSAGE | trim}}" # "Hello World" - echo "{{.NAME | title}}" # "John Doe" - echo "{{.NAME | upper}}" # "JOHN DOE" - echo "{{.MESSAGE | lower}}" # "hello world" - echo "{{.NAME | trunc 4}}" # "john" - echo "{{"test" | repeat 3}}" # "testtesttest" - echo "{{.TEXT | substr 0 5}}" # "Hello" ``` -------------------------------- ### Configure Task runtime settings Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/config.md Examples of various boolean and integer configuration options available in Task, such as verbosity, concurrency, and interactive mode. ```yaml verbose: true silent: true color: false disable-fuzzy: true concurrency: 4 failfast: true interactive: true ``` -------------------------------- ### Run Tasks Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md Executes one or more tasks defined in the Taskfile. Examples show running a single task, multiple tasks, and a task with a flag. ```bash task build task test lint task deploy --force ``` -------------------------------- ### Set and Shopt Options in Taskfile Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Specify shell options like 'pipefail' and 'globstar' at the global level in your Taskfile. 'globstar' is required for double-star globs. ```yaml version: '3' set: [pipefail] shopt: [globstar] tasks: # `globstar` required for double star globs to work default: echo **/*.go ``` -------------------------------- ### Define Remote Taskfile URIs Source: https://github.com/go-task/task/blob/main/website/src/docs/experiments/remote-taskfiles.md Examples of URI formats for referencing Taskfiles via direct HTTP/HTTPS downloads or Git repositories. These URIs can be used as entrypoints or included within other Taskfiles. ```text https://raw.githubusercontent.com/go-task/task/main/website/src/public/Taskfile.yml ``` ```text https://github.com/go-task/task.git//website/src/public/Taskfile.yml?ref=main ``` ```text git@github.com/go-task/task.git//website/src/public/Taskfile.yml?ref=main ``` -------------------------------- ### OS-Specific Taskfile Includes Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Include OS-specific Taskfiles by using the OS templating function in the path. ```yaml version: '3' includes: build: ./Taskfile_{{OS}}.yml ``` -------------------------------- ### Add Task as a Go tool dependency Source: https://github.com/go-task/task/blob/main/website/src/blog/go-tool-task.md Run this command to add the Task binary as a tool dependency to your project's go.mod file. ```bash go get -tool github.com/go-task/task/v3/cmd/task@latest ``` -------------------------------- ### Task Execution Failure Due to Failing Precondition Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md This example illustrates how a task with a failing precondition, or a dependency on a task with a failing precondition, will cause the task to fail. The 'task-will-fail' task has a precondition that always exits with 1, causing subsequent dependent tasks to also fail. ```yaml version: '3' tasks: task-will-fail: preconditions: - sh: 'exit 1' task-will-also-fail: deps: - task-will-fail task-will-still-fail: cmds: - task: task-will-fail - echo "I will not run" ``` -------------------------------- ### Configure Trusted Hosts for Remote Taskfiles (YAML) Source: https://github.com/go-task/task/blob/main/website/src/docs/experiments/remote-taskfiles.md This snippet shows how to configure a list of trusted hosts for remote Taskfiles in YAML format. These hosts will not prompt for confirmation when downloading Taskfiles. The configuration includes examples of specifying hosts with and without ports. ```yaml remote: trusted-hosts: - github.com - gitlab.com - raw.githubusercontent.com - example.com:8080 ``` -------------------------------- ### Basic Task Dependencies Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Defines a 'build' task that depends on an 'assets' task. The 'assets' task will run before 'build'. ```yaml version: '3' tasks: build: deps: [assets] cmds: - go build -v -i main.go assets: cmds: - esbuild --bundle --minify css/index.css > public/bundle.css ``` -------------------------------- ### Trust Hosts via CLI for Remote Taskfiles (Shell) Source: https://github.com/go-task/task/blob/main/website/src/docs/experiments/remote-taskfiles.md Demonstrates how to specify trusted hosts for remote Taskfiles using the Go-Task CLI. This includes examples for trusting a single host, multiple hosts (comma-separated), and a host with a specific port for a given execution. ```shell # Trust specific host for this execution task --trusted-hosts github.com -t https://github.com/user/repo.git//Taskfile.yml # Trust multiple hosts (comma-separated) task --trusted-hosts github.com,gitlab.com -t https://github.com/user/repo.git//Taskfile.yml # Trust a host with a specific port task --trusted-hosts example.com:8080 -t https://example.com:8080/Taskfile.yml ``` -------------------------------- ### Task with Loop Dependencies Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Define dependencies that iterate over a list, running the specified task for each item. Use the `ITEM` variable to access the current item. ```yaml tasks: test-all: deps: - for: [unit, integration, e2e] task: test vars: TEST_TYPE: '{{.ITEM}}' cmds: - echo "All tests completed" ``` -------------------------------- ### Formatted Output Functions Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Utilize `print`, `printf`, and `println` for formatted string output. `printf` allows for C-style format specifiers. ```yaml tasks: output: vars: VERSION: "1.2.3" BUILD: 42 cmds: - echo '{{print "Simple output"}}' - echo '{{printf "Version %s.%d" .VERSION .BUILD}}' - echo '{{println "With newline"}}' ``` -------------------------------- ### Configure VS Code YAML Schema for Taskfiles Source: https://github.com/go-task/task/blob/main/website/src/docs/integrations.md This JSON configuration snippet allows Visual Studio Code to automatically validate and provide autocompletion for Taskfile.yml files using the official schema. It requires the Red Hat YAML extension to be installed. The configuration maps the schema URL to glob patterns matching Taskfile names. ```json // settings.json { "yaml.schemas": { "https://taskfile.dev/schema.json": [ "**/Taskfile.yml", "./path/to/any/other/taskfile.yml" ] } } ``` -------------------------------- ### Copy Shell Completions to Directory Source: https://github.com/go-task/task/blob/main/website/src/docs/installation.md Manually copy completion scripts to the system's completion directory. ```shell task --completion bash > /etc/bash_completion.d/task ``` ```shell task --completion zsh > /usr/local/share/zsh/site-functions/_task ``` ```shell task --completion fish > ~/.config/fish/completions/task.fish ``` -------------------------------- ### Loop Over Static List Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Execute a command for each item in a predefined static list. ```yaml version: '3' tasks: default: cmds: - for: ['foo.txt', 'bar.txt'] cmd: cat {{ .ITEM }} ``` -------------------------------- ### Loop Over Sources with Absolute Path Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Iterate over task sources and construct absolute paths using the 'joinPath' function. Ensure 'dir' is set correctly. ```yaml version: '3' tasks: default: vars: MY_DIR: /path/to/dir dir: '{{.MY_DIR}}' sources: - foo.txt - bar.txt cmds: - for: sources cmd: cat {{joinPath .MY_DIR .ITEM}} ``` -------------------------------- ### Call Task with Single Wildcard Argument Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Demonstrates calling a task with a single wildcard argument. The argument is captured and used within the task's commands. ```shell $ task start:foo Starting foo ``` -------------------------------- ### Format Code Source: https://github.com/go-task/task/blob/main/website/src/docs/contributing.md Execute the `task fmt` command to auto-format files according to the project's style guidelines. This is useful if your editor does not automatically format on save. ```bash task fmt ``` -------------------------------- ### Simple Task: Array of Commands Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Define a task that executes multiple commands sequentially by providing them as an array of strings. Each string is a separate command. ```yaml tasks: build: - go mod tidy - go build ./... ``` -------------------------------- ### Basic Task Commands Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Define a list of shell commands to be executed sequentially for a task. ```yaml tasks: example: cmds: - echo "Simple command" - ls -la ``` -------------------------------- ### Task with Multiple Prompts Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Configure multiple prompts that must be answered before a task can execute. Useful for multi-step confirmation processes. ```yaml tasks: deploy-multi: prompt: - "Are you sure?" - "This will affect live users!" cmds: - ./deploy.sh ``` -------------------------------- ### Watch Task Configuration Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Configure a task to automatically run in watch mode using 'watch: true' and specify files to monitor with 'sources'. The default watch interval is 100ms. ```yaml version: '3' interval: 500ms tasks: build: desc: Builds the Go application watch: true sources: - '**/*.go' cmds: - go build # ... ``` -------------------------------- ### Multiple Warning Prompts Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Define a list of prompts to sequentially ask the user for confirmation. ```yaml version: '3' tasks: example: cmds: - task: dangerous dangerous: prompt: - This is a dangerous command... Do you want to continue? - Are you sure? cmds: - echo 'dangerous command' ``` -------------------------------- ### Simple Task: String Command Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Define a task with a single command specified as a string. This is the most basic way to define a task. ```yaml tasks: hello: echo "Hello World" ``` -------------------------------- ### String Testing Functions Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Demonstrates string testing functions like hasPrefix, hasSuffix, and contains. ```yaml tasks: string-test: vars: FILENAME: 'app.tar.gz' EMAIL: 'user@example.com' cmds: - echo "{{.FILENAME | hasPrefix "app"}}" # true - echo "{{.FILENAME | hasSuffix ".gz"}}" # true - echo "{{.EMAIL | contains "@"}}" # true ``` -------------------------------- ### Task Precondition Check with Custom Message Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md This snippet shows how to use 'preconditions' to enforce conditions before a task runs. It includes a check for a .env file and a custom 'sh' command that will fail with a specific message if the condition is not met. ```yaml version: '3' tasks: generate-files: cmds: - mkdir directory - touch directory/file1.txt - touch directory/file2.txt # test existence of files preconditions: - test -f .env - sh: '[ 1 = 0 ]' msg: "One doesn't equal Zero, Halting" ``` -------------------------------- ### Task with Summary (`summary`) Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Add a detailed summary for a task, shown with the `--summary` flag. Useful for providing in-depth explanations of complex tasks. ```yaml tasks: deploy: desc: Deploy to production summary: | Deploy the application to production environment. This includes building, testing, and uploading artifacts. ``` -------------------------------- ### Task with Simple Dependencies Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/schema.md Specify tasks that must run before the current task using the `deps` property with an array of task names. Ensures prerequisites are met. ```yaml tasks: deploy: deps: [build, test] cmds: - ./deploy.sh ``` -------------------------------- ### Environment Variable Path Joining (Windows) Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Join multiple Windows path strings into a single environment variable path string. ```yaml tasks: paths: vars: WIN_PATH1: 'C:\\Users\\Person\\bin' WIN_PATH2: 'C:\\Shared\\bin' cmds: # Join paths for Windows ENV vars: # C:\Users\Person\bin;C:\Shared\bin - echo "{{joinEnv .WIN_PATH1 .WIN_PATH2}}" ``` -------------------------------- ### Restrict Individual Commands to Specific Platforms Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md This task demonstrates restricting individual commands to specific platforms. The first command runs on Windows (amd64) or macOS, while the second runs on all platforms. ```yaml version: '3' tasks: build: cmds: - cmd: echo 'Running command on Windows (amd64) and macOS' platforms: [windows/amd64, darwin] - cmd: echo 'Running on all platforms' ``` -------------------------------- ### Set Variables via Environment Variables Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Shows how to pass variables to Task using environment variables. This is an alternative method when direct shell syntax is not supported. ```shell $ TASK_VARIABLE=a-value task do-something ``` -------------------------------- ### Boolean Logic with AND, OR, NOT Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/templating.md Demonstrates using boolean functions AND, OR, and NOT for conditional logic. ```yaml tasks: conditional: vars: DEBUG: true VERBOSE: false PRODUCTION: false cmds: - echo "{{if and .DEBUG .VERBOSE}}Debug mode with verbose{{end}}" - echo "{{if or .DEBUG .VERBOSE}}Some kind of debug{{end}}" - echo "{{if not .PRODUCTION}}Development build{{end}}" ``` -------------------------------- ### Use Global Taskfile Source: https://github.com/go-task/task/blob/main/website/src/docs/reference/cli.md Runs the global Taskfile located at `$HOME/Taskfile.{yml,yaml}`. ```bash task backup --global ``` -------------------------------- ### Specify .env File Precedence Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Organize your `.env` files to manage overrides effectively. By listing files in order of priority (highest first), you can control which values take precedence. ```yaml version: '3' dotenv: - .env.local # Highest priority - local developer overrides - .env.{{.ENV}} # Environment-specific settings - .env # Base defaults (lowest priority) ``` -------------------------------- ### Run Task with Local Changes Source: https://github.com/go-task/task/blob/main/website/src/docs/contributing.md Use this command to run Task with your modifications. It allows you to test your changes directly. ```bash go run ./cmd/task ``` -------------------------------- ### Arithmetic Operations with Variables (Go Task) Source: https://github.com/go-task/task/blob/main/website/src/blog/any-variables.md Illustrates performing arithmetic operations on integer and float variables in Go Task. Supports functions like add, sub, mul, div, mod, max, min, floor, ceil, round, and randInt, leveraging slim-sprig math functions. ```yaml version: 3 tasks: foo: vars: INT: 10 FLOAT: 3.14159 cmds: - 'echo {{add .INT .FLOAT}}' ``` -------------------------------- ### Set Variables via Command Line Arguments Source: https://github.com/go-task/task/blob/main/website/src/docs/guide.md Illustrates setting variables directly on the command line when invoking a Task. This method allows for overriding default values. ```shell $ task write-file FILE=file.txt "CONTENT=Hello, World!" print "MESSAGE=All done!" ```