Skip to content

Wrap postCreateCommand in sh -c and guard pre-commit for graceful failure#19

Draft
Copilot wants to merge 2 commits into
mainfrom
copilot/update-post-create-command
Draft

Wrap postCreateCommand in sh -c and guard pre-commit for graceful failure#19
Copilot wants to merge 2 commits into
mainfrom
copilot/update-post-create-command

Conversation

Copilot AI commented Nov 30, 2025

Copy link
Copy Markdown
Contributor

The devcontainers runner execs postCreateCommand without a shell, causing ENOENT (exit 127) when pre-commit is missing. Ref: failing job, commit 821a1e5.

Changes

  • Wrap command in sh -c so shell operators are interpreted
  • Guard with command -v pre-commit to skip gracefully if missing
  • Ensure non-zero exit codes are swallowed to prevent container startup failures
"postCreateCommand": "sh -c 'if command -v pre-commit >/dev/null 2>&1; then pre-commit install --install-hooks || echo \"pre-commit install failed\"; else echo \"pre-commit not installed, skipping\"; fi'"
Original prompt

Change the postCreateCommand in .devcontainer/devcontainer.json so it runs under a shell and fails gracefully if pre-commit is missing or fails. Current devcontainers job logs referenced the file at ref 821a1e5.

Modify file: .devcontainer/devcontainer.json (use the repository default branch for the PR).

Replace the existing postCreateCommand value with a shell-wrapped, idempotent command that:

  • runs under sh -c so shell operators are interpreted (the runner execs commands without a shell by default),
  • checks for the pre-commit executable and skips if missing,
  • runs pre-commit install --install-hooks when present, and
  • never returns a non-zero exit code so container startup won't fail.

Suggested replacement value (JSON string, properly escaped in the file):

sh -c 'if command -v pre-commit >/dev/null 2>&1; then pre-commit install --install-hooks || echo "pre-commit install failed"; else echo "pre-commit not installed, skipping"; fi'

Please create a branch for the change, commit the updated devcontainer.json, and open a pull request with a description that explains the rationale: make postCreateCommand robust to missing pre-commit and ensure shell interpretation of operators so the job does not fail with exit code 127. Reference the failing job logs in the PR description (https://github.com/skevetter/devcontainers/actions/runs/19791978132/job/56706351826) and the ref 821a1e5 for context.

Do not modify other files. Include the full new content of the postCreateCommand key in the commit.

Example PR description (concise):
"Wrap postCreateCommand in sh -c and guard pre-commit so missing pre-commit does not make the container startup fail. The devcontainers runner previously attempted to exec the whole command string without a shell which caused ENOENT when pre-commit was not present. This change checks for pre-commit and prevents non-zero exit codes. See failing job: https://github.com/skevetter/devcontainers/actions/runs/19791978132/job/56706351826 and related ref 821a1e5."

This pull request was created as a result of the following prompt from Copilot chat.

Change the postCreateCommand in .devcontainer/devcontainer.json so it runs under a shell and fails gracefully if pre-commit is missing or fails. Current devcontainers job logs referenced the file at ref 821a1e5.

Modify file: .devcontainer/devcontainer.json (use the repository default branch for the PR).

Replace the existing postCreateCommand value with a shell-wrapped, idempotent command that:

  • runs under sh -c so shell operators are interpreted (the runner execs commands without a shell by default),
  • checks for the pre-commit executable and skips if missing,
  • runs pre-commit install --install-hooks when present, and
  • never returns a non-zero exit code so container startup won't fail.

Suggested replacement value (JSON string, properly escaped in the file):

sh -c 'if command -v pre-commit >/dev/null 2>&1; then pre-commit install --install-hooks || echo "pre-commit install failed"; else echo "pre-commit not installed, skipping"; fi'

Please create a branch for the change, commit the updated devcontainer.json, and open a pull request with a description that explains the rationale: make postCreateCommand robust to missing pre-commit and ensure shell interpretation of operators so the job does not fail with exit code 127. Reference the failing job logs in the PR description (https://github.com/skevetter/devcontainers/actions/runs/19791978132/job/56706351826) and the ref 821a1e5 for context.

Do not modify other files. Include the full new content of the postCreateCommand key in the commit.

Example PR description (concise):
"Wrap postCreateCommand in sh -c and guard pre-commit so missing pre-commit does not make the container startup fail. The devcontainers runner previously attempted to exec the whole command string without a shell which caused ENOENT when pre-commit was not present. This change checks for pre-commit and prevents non-zero exit codes. See failing job: https://github.com/skevetter/devcontainers/actions/runs/19791978132/job/56706351826 and related ref 821a1e5."


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

…lure

Replace the existing postCreateCommand with a shell-wrapped, idempotent
command that checks for pre-commit before running it and ensures the
container startup never fails due to missing pre-commit.

See failing job: https://github.com/skevetter/devcontainers/actions/runs/19791978132/job/56706351826
Related ref: 821a1e5

Co-authored-by: skevetter <69881238+skevetter@users.noreply.github.com>
Copilot AI changed the title [WIP] Update postCreateCommand for graceful pre-commit handling Wrap postCreateCommand in sh -c and guard pre-commit for graceful failure Nov 30, 2025
Copilot AI requested a review from skevetter November 30, 2025 01:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants