diff --git a/.github/workflows/dd-trace-v5-pin.yml b/.github/workflows/dd-trace-v5-pin.yml index f22f5da2..fbea4746 100644 --- a/.github/workflows/dd-trace-v5-pin.yml +++ b/.github/workflows/dd-trace-v5-pin.yml @@ -4,6 +4,11 @@ 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. +# +# A stale pin is the expected outcome of this job, not a failure: outside of +# pull requests it posts a reminder to #apm-serverless and the job succeeds. +# The job fails only when the check itself or the Slack notification fails. +# On pull requests touching the pin, a stale pin still fails the job. on: push: @@ -33,4 +38,36 @@ jobs: node-version: "22.x" - name: Check the v5 pin against the npm registry - run: ./scripts/check_dd_trace_v5_pin.sh + id: check + run: | + status=0 + ./scripts/check_dd_trace_v5_pin.sh || status=$? + if [ "$status" -eq 2 ] && [ "$GITHUB_EVENT_NAME" != "pull_request" ]; then + echo "stale=true" >> "$GITHUB_OUTPUT" + elif [ "$status" -ne 0 ]; then + exit "$status" + fi + + - name: Notify #apm-serverless that the pin is stale + if: steps.check.outputs.stale == 'true' + 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: | + if [ -z "$CONFIGURED" ] || [ -z "$LATEST" ]; then + echo "The check exited 2 without reporting the configured/latest versions" >&2 + exit 1 + fi + if [ -z "$SLACK_WEBHOOK" ]; then + echo "SLACK_ALERTS_WEBHOOK secret is not set" >&2 + exit 1 + fi + 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, ...), so --fail fails the step + curl -sS --fail-with-body -X POST "$SLACK_WEBHOOK" \ + -H "Content-Type: application/json; charset=utf-8" \ + --data "$payload" diff --git a/scripts/check_dd_trace_v5_pin.sh b/scripts/check_dd_trace_v5_pin.sh index 8f3fcf18..69db3f1f 100755 --- a/scripts/check_dd_trace_v5_pin.sh +++ b/scripts/check_dd_trace_v5_pin.sh @@ -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 @@ -50,7 +54,11 @@ 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" + fi + exit 2 fi echo "dd-trace v5 pin is current: $DD_TRACE_V5_VERSION"