chore: get agent version from datadog-agent changelog#1144
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates GitHub workflow files to automatically determine the Datadog agent version from released tags when not explicitly provided. In the nightly builds of serverless-init, it sets the agent version to the most recent release tag, and in release builds, if AGENT_VERSION is not provided, it uses the most recent release tag from the specified branch.
Changes:
- Updated
.github/workflows/release-serverless-init.ymlto compute agent version from git tags when not provided and clarified this behavior in the input description - Updated
.github/workflows/nightly-serverless-init.ymlto compute agent version from git tags for nightly builds - Both workflows now use a consistent approach to query semantic version tags from the datadog-agent repository
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| .github/workflows/release-serverless-init.yml | Added automatic agent version detection from git tags, updated input description, and modified build environment variable to use computed version |
| .github/workflows/nightly-serverless-init.yml | Added agent version computation from git tags and passed it to build environment |
| - name: Compute agent version | ||
| id: meta | ||
| run: | | ||
| AGENT_VERSION="${{ github.event.inputs.agentVersion }}" | ||
| if [ -z "$AGENT_VERSION" ]; then | ||
| AGENT_VERSION=$(git -C datadog-agent tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -1) | ||
| fi | ||
| echo "agent_version=${AGENT_VERSION}" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
The git command to retrieve the agent version could fail silently. If no tags matching the semantic version pattern are found, AGENT_VERSION will be empty, and the build will proceed with an empty version string. This could cause silent failures or unexpected behavior downstream. Consider adding error handling to verify that AGENT_VERSION is not empty before proceeding, or provide a clear error message if the version cannot be determined.
There was a problem hiding this comment.
There is a default agent version set in datadog-agent, so an empty AGENT_VERSION would lead to it being set to 6.0.0
There was a problem hiding this comment.
is that 6.0.0 value something that we own? does it make sense to bump it to, say, 7.0.0? or better yet, "unknown"?
There was a problem hiding this comment.
We don't own it - seems like this number was set a long time ago, and some tests use this number
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 64f2554347
ℹ️ 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".
| run: | | ||
| STAMP=$(date -u +%Y%m%d) | ||
| SHORT_SHA=$(git -C datadog-agent rev-parse --short=8 HEAD) | ||
| AGENT_VERSION=$(git -C datadog-agent tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -1) |
There was a problem hiding this comment.
Fetch tags before resolving AGENT_VERSION
This command assumes release tags are present locally, but both workflows check out datadog-agent with actions/checkout@v6 defaults and do not enable tag/history fetch. In that default checkout mode, git tag is empty, so this pipeline (git tag | grep ... | head -1) yields no match; under GitHub Actions’ default bash -eo pipefail, the grep exit code fails the step and blocks nightly builds (and release runs when agentVersion is left blank).
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Updated to get agent version from CHANGELOG instead of using tag fetch in 1c875ff
| run: | | ||
| AGENT_VERSION="${{ github.event.inputs.agentVersion }}" | ||
| if [ -z "$AGENT_VERSION" ]; then | ||
| AGENT_VERSION=$(git -C datadog-agent tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -1) |
There was a problem hiding this comment.
Scope fallback tag selection to the chosen branch
The fallback lookup uses git tag --sort=-version:refname without constraining tags to agentBranch, so it can select the newest tag from any release line rather than the checked-out branch. For example, dispatching with an older maintenance branch and empty agentVersion can embed a newer unrelated version string into the built binary, which contradicts the workflow input description that the default comes from the selected branch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Updated to get the agent version from CHANGELOG, which should be the CHANGELOG from the checked-out branch
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1c875ffeea
ℹ️ 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".
| run: | | ||
| STAMP=$(date -u +%Y%m%d) | ||
| SHORT_SHA=$(git -C datadog-agent rev-parse --short=8 HEAD) | ||
| AGENT_VERSION=$(grep -m 1 -E '^[0-9]+\.[0-9]+\.[0-9]+$' datadog-agent/CHANGELOG.rst) |
There was a problem hiding this comment.
Resolve agent version from git tags, not changelog text
This step now depends on grep finding an exact x.y.z line in datadog-agent/CHANGELOG.rst; under the default GitHub Actions shell (bash -e), grep exits non-zero when no match is found, which aborts the workflow before build. Even when it matches, changelog ordering/format is not a stable interface for “latest released tag”, so this can silently select an unreleased or incorrect version string for AGENT_VERSION.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Updated to log an error when grep fails so that in a serverless-init release, the user knows to set AGENT_VERSION manually
| run: | | ||
| STAMP=$(date -u +%Y%m%d) | ||
| SHORT_SHA=$(git -C datadog-agent rev-parse --short=8 HEAD) | ||
| AGENT_VERSION=$(grep -m 1 -E '^[0-9]+\.[0-9]+\.[0-9]+$' datadog-agent/CHANGELOG.rst) || { echo "ERROR: could not detect agent version from datadog-agent's CHANGELOG.rst"; exit 1; } |
| - name: Compute agent version | ||
| id: meta | ||
| run: | | ||
| AGENT_VERSION="${{ github.event.inputs.agentVersion }}" | ||
| if [ -z "$AGENT_VERSION" ]; then | ||
| AGENT_VERSION=$(git -C datadog-agent tag --sort=-version:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | head -1) | ||
| fi | ||
| echo "agent_version=${AGENT_VERSION}" >> "$GITHUB_OUTPUT" |
There was a problem hiding this comment.
is that 6.0.0 value something that we own? does it make sense to bump it to, say, 7.0.0? or better yet, "unknown"?
|
Integration tests aren't passing because axios is blocked, but this shouldn't affect them |
Overview
AGENT_VERSIONis not set, use the most recently released version from the Datadog agent branch givenTesting
Ran the nightly workflow manually off this branch and made sure the logs print the correct agent version https://github.com/DataDog/datadog-lambda-extension/actions/runs/23804573812
https://github.com/DataDog/datadog-lambda-extension/actions/runs/23804573812/job/69374220028#:~:text=AGENT_VERSION%3A%207.77.1