Files
git.taskfile.build/README.md
T
Janik von Rotz fc09e848fd feat: enhance shellcheck integration and improve code quality across task files
- Added new prompt file `prompts/07_run-shellcheck-and-fix-issues.md` for shellcheck linting and fixing
- Updated `help()` function in `task`, `task.template`, and `README.md` to use `local grep_pattern` variable for improved readability and maintainability
- Updated `lint()` function in `task` to run `shellcheck` on both `task` and `task.template` files
- Added `export` statements for `BUILDX_PLATFORM`, `CONTAINER_REGISTRY`, `CONTAINER_TAG`, and `DOCKERFILE` variables in `task` script
- Added `# shellcheck disable=SC1090` comment before sourcing files in `task` and `task.template` to suppress shellcheck warnings
- Updated `update-template()` function in `task` to use `local temp_file` declaration before assignment for better variable scoping
- Updated `help()` function in `task.template` to use `help "$@"` instead of `help` when displaying unknown command error
- Removed `disable=SC2059` from `.shellcheckrc` as it's no longer needed after code improvements
2026-02-14 11:36:44 +01:00

173 lines
4.1 KiB
Markdown

---
layout: layouts/base.njk
permalink: /
---
<hgroup>
<h1>./task</h1>
<p>Run any project.</p>
</hgroup>
[![.forgejo/workflows/build.yml](https://codeberg.org/janikvonrotz/taskfile.build/badges/workflows/build.yml/badge.svg)](https://codeberg.org/janikvonrotz/taskfile.build/actions?workflow=build.yml) ![Vercel](https://vercelbadge.vercel.app/api/janikvonrotz/taskfile.build)
---
The task file is a simple bash script and standardized interface for any software project.
It is to be understood as a software development pattern to standardize the installation, configuration and execution of different software frameworks.
- 🛠️ **Configuration**: Install and configure software and tools with ease.
- 🐳 **Docker Build**: Build and publish Docker images for your project.
- 🔑 **KeePass / Pass**: Store and load secrets from KeePass and pass.
- 📄 **.env / dotenv**: Manage multiple dotenv files for your projects.
- 🔄 **CI Pipelines**: Simplify CI pipelines by making the executed task reproducible.
- 📝 **Helper scripts**: There are many examples and commands that make scripting easier.
## Specification
The specification is a short guide to set up a task file for a Python project.
Create a file `task` in your project.
```bash
touch task
```
Ensure it is executable.
```bash
chmod +x task
```
First add the bash shebang.
```bash
#!/usr/bin/env bash
```
Then append the abort on error setting.
```bash
set -e
```
Add a help function.
```bash
help-table() {
local -a rows
local max_cmd=7 max_opt=6 max_desc=11
rows+=("Command|Option|Description")
rows+=("help|[grep]|Show help for commands.")
rows+=("install||Setup the local environment.")
rows+=("lint||Run pre-commit and update index.html.")
rows+=("version||Show version of required tools.")
for row in "${rows[@]}"; do
IFS='|' read -r cmd opt desc <<< "$row"
(( ${#cmd} > max_cmd )) && max_cmd=${#cmd}
(( ${#opt} > max_opt )) && max_opt=${#opt}
(( ${#desc} > max_desc )) && max_desc=${#desc}
done
printf '| %-*s | %-*s | %-*s |\n' \
"$max_cmd" "Command" \
"$max_opt" "Option" \
"$max_desc" "Description"
printf '|-%*s-|-%*s-|-%*s-|\n' \
"$max_cmd" "$(printf '%*s' "$max_cmd" '' | tr ' ' '-')" \
"$max_opt" "$(printf '%*s' "$max_opt" '' | tr ' ' '-')" \
"$max_desc" "$(printf '%*s' "$max_desc" '' | tr ' ' '-')"
for row in "${rows[@]:1}"; do
IFS='|' read -r cmd opt desc <<< "$row"
printf '| %-*s | %-*s | %-*s |\n' \
"$max_cmd" "$cmd" \
"$max_opt" "$opt" \
"$max_desc" "$desc"
done
}
help() {
local grep_pattern
echo
if [[ -n "$1" ]]; then
grep_pattern="$1"
help-table | grep -i "$grep_pattern" | column -t -s'|'
else
echo 'task <command> [options]'
echo
echo 'commands:'
echo
help-table
fi
echo
}
```
Setup the command functions.
```bash
install() {
echo 'Setup venv and install python dependencies'
uv venv env
source env/bin/activate
uv pip install pre-commit
}
lint() {
source env/bin/activate
echo 'Run pre-commit'
pre-commit run --all-file
}
version() {
uv --version
}
```
Finish the task file with command switch cases.
```bash
if [[ "$1" == *","* ]]; then
# Split comma-separated commands
IFS=',' read -ra COMMANDS <<< "$1"
for cmd in "${COMMANDS[@]}"; do
# Trim whitespace
cmd=$(echo "$cmd" | xargs)
if declare -f "$cmd" > /dev/null; then
"$cmd"
else
echo "Unknown command: $1"
help "$@"
exit 1
fi
done
elif declare -f "$1" > /dev/null; then
"$1" "${@:2}"
else
case "$1" in
all)
install
lint
;;
*)
echo "Unknown command: $1"
help
exit 1
;;
esac
fi
```
These are the main parts of every task file script.
Now see [usage](/usage) on how to use the task file.
## Development
Checkout the [development](/development) page for details.