Recipe: GitHub Actions¶
This workflow runs the TPC-H polars example through the orchestrator protocol on a GitHub Actions runner. A shell loop plays the orchestrator: it reads the unit graph, runs each unit with its own command line, finalizes the run and checks the result. Nothing in it is specific to the example except the project folder and the count of nine units. The same file runs in this repository's CI, so it stays correct.
name: orchestrate-tpch
# The orchestrator protocol on a CI runner: a shell loop plays the orchestrator and runs the TPC-H
# polars example one unit at a time, from the unit graph. See docs/guide/recipe-github-actions.md.
on:
pull_request:
paths:
- "src/**"
- "plugins/pipeloom-polars/**"
- "examples/**"
- "uv.lock"
- ".github/workflows/orchestrate-tpch.yml"
push:
branches: [main]
paths:
- "src/**"
- "plugins/pipeloom-polars/**"
- "examples/**"
- "uv.lock"
- ".github/workflows/orchestrate-tpch.yml"
workflow_dispatch:
permissions: {}
concurrency:
group: orchestrate-tpch-${{ github.ref }}
cancel-in-progress: true
jobs:
orchestrate:
runs-on: ubuntu-latest
timeout-minutes: 15
permissions:
contents: read
env:
PROJECT_DIR: examples/tpch_polars
# fills the placeholders of an argv from the unit graph
FILL: '.argv[] | gsub("\\{project_dir\\}"; $p) | gsub("\\{manifest\\}"; $m) | gsub("\\{run_id\\}"; $r)'
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- uses: astral-sh/setup-uv@07a047e608db84b3d8c06cd9a7c7dcc9c355c18e # v10.3.2
# The only step tied to this repository. Outside it, install the released packages instead:
# pip install "pipeloom[polars]"
- name: Install pipeloom
run: |
uv sync --locked --all-packages
echo "$GITHUB_WORKSPACE/.venv/bin" >> "$GITHUB_PATH"
- name: Generate the TPC-H data
run: uv run examples/tpch_data.py
# One run id and one start time for every invocation of this orchestrator run.
- name: Pick the run id and start time
run: |
echo "RUN_ID=gha-${{ github.run_id }}-${{ github.run_attempt }}" >> "$GITHUB_ENV"
echo "PIPELOOM_RUN_STARTED_AT=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> "$GITHUB_ENV"
- name: Prepare the plan and the unit graph
run: |
pipeloom compile --project-dir "$PROJECT_DIR" --target dev --stable --out "$RUNNER_TEMP/manifest.json"
pipeloom graph --units --output json --project-dir "$PROJECT_DIR" --target dev --manifest "$RUNNER_TEMP/manifest.json" > "$RUNNER_TEMP/units.json"
# A unit starts after all its parents succeeded; a unit with a failed or skipped parent is
# skipped. Units run one at a time here, in the graph's topological order. Retries are the
# orchestrator's job: this graph sets none, so a failed unit stays failed.
- name: Run the units
run: |
: > "$RUNNER_TEMP/not-ok"
while read -r unit; do
id=$(jq -r '.unit_id' <<< "$unit")
blocked=""
for parent in $(jq -r '.parents[]' <<< "$unit"); do
if grep -qxF "$parent" "$RUNNER_TEMP/not-ok"; then blocked="$parent"; fi
done
if [ -n "$blocked" ]; then
echo "skip $id: parent $blocked did not succeed"
echo "$id" >> "$RUNNER_TEMP/not-ok"
continue
fi
mapfile -t argv < <(jq -r --arg p "$PROJECT_DIR" --arg m "$RUNNER_TEMP/manifest.json" --arg r "$RUN_ID" "$FILL" <<< "$unit")
echo "run $id"
if ! "${argv[@]}" < /dev/null; then
echo "::error::unit $id failed"
echo "$id" >> "$RUNNER_TEMP/not-ok"
fi
done < <(jq -c '.units[]' "$RUNNER_TEMP/units.json")
test ! -s "$RUNNER_TEMP/not-ok"
# Always runs, so a failed run still gets its run_results.json.
- name: Finalize the run
if: always()
run: |
mapfile -t argv < <(jq -r --arg p "$PROJECT_DIR" --arg m "$RUNNER_TEMP/manifest.json" --arg r "$RUN_ID" ".finalize | $FILL" "$RUNNER_TEMP/units.json")
"${argv[@]}" --orchestrator-id "gha_run_id=${{ github.run_id }}"
- name: Check the results
run: jq -e '.run.status == "succeeded" and .run.counts.succeeded == 9' "$PROJECT_DIR/target/runs/$RUN_ID/run_results.json"
- name: Upload the run folder
if: always()
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: tpch-run
path: examples/tpch_polars/target/runs
if-no-files-found: warn
retention-days: 7
Step by step¶
- Install pipeloom. The workflow installs this checkout with
uv sync --locked --all-packagesand puts.venv/binon the path. This is the only step you replace in your own repository, withpip install "pipeloom[polars]"or whatever your project needs. - Generate the data. The example ships a script that writes the five TPC-H tables as parquet. Your pipeline reads its own sources, so you drop this step.
- Pick the run id and start time.
gha-<run_id>-<attempt>is a valid run id and changes when someone reruns the workflow. The start time is exported asPIPELOOM_RUN_STARTED_AT, so every later command sees the same one. - Prepare.
compile --stablewrites the manifest.graph --units --output json --manifestwrites the unit graph with the plan hash of that manifest. - Run the units. The loop reads the units in topological order. A unit with a parent that
failed or was skipped is skipped. For the others,
jqfills the placeholders{project_dir},{manifest}and{run_id}in theargvand the loop runs it. A failed unit is recorded and the step fails at the end, after every unit that could run has run. - Finalize. This step has
if: always(), so a failed run still gets itsrun_results.json. It usesfinalize.argvfrom the unit graph and adds the id of the workflow run with--orchestrator-id. - Check.
jq -efails the job unless the run succeeded with nine succeeded units. - Upload. The run folder, with the manifest, results, attempt files, logs and events, is attached to the workflow run even when the job failed.
The loop does not retry. In the example no model sets retries, and the protocol leaves retries to
the orchestrator: add a retry loop around a unit that reads retries, retry_delay_s and
retry_on from the unit graph and the error.category of the newest attempt file. Add a
timeout around the command for a unit with timeout_s.
Several jobs¶
GitHub hosted runners share no filesystem, so one job per unit needs three things the example does
not have: a remote catalog, a remote state store, and an artifacts root on shared storage that
every job and the finalize job can read and write. With those in place each unit is a job that runs
its argv, a final job with if: always() runs finalize, and units that failed or were skipped are
passed to it with --unit-states-json. This variant is not tested in CI.
Other orchestrators¶
Kestra, Argo Workflows and Airflow without the plugin follow the same protocol. A task runs a
unit's argv, task dependencies come from edges, and a last task runs finalize whatever happened
before it. The orchestrator's own retry and timeout settings come from the unit graph.