feat: Add global_teardown_script to run during worktree cleanup#1066
Open
matthewbjones wants to merge 1 commit into
Open
feat: Add global_teardown_script to run during worktree cleanup#1066matthewbjones wants to merge 1 commit into
matthewbjones wants to merge 1 commit into
Conversation
Add support for a global teardown script that runs before worktree deletion when an issue reaches a terminal state (Done, Canceled, or deleted). Mirrors the existing global_setup_script pattern. The teardown script runs in the worktree directory so it can read configuration files (e.g. .env.local) written by the setup script. Non-blocking on failure — worktree deletion always proceeds. Use case: cleaning up per-worktree databases, deregistering ports, or removing temporary credentials provisioned during setup. Closes cyrusagents#1065
|
I was looking exactly for this, we create 1 database per worktree so this is perfect to clean up after something is done! 🙏 |
Contributor
|
This would be great. @matthewbjones we can open a PR to resolve merge conflicts. |
Contributor
|
@cyrusagent can you create a new branch based on this one and resolve merge conflicts and open a new PR attributing this one |
3 tasks
Contributor
|
Created #1111 — a rebased version of #1066 with merge conflicts resolved. Conflicts resolved:
All 569 edge-worker tests pass and the full build succeeds. The original author (@matthewbjones) is preserved on the commit. |
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.
Summary
Adds
global_teardown_scriptconfig option that runs before worktree deletion when an issue reaches a terminal state (Done, Canceled, or deleted). Mirrors the existingglobal_setup_scriptpattern.The teardown script:
.env.localand other config files written by the setup script)LINEAR_ISSUE_IDENTIFIERas an environment variableUse Case
Our Rails app's
global_setup_scriptcreates 8 isolated Postgres databases per worktree (primary, queue, cache, cable × dev + test). When Cyrus deletes the worktree, those databases are orphaned. The teardown script runsbin/worktree-teardownto drop them before the directory is removed.Config Example
{ "global_setup_script": "~/.cyrus/scripts/setup.sh", "global_teardown_script": "~/.cyrus/scripts/teardown.sh" }Changes
packages/core/src/config-schemas.ts— Addedglobal_teardown_scripttoEdgeConfigSchemapackages/core/schemas/— Updated JSON schema snapshots (auto-regenerated by pre-commit hook)packages/edge-worker/src/GitService.ts— AddedrunTeardownScriptmethod, called indeleteWorktreebefore directory removalpackages/edge-worker/src/EdgeWorker.ts— Passglobal_teardown_scriptfrom config todeleteWorktreepackages/edge-worker/test/GitService.test.ts— 3 new tests: runs teardown before deletion, continues on failure, skips when unconfigureddocs/CONFIG_FILE.md— Documented the new optiondocs/SETUP_SCRIPTS.md— Added teardown section with examples and error handling docsCHANGELOG.md— Added entry under[Unreleased]Testing
All existing tests pass (1,259 total). 3 new tests added:
Closes #1065