Skip to content

Commit efbdfa5

Browse files
authored
Improve otel-fork-replace workflow: dynamic component discovery, changelog in PR (#2086)
1 parent 19d0782 commit efbdfa5

2 files changed

Lines changed: 94 additions & 42 deletions

File tree

.github/workflows/PR-test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,11 @@ jobs:
355355
exit 0
356356
fi
357357
358+
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'skip testing') }}" == "true" ]]; then
359+
echo "'skip testing' label found - bypassing integration test requirement."
360+
exit 0
361+
fi
362+
358363
if [[ "${{ contains(github.event.pull_request.labels.*.name, 'ready for testing') }}" != "true" ]]; then
359364
echo "Missing 'ready for testing' label. Please add before merging."
360365
exit 1

.github/workflows/otel-fork-replace.yml

Lines changed: 89 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- name: Get latest commit sha
2424
id: get-latest-commit
2525
run: |
26-
if ["${{ inputs.CommitSha }}" == ""]; then
26+
if [ "${{ inputs.CommitSha }}" == "" ]; then
2727
echo "sha=$(git ls-remote ${{ env.UPSTREAM }} ${{ env.UPSTREAM_BRANCH }} | awk '{print $1;}')" >> $GITHUB_OUTPUT
2828
else
2929
echo "sha=${{ inputs.CommitSha }}" >> $GITHUB_OUTPUT
@@ -35,48 +35,90 @@ jobs:
3535
with:
3636
go-version: ~1.25.8
3737
cache: false
38+
- name: Get old commit sha from go.mod
39+
id: get-old-commit
40+
run: |
41+
set -euo pipefail
42+
# Extract all distinct 12-char hash suffixes from fork pseudo-versions in go.mod.
43+
# Pseudo-versions look like: v0.0.0-20260407222105-72a988178008
44+
shas=$(grep 'amazon-contributing/opentelemetry-collector-contrib/' go.mod \
45+
| grep -oE 'v0\.0\.0-[0-9]+-[0-9a-f]{12}' \
46+
| awk -F'-' '{print $NF}' \
47+
| sort -u || true)
48+
if [ -z "$shas" ]; then
49+
echo "::error::No fork components found in go.mod. Nothing to update."
50+
exit 1
51+
fi
52+
count=$(echo "$shas" | wc -l | tr -d ' ')
53+
if [ "$count" -ne 1 ]; then
54+
echo "::error::Found $count distinct fork SHAs in go.mod. A component may be intentionally pinned. Aborting."
55+
echo "$shas"
56+
exit 1
57+
fi
58+
echo "sha=${shas}" >> $GITHUB_OUTPUT
59+
- name: Generate changelog
60+
id: changelog
61+
env:
62+
NEW_SHA: ${{ steps.get-latest-commit.outputs.sha }}
63+
OLD_SHA: ${{ steps.get-old-commit.outputs.sha }}
64+
run: |
65+
set -euo pipefail
66+
REPO_URL="https://github.com/amazon-contributing/opentelemetry-collector-contrib"
67+
git clone --bare ${{ env.UPSTREAM }} /tmp/otel-fork
68+
# old_sha is a 12-char prefix, git log handles prefix matching
69+
raw=$(git -C /tmp/otel-fork log --oneline "${OLD_SHA}..${NEW_SHA}" 2>/dev/null || true)
70+
rm -rf /tmp/otel-fork
71+
{
72+
echo "log<<CHANGELOG_EOF"
73+
if [ -z "$raw" ]; then
74+
echo "Could not generate changelog (old SHA ${OLD_SHA} not found in history)"
75+
else
76+
echo "| Commit | Description | PR |"
77+
echo "| ------ | ----------- | -- |"
78+
echo "$raw" | while IFS= read -r line; do
79+
sha=$(echo "$line" | awk '{print $1}')
80+
msg=$(echo "$line" | cut -d' ' -f2-)
81+
# Extract (#NNN) from end of message if present
82+
if echo "$msg" | grep -qE '\(#[0-9]+\)$'; then
83+
pr_num=$(echo "$msg" | grep -oE '#[0-9]+\)$' | tr -d ')' )
84+
msg=$(echo "$msg" | sed 's/ *(#[0-9]*)$//')
85+
pr_link="[${pr_num}](${REPO_URL}/pull/${pr_num#\#})"
86+
else
87+
pr_link=""
88+
fi
89+
echo "| [\`${sha}\`](${REPO_URL}/commit/${sha}) | ${msg} | ${pr_link} |"
90+
done
91+
fi
92+
echo "CHANGELOG_EOF"
93+
} >> $GITHUB_OUTPUT
3894
- name: Update OTel fork components version
39-
id: set-matrix
95+
env:
96+
SHA: ${{ steps.get-latest-commit.outputs.sha }}
4097
run: |
41-
git config --global user.name 'Github Action'
42-
git config --global user.email 'action@github.com'
43-
git checkout -b otel-fork-replace-${{ steps.get-latest-commit.outputs.sha }}
44-
go mod edit -replace go.opentelemetry.io/collector/config/confighttp=github.com/amazon-contributing/opentelemetry-collector-contrib/config/confighttp@${{ steps.get-latest-commit.outputs.sha }}
45-
go mod tidy
46-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/processor/resourcedetectionprocessor=github.com/amazon-contributing/opentelemetry-collector-contrib/processor/resourcedetectionprocessor@${{ steps.get-latest-commit.outputs.sha }}
47-
go mod tidy
48-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsemfexporter=github.com/amazon-contributing/opentelemetry-collector-contrib/exporter/awsemfexporter@${{ steps.get-latest-commit.outputs.sha }}
49-
go mod tidy
50-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awsxrayexporter=github.com/amazon-contributing/opentelemetry-collector-contrib/exporter/awsxrayexporter@${{ steps.get-latest-commit.outputs.sha }}
51-
go mod tidy
52-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/xray=github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/xray@${{ steps.get-latest-commit.outputs.sha }}
53-
go mod tidy
54-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/awsutil=github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/awsutil@${{ steps.get-latest-commit.outputs.sha }}
55-
go mod tidy
56-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/containerinsight=github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/containerinsight@${{ steps.get-latest-commit.outputs.sha }}
57-
go mod tidy
58-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/k8s=github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/k8s@${{ steps.get-latest-commit.outputs.sha }}
59-
go mod tidy
60-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver=github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awscontainerinsightreceiver@${{ steps.get-latest-commit.outputs.sha }}
61-
go mod tidy
62-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/prometheusreceiver=github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/prometheusreceiver@${{ steps.get-latest-commit.outputs.sha }}
63-
go mod tidy
64-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/prometheus=github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/translator/prometheus@${{ steps.get-latest-commit.outputs.sha }}
65-
go mod tidy
66-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/aws/cwlogs=github.com/amazon-contributing/opentelemetry-collector-contrib/internal/aws/cwlogs@${{ steps.get-latest-commit.outputs.sha }}
67-
go mod tidy
68-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter=github.com/amazon-contributing/opentelemetry-collector-contrib/exporter/awscloudwatchlogsexporter@${{ steps.get-latest-commit.outputs.sha }}
69-
go mod tidy
70-
go mod edit -replace github.com/open-telemetry/opentelemetry-collector-contrib/receiver/awsxrayreceiver=github.com/amazon-contributing/opentelemetry-collector-contrib/receiver/awsxrayreceiver@${{ steps.get-latest-commit.outputs.sha }}
71-
go mod tidy
72-
go mod edit -replace github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws=github.com/amazon-contributing/opentelemetry-collector-contrib/override/aws@${{ steps.get-latest-commit.outputs.sha }}
73-
go mod tidy
74-
go mod edit -replace github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza=github.com/amazon-contributing/opentelemetry-collector-contrib/pkg/stanza@${{ steps.get-latest-commit.outputs.sha }}
98+
set -euo pipefail
99+
git config user.name 'Github Action'
100+
git config user.email 'action@github.com'
101+
git checkout -b "otel-fork-replace-${SHA}"
102+
103+
# Parse go.mod for all replace directives pointing to the fork,
104+
# then rewrite each one to the new SHA. This ensures the workflow
105+
# automatically covers any components added or removed in go.mod.
106+
grep 'amazon-contributing/opentelemetry-collector-contrib/' go.mod \
107+
| grep '=>' \
108+
| sed 's/^[[:space:]]*//' \
109+
| sed 's/^replace //' \
110+
| while IFS= read -r line; do
111+
# Extract: left => right (ignoring version suffix)
112+
left=$(echo "$line" | awk -F' => ' '{print $1}')
113+
right=$(echo "$line" | awk -F' => ' '{print $2}' | awk '{print $1}')
114+
echo "Updating: ${left} => ${right}@${SHA}"
115+
go mod edit -replace "${left}=${right}@${SHA}"
116+
done
117+
75118
go mod tidy
76-
git commit -am "Update OTel fork components to https://github.com/amazon-contributing/opentelemetry-collector-contrib/commit/${{ steps.get-latest-commit.outputs.sha }}"
119+
120+
git commit -am "Update OTel fork components to https://github.com/amazon-contributing/opentelemetry-collector-contrib/commit/${SHA}"
77121
git push -u origin HEAD
78-
git config --global --unset user.name
79-
git config --global --unset user.email
80122
- name: Create pull request
81123
uses: repo-sync/pull-request@7e79a9f5dc3ad0ce53138f01df2fad14a04831c5 # v2.12.1
82124
with:
@@ -87,13 +129,18 @@ jobs:
87129
pr_body: |
88130
# Description of the issue
89131
An automated PR to update the OTel fork components to point to [${{ steps.get-latest-commit.outputs.sha }}](https://github.com/amazon-contributing/opentelemetry-collector-contrib/commit/${{ steps.get-latest-commit.outputs.sha }}).
90-
132+
133+
## Commits since last update
134+
Previous SHA: `${{ steps.get-old-commit.outputs.sha }}`
135+
136+
${{ steps.changelog.outputs.log }}
137+
91138
# License
92139
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
93-
140+
94141
# Tests
95142
n/a
96-
143+
97144
# Requirements
98145
_Before commit the code, please do the following steps._
99146
1. Run `make fmt` and `make fmt-sh`

0 commit comments

Comments
 (0)