Skip to content

fix regex for finding consumer workflows#135

Merged
derekmisler merged 2 commits into
docker:mainfrom
derekmisler:fix-regex-for-finding-consumer-workflows
Apr 16, 2026
Merged

fix regex for finding consumer workflows#135
derekmisler merged 2 commits into
docker:mainfrom
derekmisler:fix-regex-for-finding-consumer-workflows

Conversation

@derekmisler

@derekmisler derekmisler commented Apr 16, 2026

Copy link
Copy Markdown
Contributor

Related Issues

Closes: https://github.com/docker/gordon/issues/396

Summary

Fixes the GitHub code search query in the release workflow that discovers consumer repos using review-pr.yml. The path: qualifier was using a regex pattern (/^\.github\/workflows\//) that wasn't matching correctly — this replaces it with the simpler string-based path:.github/workflows form, which is what the GitHub code search API actually supports.

Changed file: .github/workflows/release.yml


Tip

Comment /review to trigger the PR Reviewer agent for automated feedback.
Comment /describe to generate a PR description.

@derekmisler derekmisler self-assigned this Apr 16, 2026
@derekmisler
derekmisler requested a review from a team April 16, 2026 14:38
@derekmisler
derekmisler marked this pull request as ready for review April 16, 2026 14:38

@docker-agent docker-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

The change correctly replaces an unsupported regex-style path:/^\.github\/workflows\// qualifier with the documented string-based path:.github/workflows form for the GitHub Search API. The old regex syntax is not part of GitHub's stable code search API and was causing consumer-repo discovery failures (as noted in the linked issue).

No high or medium severity issues found. One minor/informational note left inline.

echo "Searching for consumer repos..."
REPOS=$(gh api --method GET --paginate '/search/code?per_page=100' \
-f q='org:docker "docker/cagent-action/.github/workflows/review-pr.yml@" language:YAML path:/^\.github\/workflows\//' \
-f q='org:docker "docker/cagent-action/.github/workflows/review-pr.yml@" language:YAML path:.github/workflows' \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[LOW] Trailing slash on path: qualifier

The new qualifier path:.github/workflows is a substring match, so it could theoretically match paths like .github/workflows-extra/ in addition to the intended .github/workflows/ directory. Using path:.github/workflows/ (with a trailing slash) is the more precise form and is the pattern documented in GitHub code search examples.

That said, the additional content filter ("docker/cagent-action/.github/workflows/review-pr.yml@") and language:YAML qualifier make any false-positive match practically impossible, so this has no functional impact.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change — the content filter ("docker/cagent-action/.github/workflows/review-pr.yml@") already makes false positives impossible here.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough — you're right that the content filter makes this a non-issue in practice. Thanks for considering it!

@derekmisler
derekmisler enabled auto-merge (squash) April 16, 2026 14:41
@derekmisler
derekmisler force-pushed the fix-regex-for-finding-consumer-workflows branch from 0aaaa8e to dd5f485 Compare April 16, 2026 15:29
@derekmisler

Copy link
Copy Markdown
Contributor Author

/review

@docker-agent docker-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🔴 CRITICAL

The new scripts/update-consumers.sh has one critical portability bug and three error-handling gaps. The release.yml change (fixing the code search path qualifier) is correct and straightforward.

Severity Count Finding
🔴 HIGH 1 sed -i '' breaks on GNU sed / Linux
🟡 MEDIUM 3 Silent API error swallowing, force-push data loss, silent PR failure

# @latest — bare branch/tag reference
# @<sha> # latest — pinned SHA with non-version comment
sed -i '' \
"s|docker/cagent-action/\.github/workflows/review-pr\.yml@.*|docker/cagent-action/.github/workflows/review-pr.yml@${SHA} # ${VERSION}|g" \

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sed -i '' breaks on GNU sed / Linux (macOS-only syntax)

The script uses sed -i '' (BSD sed syntax for in-place editing with no backup). On GNU sed — which is what GitHub Actions Linux runners use — this silently misbehaves: GNU sed treats the empty string '' as the sed script (a no-op), then interprets the actual s|...|...|g expression as a filename, producing No such file or directory. The subshell exits non-zero, GIT_RESULT captures the failure, and every consumer repo is silently skipped with "Git operations failed".

The script is documented as runnable both locally (macOS) and in CI (Linux). Use a cross-platform form:

# Cross-platform: create and remove a backup file
sed -i.bak "s|...|...|g" "${FILE_PATH}" && rm -f "${FILE_PATH}.bak"
# Or use perl:
perl -i -pe 's|docker/cagent-action/\.github/workflows/review-pr\.yml\@.*|docker/cagent-action/.github/workflows/review-pr.yml\@${SHA} # ${VERSION}|g' "${FILE_PATH}"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — switched to sed -i.bak + rm for cross-platform compat.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — the fix looks good! The sed -i.bak + rm pattern works correctly on both GNU sed (Linux) and BSD sed (macOS).

-f q="${SEARCH_QUERY}" \
--jq '[.items[] | {repo: .repository.full_name, path: .path}] | unique_by(.repo) | .[] | "\(.repo) \(.path)"' \
2>/dev/null || true
)"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent API failure makes complete outage indistinguishable from zero results

Both 2>/dev/null and || true are applied to the gh api --paginate discovery call. If the call fails due to rate limiting, expired credentials, network error, or GitHub API degradation, REPOS_RAW is set to an empty string and the script exits 0 with "No consumer repos found." — identical output to a legitimate zero-result search. Release automation reports success while zero consumer repos were updated.

Consider at minimum capturing stderr separately to detect failures:

REPOS_RAW="$(gh api --method GET --paginate '/search/code?per_page=100' \
  -f q="${SEARCH_QUERY}" \
  --jq '[.items[] | {repo: .repository.full_name, path: .path}] | unique_by(.repo) | .[] | "\(.repo) \(.path)"')"
# Let gh's non-zero exit propagate — set -euo pipefail will abort the script

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — removed 2>/dev/null || true so set -e propagates API failures properly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect — thanks for the fix! The API call will now fail loudly when GitHub rate-limits, auth expires, or returns an error, preventing silent zero-result scenarios from being treated as success.


git commit -m "chore: update cagent-action to ${VERSION}" -q
git push --force origin "${BRANCH_NAME}" -q
) || GIT_RESULT=$?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git push --force destroys manual commits on PR branches

The branch is pushed with --force, which unconditionally overwrites the remote branch. If a reviewer or the PR author has pushed fixup commits to the auto/update-cagent-action branch in a consumer repo since the last automated run, those commits are permanently lost on the next execution.

Use --force-with-lease instead — it aborts safely if the remote ref has diverged from what the local clone fetched:

git push --force-with-lease origin "${BRANCH_NAME}" -q

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change — this branch is exclusively managed by this script. Nobody should be pushing manual commits to auto/update-cagent-action.

--title "chore: update cagent-action to ${VERSION}" \
--body-file "${PR_BODY_FILE}" \
2>/dev/null || true
fi

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Silent PR creation/update failures inflate the success counter

Both gh pr edit and gh pr create are followed by 2>/dev/null || true, suppressing all errors and exit codes. If either call fails (insufficient permissions, invalid head ref, API error), the script still prints "✅ Done" and increments COUNT_UPDATED. The summary then shows e.g. "Updated: 5" when zero PRs may have actually been created or updated.

Additionally, gh pr create prints the new PR URL to stdout — 2>/dev/null silently drops it, making newly created PRs unlocatable from the script output.

Consider removing the error suppression and letting failures surface:

gh pr create \
  --repo "${REPO}" \
  --head "${PR_HEAD}" \
  --title "chore: update cagent-action to ${VERSION}" \
  --body-file "${PR_BODY_FILE}" || { COUNT_FAILED=$((COUNT_FAILED + 1)); continue; }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed — removed 2>/dev/null || true from both paths. PR creation now prints the URL on success and increments COUNT_FAILED on failure instead of silently counting as success.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed — the fix looks good! Both paths now properly handle failures:

  • gh pr edit increments COUNT_FAILED on non-zero exit
  • gh pr create increments COUNT_FAILED and surfaces the error message on failure
  • On success, gh pr create now captures and displays the PR URL

The counters now accurately reflect reality, and newly created PRs are immediately visible in the output. Thanks for the quick turnaround!

@derekmisler
derekmisler merged commit 22cb576 into docker:main Apr 16, 2026
26 checks passed
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