logs.gokuls.in

8 pull requests merged across 1 repo

bahdotsh/wrkflw

Problem

Gitea runs GitHub-compatible workflows, but it looks in .gitea/workflows first. In a repository that only has that directory:

  • wrkflw validate failed with Path does not exist: .github/workflows.
  • wrkflw list, the TUI and wrkflw watch found nothing by default.
  • actions/checkout dropped .gitea from the workspace, so steps could not read it.
  • ${{ gitea.ref }} silently evaluated to an empty value.

An explicit wrkflw validate .gitea/workflows already worked, and the validator already accepted Gitea-style syntax.

Changes

  • Discovery: new helpers in wrkflw-utils use Gitea's order, .gitea/workflows then .github/workflows. The order comes from WorkflowDirs in Gitea's modules/setting/actions.go.
  • validate, list and the TUI: these cover both directories when both exist. Gitea only runs the first, but a repository mirrored to both forges uses both.
  • watch: this takes one directory, so it picks .gitea/workflows and prints a note naming the skipped one.
  • Workspace copy: both copy routines now keep .gitea.
  • Expressions: gitea is an alias of the github context.
  • list refactor: the directory listing moved into list_workflow_dir, which accounts for most of the main.rs diff.

Behaviour change

In a repository with both directories, wrkflw watch now defaults to .gitea/workflows, not .github/workflows. Repositories with only .github/workflows are unaffected, except that the list message is reworded when neither directory exists.

Not included

  • Absolute-URL actions: uses: https://gitea.com/actions/checkout@v4 passes validation, but at run time the URL is mangled and the step falls back to built-in handling, reporting success. This is listed under "Not yet supported" in the README.
  • Remote triggering: trigger stays GitHub and GitLab only.
  • Forgejo: .forgejo/workflows is not discovered.

Testing

  • cargo test --workspace, cargo clippy --workspace --all-targets -- -D warnings and cargo fmt --check all pass.
  • New unit tests cover directory ordering, both workspace copies and the gitea alias.
  • I ran the built binary against .gitea-only, both-directory and neither-directory repositories for validate and list, and started watch on the first two.
  • An emulation run with actions/checkout reads .gitea/workflows/co.yml with the fix and fails when the engine copy change is reverted.
  • The TUI, driven through a pseudo-terminal, lists .gitea/workflows, both directories together, and .github/workflows alone, and it ran a .gitea workflow to success.
  • A workflow using actions/checkout, a local .gitea composite action, gitea.* expressions and a reusable .gitea workflow passes under the emulation and Podman runtimes. Docker was not running, so it was not tested.
  • wrkflw validate exits 1 on an invalid .gitea workflow, and wrkflw watch triggers when a .gitea workflow is edited.

Existing issues found, not caused by this PR

  • secure-emulation fails the same workflow from .github: a step cannot see checked-out files.
  • wrkflw watch on macOS re-triggers many times after one edit. Unmodified main and this branch both logged about 20 detections in 12 seconds.

Problem

The TUI palette was hard-coded for dark backgrounds. On a light terminal, pale yellow and cyan text was nearly invisible, and the title bar, status bar and selected row stayed near-black.

Changes

  • Light palette: COLORS now resolves to a dark or light table at runtime, so existing call sites are unchanged. The dark palette keeps its values.
  • Accents: each Tweaks accent has a light variant. The accent overrides the palette on every frame, so the palette alone would not have fixed it.
  • Help overlay: the backdrop uses the theme instead of hard-coded black.
  • Theme selection: the theme is chosen once at startup, in this order:

1. --theme auto|dark|light

2. WRKFLW_THEME

3. The terminal's reported background

4. COLORFGBG

5. Dark

Auto-detection suits terminals that change theme by time of day, as in the issue.

Notes for review

  • New dependency: terminal-colorsaurus is added behind the tui feature. It resolves to 1.0.0 because 1.0.3 conflicts with the mio version required by crossterm 0.28.
  • Public API: run_wrkflw_tui gains a theme parameter, which is a breaking change for library users. The READMEs are updated.
  • Startup delay: a terminal that answers neither color nor device queries delays startup by up to 1 second. Explicit --theme dark or --theme light skips the query.
  • No live switching: changing the terminal theme needs a TUI restart. A live toggle is left out because the log worker caches styles built from the old palette.
  • Forced light on a dark terminal: the TUI does not paint the main background, so light text colors are the user's explicit choice there.

Testing

  • cargo fmt --check, cargo clippy --workspace --all-targets -- -D warnings and cargo test --workspace pass.
  • wrkflw builds with --no-default-features.
  • New unit tests require 4.5:1 contrast for light-theme text on white and on every light background, and for solid chips.
  • The real binary was run in a scripted pseudo-terminal, reading the colors it emitted:
  • Flag, environment variable, flag precedence and invalid environment values behaved as designed.
  • Simulated white and black terminals selected light and dark.
  • A silent terminal used COLORFGBG, then dark.
  • This has not been checked by eye in a real terminal emulator.

Problem

wrkflw hardcoded ~/.wrkflw/ in three places: the actions/cache store (the one the issue cites), RUNNER_TOOL_CACHE, and the default file secrets provider path.

Changes

PurposeBeforeLinuxmacOS
actions/cache store~/.wrkflw/cache$XDG_CACHE_HOME/wrkflw/cache~/Library/Caches/wrkflw/cache
RUNNER_TOOL_CACHE~/.wrkflw/tools$XDG_CACHE_HOME/wrkflw/tools~/Library/Caches/wrkflw/tools
Default file secrets~/.wrkflw/secrets$XDG_CONFIG_HOME/wrkflw/secrets~/Library/Application Support/wrkflw/secrets

Paths come from the dirs crate, which was already a dependency, so $XDG_* is honoured on Linux and macOS and Windows use their native locations. $XDG_* is not read on macOS.

Migration

  • Secrets: ~/.wrkflw/secrets keeps being used until the new location exists, so upgrading does not hide anyone's secrets.
  • Caches: not migrated, because they repopulate on the next run. The old directories are left in place, and BREAKING_CHANGES.md documents how to delete them.

Testing

  • cargo test --workspace and cargo clippy --workspace --all-targets -- -D warnings pass.
  • New unit tests cover how the secrets path is chosen (new location, legacy fallback, both present, neither resolvable).
  • End-to-end on macOS with an isolated HOME: an emulation run saved and then restored an actions/cache entry under Library/Caches/wrkflw/cache, RUNNER_TOOL_CACHE pointed at Library/Caches/wrkflw/tools, and no ~/.wrkflw was created.
  • CI passes on Linux, macOS and Windows, but only the macOS paths were exercised end-to-end. The $XDG_* lookup on Linux relies on dirs.

Docs

The secrets docs described ~/.wrkflw/secrets.yml as if it were picked up automatically, but nothing loads a config file by default. The paths are updated, and the root README now points at the secrets directory the file provider actually reads. crates/secrets/README.md and the secrets demo still describe a config file there and only had their paths changed.

Problem

strategy.matrix.include: ${{ fromJSON(needs.<job>.outputs.<name>) }} is valid GitHub Actions syntax, but wrkflw validate failed with include must be an array of objects. Fixing that message alone wasn't enough, because MatrixConfig couldn't deserialize a string there either.

Changes

  • wrkflw-matrix: include and exclude are now MatrixEntries, either a literal List or an Expression. MatrixConfig::resolve_expressions turns expressions into lists. expand_matrix returns an error if one is still unresolved, rather than silently dropping it.
  • Include-only matrices: a matrix with include and no axes now expands. It used to fail with "Matrix has no valid parameters", and it's a common shape for generated matrices.
  • Strategy contexts: expressions may use only github, needs, vars and inputs, and no special functions, matching GitHub's strategy context. wrkflw validate and wrkflw run share this check. vars is accepted but wrkflw does not resolve it, so it evaluates to empty.
  • Executor: expressions are resolved after the job's if: gate. A matrix that can't be computed fails that job, and its dependents are skipped.
  • Validator and parser: accept a value wrapped in ${{ }}. Plain strings and non-object items are still rejected.
  • TUI: the matrix pane shows an expansion error for these jobs, because the combinations aren't known until the run.

Behaviour to check

  • If the expression doesn't evaluate to an array of objects, the job fails and the rest of the run continues. This includes an empty output, and an include-only matrix that resolves to []. Static expansion failures now behave the same way.
  • MatrixConfig.include and .exclude change type, which is a breaking change to the public API of wrkflw-matrix.

Not included

  • Expressions for the whole matrix (matrix: ${{ ... }}) are still rejected.
  • Expressions for a single axis (os: ${{ ... }}) still pass validation but are treated as a literal value at run time.

Testing

  • Added unit tests in wrkflw-matrix and the validator.
  • Added crates/wrkflw/tests/dynamic_matrix_test.rs, which runs merging, include-only, exclude and invalid-result cases end to end through emulation.
  • cargo test --workspace and cargo clippy --workspace --all-targets -- -D warnings pass.
  • Ran a local workflow with the same shape as the issue's, with list.py replaced by its hard-coded JSON output and the install and setup-node steps removed. It validated and ran 4 combinations.

Problem

On some terminals (reported on iTerm2), entering the alternate screen keeps whatever was on the primary screen. ratatui assumes the terminal starts blank and only writes cells that change between frames, so pre-existing text stayed visible in any region a frame didn't paint — including after switching tabs such as Logs.

Fix

Call terminal.clear() right after constructing the ratatui Terminal. This clears the physical screen and resets ratatui's back buffer, so the first frame is drawn onto a known-empty screen. Resizes are already handled by ratatui's autoresize, which clears too.

Testing

  • cargo build / cargo clippy / cargo fmt --check for wrkflw-ui
  • Not verified interactively in iTerm2

Problem

wrkflw parsed only the top-level .gitlab-ci.yml, as written. Real pipelines like the two in the issue failed:

  • rust-json-job-dispatch: hidden .-prefixed templates were reported as jobs with no script, and every extends target defined in an included file showed up as extends undefined job.
  • ParaView: failed straight away with deserializing from YAML containing more than one document is not supported, because of its spec:inputs header.

Even where validation passed, extends was never applied, so a job that took its script from a template would run with no steps.

Fix

A new gitlab_config module in the parser builds the resolved configuration before it is deserialized into Pipeline:

FeatureBehaviour
includeLocal includes, given as a string, as local:, or with wildcards. They are deep-merged in order and the including file wins. Cycles are detected, and paths must stay inside the repository. remote/project/template/component are skipped with a warning, since they need network access.
spec:inputsHeader document plus $[[ inputs.x ]] interpolation in keys and values. Uses defaults and checks type/options/regex. Reports required inputs that are missing and inputs that are unknown. A whole-string placeholder keeps its type (number/bool/array). Supports expand_vars, truncate(a,b) and posix_escape.
extendsDeep merge, multiple parents applied in order, transitive. Cycle and depth (11) limits.
!referenceResolved after extends, nesting limited to 10 levels. Nested script arrays (from anchors or references) are flattened, as GitLab does.
Hidden keys.-prefixed keys are removed once resolved, so they are never treated as jobs.

Smaller model and schema gaps that the example pipelines hit:

  • allow_failure: { exit_codes: ... } is now accepted (new AllowFailure enum; the field had no other users).
  • Jobs with trigger: and no script are accepted by the validators.
  • The bundled schema now accepts a list for artifacts:reports:annotations and null/empty variable values. ParaView uses both and GitLab accepts both.
  • Schema errors now include the JSON path (e.g. /job/variables/FOO: ...). The merged config has no line numbers, so without the path these errors were impossible to locate.

Testing

  • 12 new unit tests in gitlab_config and one parse_pipeline integration test. They cover merging, overrides, wildcards, skipped includes, cycles, escaping the repository root, typed inputs, input errors, !reference, and anchor flattening.
  • cargo fmt --check, cargo clippy --workspace --all-features -- -D warnings, cargo check --no-default-features, cargo test --workspace --all-features all pass locally (853 tests).
  • Both pipelines from the issue now validate cleanly (wrkflw validate .gitlab-ci.yml). ParaView resolves to 25 jobs across its include/inputs chain.
  • End-to-end wrkflw run --runtime emulation on a fixture with two levels of inputs, includes, multi-parent extends and !reference. A script asserting the interpolated and inherited values passes, and the same script with a wrong expected value fails.

Known limitations (not in this PR)

  • rules: on include entries are ignored; the file is always included.
  • trigger: jobs run as no-op jobs locally.
  • default: keyword values still aren't applied to jobs (pre-existing).

Follow-up to #126.

Problem

#126 skipped jobs whose needs: did not succeed, but let any job with an explicit if: bypass the gate. That if: was then evaluated by evaluate_job_condition with job_status hardcoded to "success" and an empty needs context. After a failed need:

if:GitHub Actionsbefore this PR
failure()runsskipped
success()skippedran
always() && needs.x.result == 'failure'runsskipped (needs.x.result was null)
github.ref == '…' (no status function)skipped (implicit success() &&)ran

Jobs inside reusable workflows were not gated at all, because run_called_workflow runs its own batch loop.

Change

The gate moves from the execute_github_workflow batch loop into execute_job_with_matrix, after the needs context is built:

  • A job with no if: is evaluated as success().
  • An if: that calls none of success() / failure() / always() / cancelled() is evaluated as success() && (<expr>). String literals and property names are ignored when looking for those calls.
  • success() / failure() see the upstream status. It is failure when any transitive ancestor failed, which matches GitHub's documented ancestor rule. It is skipped when a direct need was skipped, so both functions are false.
  • needs.<id>.result and needs.<id>.outputs are available to the job-level if:.
  • - A matrix job's needs.<id>.result is the aggregate of its combinations: failure if any failed, otherwise success if any succeeded, otherwise skipped. It used to be whichever combination was recorded last. A combination that errors with fail-fast: false is now recorded as failed instead of dropped.
  • Status-function detection uses the expression tokenizer instead of a separate scanner.
  • A need with no recorded result does not block. That only happens for a matrix job that expanded to zero combinations. The old comment blamed --target-job plans, which always keep transitive deps.

Because run_called_workflow also runs jobs through execute_job_with_matrix, reusable workflows get the same rules. job_blocked_by_needs is removed, and the skipped JobResult literal is replaced by a JobResult::skipped constructor.

Tests

Unit tests in engine.rs cover status-function detection, implicit success(), the skipped-need case and upstream_status. The existing evaluate_job_condition tests were moved to the new signature unchanged in meaning.

New integration tests in needs_failure_propagation_test.rs:

testasserts
status_functions_see_the_failed_needif: failure() runs, if: success() skips
needs_result_is_visible_to_job_ifneeds.deploy.result == 'failure' is true
plain_if_is_still_gated_on_needsif: ${{ true }} still skips after a failed need
need_skipped_by_its_own_if_skips_dependentsif: false on a need skips its dependent
any_failed_need_among_several_skipsone failed need out of two skips
ancestor_failure_propagates_past_an_always_jobfailed grandparent keeps success() false and failure() true
reusable_workflow_jobs_skip_after_failed_needinner needs: chain is gated
matrix_need_with_one_failed_combination_counts_as_failedplain, failure() and needs.x.result all see a failed matrix
fail_fast_matrix_need_counts_as_failedfail-fast-skipped combinations don't mask the failure
needs_outputs_are_visible_to_job_ifneeds.<id>.outputs drives a job if: both ways
gate_skipped_need_reports_skipped_resulta gate-skipped need reports skipped

The integration test file is gated off Windows. It runs bash steps through the emulation runtime, and on windows-latest bash is the WSL launcher with no distribution installed, so every step fails. This was already failing on main since #126. The engine's own emulation unit tests use the same gate.

Against main's engine, 5 of these fail. On this branch, cargo fmt --check, cargo clippy --workspace --all-features --tests -- -D warnings, cargo test --workspace --all-features (836 passed) and cargo check --no-default-features --workspace are all clean.

Behaviour change

Jobs with if: expressions that call no status function now skip after a failed need, as they do on GitHub. This is worth a line in the release notes.

Follow-up to #123, addressing the review findings left after merge.

Fixes

  • Windows host + docker/podman. The {0} script path was built with guest_dir.join(name), which produces /github/workflow\wrkflw-<uuid> on a Windows host. A Linux container cannot resolve that. The guest path is now built as a POSIX string, the same way the GITHUB_ENV remap already does it. Windows CI did not catch this because the mock runtime resolves mounts with Path::strip_prefix, which accepts both separators on Windows.
  • Missing mount under a container runtime. When github_mount was None, the code fell back to using working_dir as both host and guest path. That is only valid for host-side runtimes. Under docker/podman the step now fails with an explicit message instead of passing the container a host path. It is unreachable today because GITHUB_ENV is always seeded, but the invariant is now enforced instead of implied.

Refactor

  • The custom-shell setup moved out of execute_step into prepare_custom_shell. It returns a CustomShellScript guard whose Drop removes the script file, so cleanup happens on every exit path.
  • The docker/podman check is now a single uses_container_runtime helper, stored on StepContainerContext. It was duplicated between execute_step and prepare_container_mounts.
  • The resolved custom shell argv is logged at info level. The previous path was silent outside emulation's verbose logs.

Tests

  • prepare_custom_shell_uses_posix_guest_path_under_container_runtime asserts the guest path has no \, the script content is correct, and the file is removed on drop.
  • prepare_custom_shell_fails_without_github_mount_under_container_runtime asserts the explicit failure and that nothing is written to the host.
  • prepare_custom_shell_rejects_missing_placeholder_without_writing asserts no file is left behind on a validation failure.
  • custom_shell_resolves_relative_command_to_absolute_path now uses a tempdir instead of writing its script into the crate directory.

cargo fmt --check, cargo clippy --workspace --all-features -- -D warnings, cargo check --no-default-features --workspace and cargo test --workspace --all-features are clean locally on macOS.

Not in scope

  • The cmd arm still uses cmd -c. The real template is cmd /D /E:ON /V:OFF /S /C "CALL "{0}"", but it needs a Windows runner to verify.