Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion .github/workflows/dd-trace-v5-pin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ name: dd-trace v5 pin freshness
# scripts/dd_trace_versions.sh (the dependency-update workflow only tracks
# the v6 line). Runs when the pin file changes and weekly; the same check
# gates the npm publish job in GitLab.
#
# Outside of pull requests, results are reported to #apm-serverless:
# - stale pin: a reminder is posted and the job succeeds (it did its job);
# - the check itself fails: an alert is posted and the job fails.
# On pull requests, nothing is posted and any non-zero exit fails the job.
# A failing Slack notification also fails the job.

on:
push:
Expand All @@ -23,6 +29,7 @@ on:
jobs:
check-pin:
runs-on: ubuntu-latest
environment: datadog-lambda-js-pin
steps:
- name: Checkout
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
Expand All @@ -33,4 +40,44 @@ jobs:
node-version: "22.x"

- name: Check the v5 pin against the npm registry
run: ./scripts/check_dd_trace_v5_pin.sh
id: check
# exit codes: 0 = pin current, 2 = pin stale, anything else = the check failed
run: |
status=0
./scripts/check_dd_trace_v5_pin.sh || status=$?
echo "status=$status" >> "$GITHUB_OUTPUT"

- name: "Notify #apm-serverless that the pin is stale"
if: steps.check.outputs.status == '2' && github.event_name != 'pull_request'
env:
# Incoming webhook bound to #apm-serverless
SLACK_WEBHOOK: ${{ secrets.SLACK_ALERTS_WEBHOOK }}
CONFIGURED: ${{ steps.check.outputs.configured }}
LATEST: ${{ steps.check.outputs.latest }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
text=":warning: datadog-lambda-js: the dd-trace v5 pin is stale (configured \`$CONFIGURED\`, latest \`$LATEST\`). Bump \`DD_TRACE_V5_VERSION\` in \`scripts/dd_trace_versions.sh\`. <$RUN_URL|Workflow run>"
payload=$(jq -n --arg text "$text" '{text: $text, unfurl_links: false}')
# Incoming webhooks answer non-2xx on errors (revoked webhook, bad payload, ...)
curl -sS --fail-with-body -X POST "$SLACK_WEBHOOK" \
-H "Content-Type: application/json; charset=utf-8" \
--data "$payload"

- name: "Notify #apm-serverless that the check failed"
if: steps.check.outputs.status != '0' && steps.check.outputs.status != '2' && github.event_name != 'pull_request'
env:
SLACK_WEBHOOK: ${{ secrets.SLACK_ALERTS_WEBHOOK }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
text=":x: datadog-lambda-js: the dd-trace v5 pin check unexpectedly failed. <$RUN_URL|Workflow run>"
payload=$(jq -n --arg text "$text" '{text: $text, unfurl_links: false}')
curl -sS --fail-with-body -X POST "$SLACK_WEBHOOK" \
-H "Content-Type: application/json; charset=utf-8" \
--data "$payload"

- name: Fail the job
# Any failure on pull requests; outside of them, only when the check itself failed
if: steps.check.outputs.status != '0' && (steps.check.outputs.status != '2' || github.event_name == 'pull_request')
run: |
echo "check_dd_trace_v5_pin.sh exited with ${{ steps.check.outputs.status }}" >&2
exit 1
20 changes: 15 additions & 5 deletions scripts/check_dd_trace_v5_pin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
# 1. peerDependencies no longer lists both pins.
# 2. The pin lags latest published v5. Dep-update only tracks the v6 lockfile,
# so 18/20 layers would ship a stale tracer.
#
# Exit codes: 0 = pin current, 2 = pin stale (case 2), 1 = anything else.
# When run in GitHub Actions, a stale pin also writes configured=/latest= to
# $GITHUB_OUTPUT so the workflow can report it.

set -e

Expand All @@ -31,26 +35,32 @@ fi

echo "peerDependencies['dd-trace'] advertises both pins: $peer_range"

# npm may return a single string or an array of matching versions; take the last
latest_v5=$(npm view 'dd-trace@5' version --json | node -e "
# npm may return a single string or an array of matching versions; take the last.
# On registry errors npm exits non-zero and prints a JSON error object: pipefail
# keeps that exit status, and the version check rejects anything else unexpected.
latest_v5=$(set -o pipefail; npm view 'dd-trace@5' version --json | node -e "
let d = '';
process.stdin
.on('data', (c) => (d += c))
.on('end', () => {
const v = JSON.parse(d);
console.log(Array.isArray(v) ? v[v.length - 1] : v);
});
")
") || latest_v5=""

if [ -z "$latest_v5" ]; then
if ! [[ "$latest_v5" =~ ^5\.[0-9]+\.[0-9]+$ ]]; then
echo "Could not determine the latest dd-trace v5 version from the npm registry" >&2
exit 1
fi

if [ "$DD_TRACE_V5_VERSION" != "$latest_v5" ]; then
echo "dd-trace v5 pin is stale: configured=$DD_TRACE_V5_VERSION latest=$latest_v5" >&2
echo "Bump DD_TRACE_V5_VERSION in scripts/dd_trace_versions.sh" >&2
exit 1
if [ -n "$GITHUB_OUTPUT" ]; then
echo "configured=$DD_TRACE_V5_VERSION" >> "$GITHUB_OUTPUT"
echo "latest=$latest_v5" >> "$GITHUB_OUTPUT"
Comment thread
cbeauchesne marked this conversation as resolved.
Resolved
fi
exit 2
fi

echo "dd-trace v5 pin is current: $DD_TRACE_V5_VERSION"
Loading