|
| 1 | +name: Sync OBI Chart Version |
| 2 | + |
| 3 | +on: |
| 4 | + repository_dispatch: |
| 5 | + types: [obi-chart-release] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + version: |
| 9 | + description: 'New opentelemetry-ebpf-instrumentation chart version' |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +env: |
| 14 | + DEPENDENCY_NAME: opentelemetry-ebpf-instrumentation |
| 15 | + # Charts consuming the OBI chart dependency |
| 16 | + CHARTS: otel-integration |
| 17 | + # Path (relative to repo root) whose Chart.yaml carries the dependency |
| 18 | + CHART_PATHS: otel-integration/k8s-helm |
| 19 | + # Source of the chart + changelog |
| 20 | + SOURCE_REPO: coralogix/opentelemetry-helm-charts |
| 21 | + CHANGELOG_PATH: charts/opentelemetry-ebpf-instrumentation/CHANGELOG.md |
| 22 | + |
| 23 | +jobs: |
| 24 | + bump-version: |
| 25 | + runs-on: ubuntu-latest |
| 26 | + permissions: |
| 27 | + contents: write |
| 28 | + pull-requests: write |
| 29 | + |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + fetch-depth: 0 |
| 34 | + |
| 35 | + - uses: azure/setup-helm@v4 |
| 36 | + |
| 37 | + - name: Install yq |
| 38 | + run: | |
| 39 | + sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 |
| 40 | + sudo chmod +x /usr/local/bin/yq |
| 41 | +
|
| 42 | + - name: Add helm repos |
| 43 | + run: | |
| 44 | + helm repo add coralogix-charts https://cgx.jfrog.io/artifactory/coralogix-charts |
| 45 | + helm repo add coralogix-charts-virtual https://cgx.jfrog.io/artifactory/coralogix-charts-virtual |
| 46 | + helm repo update |
| 47 | +
|
| 48 | + - name: Get version |
| 49 | + id: version |
| 50 | + run: | |
| 51 | + if [[ "${{ github.event_name }}" == "repository_dispatch" ]]; then |
| 52 | + VERSION="${{ github.event.client_payload.version }}" |
| 53 | + SOURCE_PR="${{ github.event.client_payload.pr_url }}" |
| 54 | + else |
| 55 | + VERSION="${{ inputs.version }}" |
| 56 | + SOURCE_PR="" |
| 57 | + fi |
| 58 | + echo "value=$VERSION" >> $GITHUB_OUTPUT |
| 59 | + echo "source_pr=$SOURCE_PR" >> $GITHUB_OUTPUT |
| 60 | +
|
| 61 | + - name: Extract full changelog |
| 62 | + id: changelog |
| 63 | + run: | |
| 64 | + TARGET_VERSION="${{ steps.version.outputs.value }}" |
| 65 | + echo "Target version: $TARGET_VERSION" |
| 66 | +
|
| 67 | + # Current pinned dependency version across consuming charts |
| 68 | + MIN_VERSION="" |
| 69 | + for chart in $CHART_PATHS; do |
| 70 | + if [[ -f "${chart}/Chart.yaml" ]]; then |
| 71 | + VER=$(yq ".dependencies[] | select(.name == \"$DEPENDENCY_NAME\") | .version" "${chart}/Chart.yaml" 2>/dev/null | head -1 | tr -d '"') |
| 72 | + if [[ -n "$VER" ]]; then |
| 73 | + echo " $chart: $VER" |
| 74 | + if [[ -z "$MIN_VERSION" ]] || [[ "$(printf '%s\n' "$VER" "$MIN_VERSION" | sort -V | head -1)" == "$VER" ]]; then |
| 75 | + MIN_VERSION="$VER" |
| 76 | + fi |
| 77 | + fi |
| 78 | + fi |
| 79 | + done |
| 80 | +
|
| 81 | + echo "Minimum version across charts: $MIN_VERSION" |
| 82 | +
|
| 83 | + # Skip if minimum version is at or above target (all charts already up-to-date) |
| 84 | + HIGHEST=$(printf '%s\n' "$MIN_VERSION" "$TARGET_VERSION" | sort -V | tail -1) |
| 85 | + if [[ "$MIN_VERSION" == "$TARGET_VERSION" ]] || [[ "$HIGHEST" == "$MIN_VERSION" ]]; then |
| 86 | + echo "All charts already at target version or newer (min=$MIN_VERSION >= target=$TARGET_VERSION)" |
| 87 | + echo "status=skip" >> $GITHUB_OUTPUT |
| 88 | + echo "file=" >> $GITHUB_OUTPUT |
| 89 | + exit 0 |
| 90 | + fi |
| 91 | +
|
| 92 | + echo "Baseline for changelog: $MIN_VERSION" |
| 93 | +
|
| 94 | + # Fetch the OBI chart CHANGELOG.md and extract entries between versions |
| 95 | + CHANGELOG=$(gh api "repos/${SOURCE_REPO}/contents/${CHANGELOG_PATH}" \ |
| 96 | + --jq '.content' | base64 -d | awk -v current="$MIN_VERSION" -v target="$TARGET_VERSION" ' |
| 97 | + function semver_cmp(v1, v2, a1, a2, i) { |
| 98 | + split(v1, a1, "."); split(v2, a2, ".") |
| 99 | + for (i = 1; i <= 3; i++) { |
| 100 | + if (a1[i]+0 < a2[i]+0) return -1 |
| 101 | + if (a1[i]+0 > a2[i]+0) return 1 |
| 102 | + } |
| 103 | + return 0 |
| 104 | + } |
| 105 | + /^[[:space:]]*### v[0-9]/ { |
| 106 | + match($0, /[0-9]+\.[0-9]+\.[0-9]+/) |
| 107 | + ver = substr($0, RSTART, RLENGTH) |
| 108 | + in_range = (semver_cmp(ver, current) > 0 && semver_cmp(ver, target) <= 0) |
| 109 | + if (in_range) { |
| 110 | + if (seen_version) print "" |
| 111 | + print "#### Changes from " ENVIRON["DEPENDENCY_NAME"] " " ver ":" |
| 112 | + seen_version = 1 |
| 113 | + } |
| 114 | + next |
| 115 | + } |
| 116 | + in_range && /^[[:space:]]*-/ { print } |
| 117 | + ') |
| 118 | +
|
| 119 | + if [[ -n "$CHANGELOG" ]]; then |
| 120 | + echo "$CHANGELOG" > /tmp/changelog-entries.txt |
| 121 | + echo "status=ok" >> $GITHUB_OUTPUT |
| 122 | + echo "file=/tmp/changelog-entries.txt" >> $GITHUB_OUTPUT |
| 123 | + echo "Extracted changelog entries from $MIN_VERSION to $TARGET_VERSION" |
| 124 | + echo "$CHANGELOG" | head -10 |
| 125 | + else |
| 126 | + echo "status=empty" >> $GITHUB_OUTPUT |
| 127 | + echo "file=" >> $GITHUB_OUTPUT |
| 128 | + echo "No changelog entries found" |
| 129 | + fi |
| 130 | + env: |
| 131 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 132 | + |
| 133 | + - name: Check if update needed |
| 134 | + if: steps.changelog.outputs.status == 'skip' |
| 135 | + run: | |
| 136 | + echo "::notice::Already at target version or newer - skipping" |
| 137 | + exit 0 |
| 138 | +
|
| 139 | + - name: Close stale bump PRs |
| 140 | + if: steps.changelog.outputs.status != 'skip' |
| 141 | + run: | |
| 142 | + VERSION="${{ steps.version.outputs.value }}" |
| 143 | +
|
| 144 | + gh pr list --label obi-bump --state open --json number,title | jq -c '.[]' | while read -r row; do |
| 145 | + PR_NUM=$(echo "$row" | jq -r '.number') |
| 146 | + PR_VERSION=$(echo "$row" | jq -r '.title' | grep -oE '[0-9]+\.[0-9]+\.[0-9]+$' || true) |
| 147 | +
|
| 148 | + [[ -z "$PR_VERSION" || "$PR_VERSION" == "$VERSION" ]] && continue |
| 149 | +
|
| 150 | + HIGHEST=$(printf '%s\n' "$PR_VERSION" "$VERSION" | sort -V | tail -1) |
| 151 | + if [[ "$HIGHEST" == "$VERSION" && "$PR_VERSION" != "$VERSION" ]]; then |
| 152 | + echo "Closing stale PR #$PR_NUM (v$PR_VERSION < v$VERSION)" |
| 153 | + gh pr close $PR_NUM --comment "🔄 Superseded by v${VERSION}. All changelog entries included in new PR." || true |
| 154 | + fi |
| 155 | + done |
| 156 | + env: |
| 157 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 158 | + |
| 159 | + - name: Create branch |
| 160 | + if: steps.changelog.outputs.status != 'skip' |
| 161 | + run: | |
| 162 | + branch_name="chore/bump-obi-${{ steps.version.outputs.value }}" |
| 163 | + echo "branch_name=$branch_name" >> $GITHUB_ENV |
| 164 | +
|
| 165 | + git push origin --delete "$branch_name" 2>/dev/null || true |
| 166 | +
|
| 167 | + git config user.name "github-actions[bot]" |
| 168 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 169 | + git checkout -b $branch_name |
| 170 | + env: |
| 171 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 172 | + |
| 173 | + - name: Run bump script |
| 174 | + if: steps.changelog.outputs.status != 'skip' |
| 175 | + run: | |
| 176 | + CHANGELOG_ARGS="" |
| 177 | + if [[ -n "${{ steps.changelog.outputs.file }}" ]]; then |
| 178 | + CHANGELOG_ARGS="--changelog-file ${{ steps.changelog.outputs.file }}" |
| 179 | + fi |
| 180 | +
|
| 181 | + chmod +x ./scripts/bump-otel-collector-version.sh |
| 182 | + ./scripts/bump-otel-collector-version.sh \ |
| 183 | + --version "${{ steps.version.outputs.value }}" \ |
| 184 | + --dependency-name "$DEPENDENCY_NAME" \ |
| 185 | + --charts "$CHARTS" \ |
| 186 | + $CHANGELOG_ARGS |
| 187 | +
|
| 188 | + - name: Commit and push |
| 189 | + if: steps.changelog.outputs.status != 'skip' |
| 190 | + run: | |
| 191 | + git add -A |
| 192 | + if git diff --staged --quiet; then |
| 193 | + echo "::error::No changes to commit - version ${{ steps.version.outputs.value }} may already be applied" |
| 194 | + exit 1 |
| 195 | + fi |
| 196 | + git commit -m "chore: bump ${DEPENDENCY_NAME} to ${{ steps.version.outputs.value }}" |
| 197 | + git push origin $branch_name |
| 198 | +
|
| 199 | + - name: Build PR body |
| 200 | + if: steps.changelog.outputs.status != 'skip' |
| 201 | + run: | |
| 202 | + if [[ -f "/tmp/otel-bump-summary.md" ]]; then |
| 203 | + cat /tmp/otel-bump-summary.md > /tmp/pr-body.md |
| 204 | + else |
| 205 | + echo "Bumping ${DEPENDENCY_NAME} to \`${{ steps.version.outputs.value }}\`" > /tmp/pr-body.md |
| 206 | + fi |
| 207 | + echo "" >> /tmp/pr-body.md |
| 208 | + if [[ -n "${{ steps.version.outputs.source_pr }}" ]]; then |
| 209 | + echo "**Source:** ${{ steps.version.outputs.source_pr }}" >> /tmp/pr-body.md |
| 210 | + echo "" >> /tmp/pr-body.md |
| 211 | + fi |
| 212 | + case "${{ steps.changelog.outputs.status }}" in |
| 213 | + empty) |
| 214 | + echo "⚠️ **Changelog:** No entries found between versions - using default entry." >> /tmp/pr-body.md |
| 215 | + echo "" >> /tmp/pr-body.md |
| 216 | + ;; |
| 217 | + ok) |
| 218 | + echo "✅ **Changelog:** Includes all entries from current to target version." >> /tmp/pr-body.md |
| 219 | + echo "" >> /tmp/pr-body.md |
| 220 | + ;; |
| 221 | + esac |
| 222 | +
|
| 223 | + - name: Ensure labels exist |
| 224 | + if: steps.changelog.outputs.status != 'skip' |
| 225 | + run: | |
| 226 | + for label in obi-bump chart:otel-integration; do |
| 227 | + gh label create "$label" --description "Auto-created for OBI chart sync" --color "0E8A16" 2>/dev/null || true |
| 228 | + done |
| 229 | + env: |
| 230 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 231 | + |
| 232 | + - name: Create pull request |
| 233 | + if: steps.changelog.outputs.status != 'skip' |
| 234 | + run: | |
| 235 | + gh pr create \ |
| 236 | + --base master \ |
| 237 | + --head "$branch_name" \ |
| 238 | + --title "chore: bump ${DEPENDENCY_NAME} to ${{ steps.version.outputs.value }}" \ |
| 239 | + --body-file /tmp/pr-body.md \ |
| 240 | + --label "obi-bump,chart:otel-integration" |
| 241 | + env: |
| 242 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments