Skip to content

chore: get agent version from datadog-agent changelog#1144

Merged
kathiehuang merged 6 commits intomainfrom
kathie.huang/set-agent-version
Mar 31, 2026
Merged

chore: get agent version from datadog-agent changelog#1144
kathiehuang merged 6 commits intomainfrom
kathie.huang/set-agent-version

Conversation

@kathiehuang
Copy link
Copy Markdown
Contributor

@kathiehuang kathiehuang commented Mar 31, 2026

Overview

  • In the nightly builds of serverless-init, set the agent version to be the most recently released version of datadog-agent
  • In the release build of serverless-init, if AGENT_VERSION is not set, use the most recently released version from the Datadog agent branch given

Testing

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

 AGENT_VERSION: 7.77.1

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.yml to compute agent version from git tags when not provided and clarified this behavior in the input description
  • Updated .github/workflows/nightly-serverless-init.yml to 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

Comment on lines +56 to +63
- 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"
Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

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.

Copilot generated this review using guidance from repository custom instructions.
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.

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

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.

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"?

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.

We don't own it - seems like this number was set a long time ago, and some tests use this number

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: 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)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

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.

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)
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 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 👍 / 👎.

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.

Updated to get the agent version from CHANGELOG, which should be the CHANGELOG from the checked-out branch

1c875ff

@kathiehuang
Copy link
Copy Markdown
Contributor Author

@codex review

@kathiehuang kathiehuang changed the title chore: get agent version from datadog-agent tag list chore: get agent version from datadog-agent changelog Mar 31, 2026
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: 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)
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 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 👍 / 👎.

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.

Updated to log an error when grep fails so that in a serverless-init release, the user knows to set AGENT_VERSION manually

bd66093

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; }
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.

nice!

Comment on lines +56 to +63
- 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"
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.

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"?

@kathiehuang
Copy link
Copy Markdown
Contributor Author

kathiehuang commented Mar 31, 2026

Integration tests aren't passing because axios is blocked, but this shouldn't affect them

@kathiehuang kathiehuang merged commit 0d19e53 into main Mar 31, 2026
51 of 55 checks passed
@kathiehuang kathiehuang deleted the kathie.huang/set-agent-version branch March 31, 2026 22:07
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.

4 participants