Repository navigation
Add a CircleCI mode to mockci: setup workflows, continuation and the cache - #41
Open
ndbroadbent wants to merge 6 commits into
Open
ndbroadbent wants to merge 6 commits into
ndbroadbent wants to merge 6 commits into
Conversation
…cache CircleCI parity item (a). `circleci local execute` runs single jobs and skips cache steps, so nothing could show what CircleCI does with a setup workflow, a continuation or a cache key. Simulator::run_circleci runs .circleci/config.yml at the event's commit and returns a PipelineReport. - Setup workflows: continuation/continue and finish run natively (the orb's script posts to CircleCI and writes to the host's /tmp), with the orb's own checks and what the continue API refuses: a second continuation, a setup config, undeclared or mistyped parameters. - Jobs: requires order, blocked jobs, branch filters, checkout, run with BASH_ENV, step when, circleci step halt, commands with parameters, << pipeline.* >> substitution, a home directory per job. - The cache: one scope for the project, keys matched as prefixes newest first, immutable, expiring 15 days after the save; checksum, .Branch, .Revision, .Environment and epoch templates. - Strict: unknown keys, other orbs and anything that would touch the host (absolute cache paths, working directories outside ~) are errors. Tests: tests/mockci_circleci.rs and tests/mockci_circleci_setup.rs, with hand-written configs. MOCK_CI.md documents the mode and its limits.
…d, a /tmp per job From CircleCI's configuration reference: - `requires` can name statuses: `build: failed`, `build: [success, failed]`, `build: terminal` (success, failed, canceled, unauthorized, not_run). A blocked job counts as not_run. (b)'s gate needs this to run when a job fails. - "If filters stop a dependency from running, CircleCI ignores them as dependencies for other jobs." mockci errored instead; now it ignores them. - restore_cache puts files back where they were saved from, so markers that pass between jobs with different images belong in /tmp. Each job gets its own /tmp, which steps reach through TMPDIR; cache paths, checksum files and step directories under /tmp/ resolve to it.
…gaps
1. `{{ .Environment.X }}` sees only CircleCI's own variables and the
project's. A job's or an image's `environment:`, or an unset name, renders
as `<no value>` on CircleCI (a constant key), so mockci refuses it instead
of rendering a varying one. Template errors now stop the run instead of
failing the step. A test checks generated CircleCI config uses no
.Environment.
2, 3. Every path a config names resolves through src/circleci/paths.rs:
cache paths, checksum files, checkout and step directories, the job's
working_directory, and the continuation's configuration_path and
parameters file. It refuses `..` and absolute paths outside /tmp, so
nothing reaches a host file. tests/mockci_circleci_strict.rs probes each.
4, 5. Documented under "Not modelled yet": jobs ready together run one at
a time and see each other's caches; the continue API's "Conflicting
pipeline parameters" refusal.
Member
Author
|
Pushed review fixes and CircleCI facts:
|
…filtered, host /tmp
A. A doubled slash escaped every guard: `~//etc/hosts` stripped to an
absolute path that Path::join used as is. paths.rs refuses `//`, and
checks that the joined path stays inside its base. The unit test lists
`~//etc/passwd`, `/tmp//etc/passwd` and `a//b`.
B. "If filters exclude all dependencies of a job, that job doesn't execute
either": order.rs leaves such a job out, and carries on to the jobs that
lose all their requirements that way. A job with one requirement left
still runs.
C. save_cache of a /tmp path that the job's /tmp lacks but the host's has is
an error pointing at ${TMPDIR:-/tmp}, instead of a quiet "No files to
save".
…ale host /tmp not blamed copy_tree recursed forever on a directory symlink (walkdir reports it as not a directory, so it called itself on the same path). It now copies symlinks as symlinks, replaces a symlink at the destination instead of writing through it, and refuses a parent that resolves outside the destination. The CircleCI path guard follows symlinks a step made before checking containment. save_cache blames the host's /tmp only when that path changed after the job started.
… links, deep /tmp writes copy_tree takes the root its destination must stay inside (the workspace, the job's home or /tmp, or the cache store), replaces a symlink at the destination, and checks the destination's nearest existing ancestor and each entry's parent against that root, so a GitHub cache restore can't write through `stored -> <host dir>`. Artifact uploads follow symlinks and leave broken ones out, as upload-artifact's search does (followSymbolicLinks, omitBrokenSymbolicLinks). The host /tmp hint looks at the newest change anywhere under the path.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CircleCI parity item (a): a CircleCI mode for mockci, so (b)'s setup job, plan slice and gate can be tested end to end.
circleci local executeruns single jobs and skips cache steps, so until now nothing could show what CircleCI does with a setup workflow, a continuation or a cache key.What changed
Simulator::run_circleci(&event)(orrun_circleci_with(&event, parameters)) runs.circleci/config.ymlat the event's commit and returns aPipelineReport: the setup workflow, the workflows that ran and their parameters. Code incrates/mockci/src/circleci/, every file under 300 lines.continuation/continueandfinishrun natively, because the orb's script posts to CircleCI's API and writes to the host's/tmp. They make the checks orb 1.0.0 makes (fetched from the orb registry): the continuation key first, thenparametersas JSON or a path to a JSON file. They also refuse what the continue API refuses: a second continuation, a setup config, and parameters the continued config doesn't declare or that have the wrong type. A workflow whosewhenis false is left out.requiresorder; a job whose requirement didn't succeed is blocked and reported as skipped. Also branchonly/ignore(exact names),checkout,run(/bin/bash -eo pipefail, aBASH_ENVevery step sources), stepwhen,circleci step halt, commands with parameters,when/unlesssteps, and<< pipeline.* >>substitution. Each job gets its own home directory, with~/projectas the working directory.{{ checksum }}(base64 SHA-256),.Branch,.Revision,.Environment.Xandepoch.when, and anything that would touch the host are errors. Touching the host means an absolute cache path or a working directory outside~. Thedockerimage is checked but steps run on the host.Testing
tests/mockci_circleci.rs:BASH_ENV, commands,when, blocked jobs, halt, the shared cache across branches, immutability, 15-day expiry, prefix keys in order newest first, and the strictness errors. The checksum is checked againstopenssl dgst -sha256 -binary | base64.tests/mockci_circleci_setup.rs: continuing with parameters from a file, a false workflowwhen, the continuation key only in the setup workflow, continuing once,finish, refused parameters, and continuing outside a setup workflow.task cigreen. MOCK_CI.md has a "CircleCI mode" section with the limits; STATUS's Tests list names the new files.For (b)
Today's generated setup job writes to
/tmpon the host (rm -rf /tmp/skip), so it can't run in mockci safely. STATUS 13 will be shown running by (b)'s scenarios, with workspace-relative paths.Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.