Skip to content

Add GitHub Actions annotation primitive to ddev's Application#23654

Open
AAraKKe wants to merge 4 commits into
masterfrom
aarakke/ddev-annotate-primitive
Open

Add GitHub Actions annotation primitive to ddev's Application#23654
AAraKKe wants to merge 4 commits into
masterfrom
aarakke/ddev-annotate-primitive

Conversation

@AAraKKe
Copy link
Copy Markdown
Contributor

@AAraKKe AAraKKe commented May 10, 2026

What does this PR do?

Adds three helpers to ddev's Application so commands can emit GitHub Actions workflow annotations (::error / ::warning) that surface inline in PR diffs on CI:

  • Application.annotate_error(file, message, line=1)
  • Application.annotate_warning(file, message, line=1)
  • Application.annotate_display_queue(file, display_queue, line=1) — takes a list of (level, message) tuples and groups same-level messages into a single multi-line annotation using the GitHub %0A newline escape.

All three are no-ops outside CI; the CI check reuses ddev's existing ddev.utils.ci.running_in_ci() helper (which already recognises GITHUB_ACTIONS=true|1 and CI=true|1). Workflow commands are emitted via print() to stdout — that's where the runner parses them, and it avoids the shell-injection footgun of the legacy os.system("echo ...") implementation.

Helper gap notes

  • _emit_github_annotation is intentionally a private method on Application rather than a standalone helper. It's only consumed by the two public annotate_* entry points and reusing Application's state (and following the existing convention of display_* living on Application) keeps the surface compact.
  • The display-queue helper's tuple shape is (level, message) (ddev style) rather than legacy (func, message). The retrofit PR for the three already-migrated commands will adapt their queues to the new shape.

Test plan

  • ddev --no-interactive test ddev passes (993 passed; the 3 tests/utils/test_github.py failures are the documented worktree-vs-cassette noise unrelated to this change — see 00-overview.md Known issues).
  • ddev test -fs ddev reports no formatter changes.
  • New ddev/tests/cli/test_application.py covers: on-CI emits the workflow command on stdout (parametrized over error/warning); off-CI is silent; custom line is preserved; shell-unsafe characters round-trip cleanly (regression for the legacy os.system smell); display-queue groups levels with %0A; unknown levels are skipped; empty queue emits nothing; off-CI display-queue is silent.

Motivation

ddev was missing a primitive for the GitHub Actions workflow-command annotations that legacy datadog_checks_dev/tooling/commands/console.py exposes as annotate_error / annotate_warning / annotate_display_queue. Three in-flight migration PRs that touched commands using those helpers — #23651 (validate codeowners), #23652 (validate jmx-metrics), and #23653 (validate config) — had to drop the annotation calls, regressing CI annotation UX (errors no longer surface inline in PR diffs on CI).

This PR adds the missing primitive to Application so:

  1. Future migrations that touch annotation-using commands (validate dashboards, validate models, validate service-checks, meta manifest, …) don't have to choose between dropping the feature or porting the helper ad-hoc.
  2. A follow-up PR can retrofit Migrate validate codeowners from datadog_checks_dev to ddev #23651 / Migrate validate jmx-metrics from datadog_checks_dev to ddev #23652 / Migrate validate config from datadog_checks_dev to ddev #23653 so they regain CI annotation parity with master.

No changes to datadog_checks_dev/. No change to the existing Application surface beyond the three new methods.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Adds Application.annotate_error/annotate_warning/annotate_display_queue
that emit GitHub Actions workflow annotations (::error/::warning) when
running on CI and no-op locally. Mirrors the legacy
datadog_checks_dev/tooling/commands/console.py helpers so future
migrations (and a retrofit of #23651/#23652/#23653) keep CI annotation
UX.

The display-queue helper takes a list of (level, message) tuples instead
of the legacy (func, message) shape, which is idiomatic for ddev's
Application-style API.
@AAraKKe AAraKKe added the qa/skip-qa Automatically skip this PR for the next QA label May 10, 2026
@dd-octo-sts dd-octo-sts Bot added the ddev label May 10, 2026
AAraKKe added 2 commits May 10, 2026 22:54
- Replace ANNOTATION_LEVEL_ERROR/WARNING string constants and the
  _GH_ANNOTATION_LEVELS frozenset with a single AnnotationLevel(StrEnum).
  Method signatures now type level as AnnotationLevel; the old runtime
  "unknown level falls back to error" guard is gone because the enum
  enforces membership at construction time.
- Swap annotate_display_queue's pre-populated dict + membership filter
  for collections.defaultdict(list). Emission iterates AnnotationLevel
  so output order is deterministic (errors before warnings) regardless
  of input order — covered by a new test.
- Add a one-line comment near the print() call explaining why it isn't
  os.system("echo ...") (the legacy shape was shell-injection prone).
- Tests use AnnotationLevel members directly; new tests for StrEnum
  string-identity and the deterministic emission order. 12 tests total.
@codecov
Copy link
Copy Markdown

codecov Bot commented May 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.87%. Comparing base (03b790e) to head (ba95291).

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@datadog-prod-us1-6
Copy link
Copy Markdown

datadog-prod-us1-6 Bot commented May 10, 2026

Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 87.37% (+0.11%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: ba95291 | Docs | Datadog PR Page | Give us feedback!

@AAraKKe AAraKKe marked this pull request as ready for review May 10, 2026 22:19
@AAraKKe AAraKKe requested a review from a team as a code owner May 10, 2026 22:19
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 38afb36f02

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ddev/src/ddev/cli/application.py Outdated
return
# `print` (not `os.system("echo ...")`): the GH runner parses workflow commands
# off stdout, and shelling out would corrupt messages containing quotes / `$()`.
print(f'::{level} file={file},line={line}::{message}')
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Escape workflow command values before printing

When these helpers are used on GitHub Actions with messages or paths that contain workflow-command control characters, the runner can parse a different command than intended: a literal newline in message terminates the annotation line, %0A in a message is decoded as a newline, and ,/: in file can corrupt the property list. I checked GitHub's workflow-command format (::workflow-command parameter1={data},parameter2={data}::{command value} over stdout) and the official actions/toolkit command implementation, which escapes %, CR, and LF in command data and additionally escapes :, , in properties. Since these helpers accept arbitrary validation/test output, multi-line failures will be truncated or malformed unless file and message are escaped here rather than interpolated raw.

Useful? React with 👍 / 👎.

The previous implementation interpolated message and property values raw
into the workflow command, so a literal newline in the message would
terminate the annotation early, a `%0A` would be decoded back into a
newline, and `,` / `:` in a file path would corrupt the property list.

Add `_escape_workflow_data` and `_escape_workflow_property` private
helpers that mirror `@actions/core`'s `escapeData` / `escapeProperty`:

- Data:     % -> %25, \r -> %0D, \n -> %0A
- Property: same, plus : -> %3A, , -> %2C

Verified against actions/toolkit packages/core/src/command.ts (same
operations, same order). `annotate_display_queue` now joins messages
with a real `\n` so the escaper produces a single canonical `%0A`
sequence instead of double-encoding a literal `%0A`.

Tests cover newline / percent / property-separator round-trips plus
table-driven coverage of each escaper helper. Existing ASCII-only tests
keep passing because the escapers are identity on those inputs.
@dd-octo-sts
Copy link
Copy Markdown
Contributor

dd-octo-sts Bot commented May 10, 2026

Validation Report

All 20 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and Codecov settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ddev qa/skip-qa Automatically skip this PR for the next QA team/agent-integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant