-
Notifications
You must be signed in to change notification settings - Fork 2
chore: Debug exit code 2 #429
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -139,22 +139,70 @@ jobs: | |||||||
| NOMAD_VAR_holochain_bin_url: "${{ env.HOLOCHAIN_BIN_URL }}" | ||||||||
| run: |- | ||||||||
| set -euo pipefail | ||||||||
| nomad_output=$(nix run --impure --inputs-from . nixpkgs#nomad -- job run nomad/jobs/${JOB_NAME}.nomad.hcl) | ||||||||
|
|
||||||||
| echo "Running Nomad job: ${JOB_NAME}" | ||||||||
| if ! nomad_output=$(nix run --impure --inputs-from . nixpkgs#nomad -- job run nomad/jobs/${JOB_NAME}.nomad.hcl 2>&1); then | ||||||||
| echo "ERROR: Failed to run Nomad job" | ||||||||
| echo "Nomad command exit code: $?" | ||||||||
| echo "Output:" | ||||||||
| echo "$nomad_output" | ||||||||
| exit 1 | ||||||||
|
Comment on lines
+144
to
+149
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Exit code capture is incorrect. Line 146 attempts to capture the Nomad command's exit code with 🔎 Proposed fix echo "Running Nomad job: ${JOB_NAME}"
if ! nomad_output=$(nix run --impure --inputs-from . nixpkgs#nomad -- job run nomad/jobs/${JOB_NAME}.nomad.hcl 2>&1); then
+ nomad_exit_code=$?
echo "ERROR: Failed to run Nomad job"
- echo "Nomad command exit code: $?"
+ echo "Nomad command exit code: $nomad_exit_code"
echo "Output:"
echo "$nomad_output"
exit 1
fi🤖 Prompt for AI Agents |
||||||||
| fi | ||||||||
|
|
||||||||
| echo "$nomad_output" | ||||||||
| echo "Ran ${JOB_NAME} with run ID ${RUN_ID}" >> "$GITHUB_STEP_SUMMARY" | ||||||||
| alloc_ids=$(echo "$nomad_output" | grep -oP --color=never 'Allocation "\K[0-9a-f]+(?=" created)' | paste -sd ' ' -) | ||||||||
|
|
||||||||
| echo "Extracting allocation IDs from Nomad output..." | ||||||||
| if ! alloc_ids=$(echo "$nomad_output" | grep -oP --color=never 'Allocation "\K[0-9a-f]+(?=" created)' 2>&1); then | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use The current implementation uses Based on learnings, 🔎 Proposed fix for portability echo "Extracting allocation IDs from Nomad output..."
- if ! alloc_ids=$(echo "$nomad_output" | grep -oP --color=never 'Allocation "\K[0-9a-f]+(?=" created)' 2>&1); then
+ if ! alloc_ids=$(echo "$nomad_output" | grep -oE --color=never 'Allocation "[0-9a-f-]+" created' | grep -oE '[0-9a-f-]+' | grep -v 'Allocation\|created' 2>&1); then
grep_exit_code=$?Alternatively, if the Nomad output format is predictable, you could use a simpler pattern: echo "Extracting allocation IDs from Nomad output..."
- if ! alloc_ids=$(echo "$nomad_output" | grep -oP --color=never 'Allocation "\K[0-9a-f]+(?=" created)' 2>&1); then
+ if ! alloc_ids=$(echo "$nomad_output" | grep -oE 'Allocation "[0-9a-f-]+"' | cut -d'"' -f2 2>&1); then
grep_exit_code=$?📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| grep_exit_code=$? | ||||||||
| echo "ERROR: grep command failed with exit code ${grep_exit_code}" | ||||||||
| if [ $grep_exit_code -eq 1 ]; then | ||||||||
| echo "No allocation IDs found in Nomad output (no matches)" | ||||||||
| elif [ $grep_exit_code -eq 2 ]; then | ||||||||
| echo "grep encountered an error (invalid regex or other issue)" | ||||||||
| fi | ||||||||
| echo "Full Nomad output for debugging:" | ||||||||
| echo "--- START NOMAD OUTPUT ---" | ||||||||
| echo "$nomad_output" | ||||||||
| echo "--- END NOMAD OUTPUT ---" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| if ! alloc_ids=$(echo "$alloc_ids" | paste -sd ' ' - 2>&1); then | ||||||||
| echo "ERROR: Failed to format allocation IDs" | ||||||||
| echo "paste command failed" | ||||||||
| echo "Raw allocation IDs:" | ||||||||
| echo "$alloc_ids" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| if [ -z "$alloc_ids" ]; then | ||||||||
| echo "Failed to extract allocation IDs from Nomad job output" | ||||||||
| echo "ERROR: Extracted allocation IDs string is empty" | ||||||||
| echo "Full Nomad output for debugging:" | ||||||||
| echo "--- START NOMAD OUTPUT ---" | ||||||||
| echo "$nomad_output" | ||||||||
| echo "--- END NOMAD OUTPUT ---" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| echo "Successfully extracted allocation IDs: $alloc_ids" | ||||||||
|
|
||||||||
| echo "Reading job duration from nomad/vars/${JOB_NAME}.json..." | ||||||||
| if ! duration="$(jq -e -r '.duration' "nomad/vars/${JOB_NAME}.json" 2>&1)"; then | ||||||||
| echo "ERROR: Failed to read duration from nomad/vars/${JOB_NAME}.json" | ||||||||
| echo "jq output: $duration" | ||||||||
| exit 1 | ||||||||
| fi | ||||||||
|
|
||||||||
| duration="$(jq -e -r '.duration' "nomad/vars/${JOB_NAME}.json")" | ||||||||
| echo "Job duration: ${duration}s" | ||||||||
|
|
||||||||
| echo "alloc_ids=$alloc_ids" >> "$GITHUB_OUTPUT" | ||||||||
| echo "started_at=$(date +%s)" >> "$GITHUB_OUTPUT" | ||||||||
| echo "job_name=${JOB_NAME}" >> "$GITHUB_OUTPUT" | ||||||||
| echo "duration=$duration" >> "$GITHUB_OUTPUT" | ||||||||
|
|
||||||||
| echo "Successfully configured Nomad job outputs" | ||||||||
|
|
||||||||
| - name: Save alloc_ids to file | ||||||||
| run: | | ||||||||
| started_at=${{ steps.run-nomad-job.outputs.started_at }} | ||||||||
|
|
||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought
set -euo pipefailshould already cause the command within$()to send its stderr to the shell's stderr which I thought github actions would print?