Repository navigation
import-page-draft: fail fast on environment-like site names, clean up temp files on any exit - #296
Merged
Merged
Conversation
… in import-page-draft A site name of local, production or both is the environment argument in the wrong position; the script built /srv/www/<environment>/current from it and only failed inside trellis vm shell. Exit early with the usage line instead. set -e without a trap meant cleanup ran only on success, so a failed run left the stripped draft in /tmp, its copy in the Bedrock site root and the scp'd copy on the server after a failed production import. An EXIT trap now removes all three on any exit; the remote remove is best-effort and only runs once the scp happened. Resolves #232 (points 1 and 2; point 3 landed in #246).
This was referenced Nov 17, 2026
Merged
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.
This PR hardens
wp-cli/content-creation/import-page-draft.shwith two robustness fixes: an early argument-validation guard and comprehensive temp-file cleanup. When a site name oflocal,production, orbothwas passed in the site-name position (argument drift from older documented invocations), the script silently constructed/srv/www/<environment>/currentas its path and only failed much later insidetrellis vm shellwith a confusing error. It also relied on inlinerm -fcalls after each success path, so underset -eany failed run left the stripped draft in/tmp, its copy in the Bedrock site root, and — after a failed production import — the scp'd copy on the remote server. Both issues are points 1 and 2 of #232 (point 3, header-comment stripping, landed earlier in #246). The change spans 2 files with 31 insertions and 4 deletions, and includes a correspondingCHANGELOG.mdentry under theUnreleasedFixedsection.Input validation and fail-fast behavior:
local,production, orbothas the site name — these values belong in the environment argument position, and previously produced a nonsensicalSERVER_PATHbuilt from the environment string.$0 <draft-file> <page-id> [site-name] [environment] [template]) before touching the filesystem or starting any remote operations, instead of failing deep inside trellis VM shell.Temp-file cleanup on all exit paths:
cleanup()function registered withtrap cleanup EXIT, which removes the stripped draft from/tmpand the copy from the site directory (SITE_DIR/$TMP_NAME) on any exit — success, failure, or error fromset -e.$SERVER_PATH/$TMP_NAMEover SSH, gated behind aPROD_UPLOADEDflag that flips toyesonly after thescpsucceeds, so the trap never attempts a remote removal for a run that never uploaded anything.rm -finside cleanup is best-effort (2>/dev/null || true) so a transient SSH failure during cleanup cannot mask the original exit status or break the trap.rm -fcalls from the stray-comment error path, the end ofupdate_local(), the end ofupdate_production(), and the script's final line, consolidating all removal logic in one place.Documentation:
CHANGELOG.mdgains a### Fixedentry under[Unreleased]describing both behaviors and referencing import-page-draft: validate site-name arg, clean up temp files on failure, strip HTML comment headers #232, noting that the header-comment stripping requested in the same issue had already landed in publish-post / import-page-draft: header comments other than SUGGESTED leak into post_content #246.Files Changed:
CHANGELOG.md(Modified)wp-cli/content-creation/import-page-draft.sh(Modified)