Switch to dark theme

Tutorial

This tutorial builds tally, a three-project workspace that needs only sh: lib sorts a word list, app counts the sorted words, and docs appends the list to a page. The finished workspace lives in examples/tally and is verified by crates/cli/tests/suite/examples.rs.

Install urepo once. On Linux and macOS:

Shell
curl -fsSL https://github.com/2xf-org/urepo/releases/latest/download/install.sh | sh

On Windows, in PowerShell:

powershell
irm https://github.com/2xf-org/urepo/releases/latest/download/install.ps1 | iex

The installer puts urepo in ~/.urepo/bin and adds that folder to your PATH. Open a new shell after it runs.

Create the workspace

Shell
mkdir tally && cd tally
urepo config init

urepo config init creates .urepo/urepo.toml, .urepo/.gitignore, and starter workflows under .github/workflows/.

Add the first project

Create lib/words.txt with one word per line (including duplicates):

text
tally
count
tally
sum
count

Create lib/urepo.toml:

TOML
# lib/urepo.toml
[project]
name = "lib"

[task.build]
description = "Sort the words and drop the repeats"
run         = ["mkdir -p dist", "sort -u words.txt > dist/vocabulary.txt"]
inputs      = ["words.txt"]
outputs     = ["dist/vocabulary.txt"]

List the workspace's tasks:

Shell
$ urepo task list
task       state  ci      supplier  description
lib:build  stale  cached  explicit  Sort the words and drop the repeats

Run build twice:

Shell
$ urepo run build
task       state  time
lib:build  ran    11ms

$ urepo run build
task       state
lib:build  current

urepo run is a shortcut for urepo task run. Progress lines go to standard error, and the summary table goes to standard output. In a pipe or a log, the progress is a line as each task starts and ends, with the task's output after its end line. On the second run, urepo hashes the task's commands and words.txt, finds the record in ~/.urepo/store, and skips execution.

Inspect staleness and restore outputs

Edit lib/words.txt and ask why lib:build is stale:

Shell
$ echo mean >> lib/words.txt
$ urepo task why lib:build
task    lib:build
state   stale
reason  no record under its key
key     ffa1b9c

changed  before   after
inputs   9230ff9  2d28a84

input file     change
lib/words.txt  modified

Run urepo run build to record the new output, then delete lib/dist and run again:

Shell
urepo run build
rm -r lib/dist
urepo run build

lib:build reports current without running, and lib/dist/vocabulary.txt is restored from the store.

Add dependent projects and see early cutoff

Create app/src/report.sh:

Shell
#!/bin/sh
set -eu
words=$(wc -l < ../lib/dist/vocabulary.txt | tr -d ' ')
echo "the vocabulary holds $words words"

Create app/urepo.toml:

TOML
# app/urepo.toml
[project]
name    = "app"
depends = ["lib"]

[task.build]
description = "Count the words of the library"
run         = ["mkdir -p dist", "sh src/report.sh > dist/report.txt"]
after       = ["^build"]
inputs      = ["src/**"]
outputs     = ["dist/report.txt"]

[task.show]
description = "Print the report"
run         = "cat dist/report.txt"
after       = ["build"]
inputs      = []
cache       = false

after = ["^build"] waits for build in every project listed in depends and includes the hash of their outputs in app:build's key. Add a third project in docs/page.txt (Tally counts words.) and docs/urepo.toml using an explicit cross-project task reference after = ["lib:build"], and add a same-project test task to lib/urepo.toml with after = ["build"].

Now run urepo run build, then append a duplicate word to lib/words.txt and run again:

Shell
$ urepo run build
task        state  time
lib:build   ran    12ms
app:build   ran    40ms
docs:build  ran    9ms

$ echo count >> lib/words.txt
$ urepo run build
task        state    time
lib:build   ran      11ms
app:build   current
docs:build  current

lib:build ran because words.txt changed, produced the same dist/vocabulary.txt, and both app:build and docs:build stayed current.

Inspect the graph, uncached tasks, and root tasks

List the tasks with what each waits for:

Shell
$ urepo task list
task        state    ci        supplier  after      description
app:build   current  cached    explicit  lib:build  Count the words of the library
app:show    stale    uncached  explicit  app:build  Print the report
docs:build  current  cached    explicit  lib:build  Join the page and the vocabulary
lib:build   current  cached    explicit             Sort the words and drop the repeats
lib:test    stale    cached    explicit  lib:build  Check that the vocabulary is not empty
tally:lint  stale    cached    explicit             Check that every script stops at its first error

Run the uncached show task (cache = false always runs without recording, while its prerequisites stay current):

Shell
urepo run show app

Pass extra arguments after -- to append them to the last command (this marks the run partial and records nothing):

Shell
urepo run show app -- ../lib/words.txt

You can also place [task.<name>] directly in .urepo/urepo.toml. That makes the workspace root a project owning every file outside nested projects and .urepo/ (see tally:lint in examples/tally/.urepo/urepo.toml).

Preview changes and read JSON

Pass --dry-run to preview what would run without changing files or records, and --json to print the same command view as JSON on standard output:

Shell
urepo run build --dry-run
urepo run test lib --json

Next steps