|
| 1 | +name: Sync Fleet Manager OTEL Integration changelog |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + paths: |
| 8 | + - otel-integration/CHANGELOG.md |
| 9 | + - otel-linux-standalone/CHANGELOG.md |
| 10 | + - otel-macos-standalone/CHANGELOG.md |
| 11 | + - otel-windows-standalone/CHANGELOG.md |
| 12 | + - cmd/helmlog/** |
| 13 | + - go.mod |
| 14 | + - go.sum |
| 15 | + workflow_dispatch: |
| 16 | + inputs: |
| 17 | + fleet_manager_repo: |
| 18 | + description: "Fleet Manager repo in owner/repo format" |
| 19 | + type: string |
| 20 | + default: "coralogix/fleet-manager" |
| 21 | + required: false |
| 22 | + fleet_manager_ref: |
| 23 | + description: "Fleet Manager ref (branch/tag/SHA)" |
| 24 | + type: string |
| 25 | + default: "master" |
| 26 | + required: false |
| 27 | + create_pr: |
| 28 | + description: "If true, create branch/commit/push and open PR in Fleet Manager" |
| 29 | + type: boolean |
| 30 | + default: false |
| 31 | + |
| 32 | +permissions: |
| 33 | + contents: read |
| 34 | + |
| 35 | +jobs: |
| 36 | + sync-fleet-manager-otel-integration-changelog: |
| 37 | + runs-on: ubuntu-latest |
| 38 | + steps: |
| 39 | + - uses: actions/checkout@v4 |
| 40 | + |
| 41 | + - uses: actions/setup-go@v4 |
| 42 | + with: |
| 43 | + go-version-file: 'go.mod' |
| 44 | + |
| 45 | + - name: Validate changelog format |
| 46 | + run: | |
| 47 | + go run ./cmd/helmlog validate \ |
| 48 | + otel-integration/CHANGELOG.md \ |
| 49 | + otel-linux-standalone/CHANGELOG.md \ |
| 50 | + otel-macos-standalone/CHANGELOG.md \ |
| 51 | + otel-windows-standalone/CHANGELOG.md |
| 52 | +
|
| 53 | + - name: Generate changelog artifacts (json) |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | +
|
| 57 | + go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel-integration_changelog.json" otel-integration/CHANGELOG.md |
| 58 | + go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel-linux-standalone_changelog.json" otel-linux-standalone/CHANGELOG.md |
| 59 | + go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel-macos-standalone_changelog.json" otel-macos-standalone/CHANGELOG.md |
| 60 | + go run ./cmd/helmlog generate --output "$RUNNER_TEMP/otel-windows-standalone_changelog.json" otel-windows-standalone/CHANGELOG.md |
| 61 | +
|
| 62 | + - name: Checkout Fleet Manager |
| 63 | + uses: actions/checkout@v4 |
| 64 | + with: |
| 65 | + repository: ${{ inputs.fleet_manager_repo || 'coralogix/fleet-manager' }} |
| 66 | + ref: ${{ inputs.fleet_manager_ref || 'master' }} |
| 67 | + path: fleet-manager |
| 68 | + fetch-depth: 0 |
| 69 | + token: ${{ secrets.GH_TOKEN }} |
| 70 | + |
| 71 | + - name: Copy artifacts when changed |
| 72 | + id: update_file |
| 73 | + run: | |
| 74 | + set -euo pipefail |
| 75 | + mappings=( |
| 76 | + "otel-integration_changelog.json:pkg/helm/data/otel-integration_changelog.json" |
| 77 | + "otel-linux-standalone_changelog.json:pkg/helm/data/otel-linux-standalone_changelog.json" |
| 78 | + "otel-macos-standalone_changelog.json:pkg/helm/data/otel-macos-standalone_changelog.json" |
| 79 | + "otel-windows-standalone_changelog.json:pkg/helm/data/otel-windows-standalone_changelog.json" |
| 80 | + ) |
| 81 | +
|
| 82 | + changed_files=() |
| 83 | +
|
| 84 | + for mapping in "${mappings[@]}"; do |
| 85 | + src_name="${mapping%%:*}" |
| 86 | + dst_name="${mapping##*:}" |
| 87 | + src="$RUNNER_TEMP/$src_name" |
| 88 | + dst="$GITHUB_WORKSPACE/fleet-manager/$dst_name" |
| 89 | +
|
| 90 | + if [ -f "$dst" ] && cmp -s "$src" "$dst"; then |
| 91 | + continue |
| 92 | + fi |
| 93 | +
|
| 94 | + mkdir -p "$(dirname "$dst")" |
| 95 | + cp "$src" "$dst" |
| 96 | + changed_files+=("$dst_name") |
| 97 | + done |
| 98 | +
|
| 99 | + if [ "${#changed_files[@]}" -eq 0 ]; then |
| 100 | + echo "No changelog updates to sync." |
| 101 | + echo "updated=false" >> "$GITHUB_OUTPUT" |
| 102 | + exit 0 |
| 103 | + fi |
| 104 | +
|
| 105 | + echo "updated=true" >> "$GITHUB_OUTPUT" |
| 106 | + printf 'changed_files=%s\n' "${changed_files[*]}" >> "$GITHUB_OUTPUT" |
| 107 | +
|
| 108 | + - name: Create or update Fleet Manager PR |
| 109 | + if: steps.update_file.outputs.updated == 'true' |
| 110 | + env: |
| 111 | + GH_TOKEN: ${{ secrets.GH_TOKEN }} |
| 112 | + CREATE_PR: ${{ github.event_name != 'workflow_dispatch' || inputs.create_pr }} |
| 113 | + FLEET_MANAGER_REPO: ${{ inputs.fleet_manager_repo || 'coralogix/fleet-manager' }} |
| 114 | + FLEET_MANAGER_REF: ${{ inputs.fleet_manager_ref || 'master' }} |
| 115 | + run: | |
| 116 | + set -euo pipefail |
| 117 | +
|
| 118 | + if [ -z "${GH_TOKEN:-}" ]; then |
| 119 | + echo "Missing GH_TOKEN secret" |
| 120 | + exit 1 |
| 121 | + fi |
| 122 | +
|
| 123 | + repo_dir="$GITHUB_WORKSPACE/fleet-manager" |
| 124 | + branch="bot/sync-otel-integration-changelog" |
| 125 | +
|
| 126 | + if [ "${CREATE_PR:-false}" != "true" ]; then |
| 127 | + echo "CREATE_PR is false; skipping branch/commit/push/PR. (Dry run complete.)" |
| 128 | + echo "" |
| 129 | + echo "Changed files in Fleet Manager:" |
| 130 | + git -C "$repo_dir" --no-pager diff --stat |
| 131 | + echo "" |
| 132 | + echo "Full diff:" |
| 133 | + git -C "$repo_dir" --no-pager diff |
| 134 | + exit 0 |
| 135 | + fi |
| 136 | +
|
| 137 | + git -C "$repo_dir" config user.name "github-actions[bot]" |
| 138 | + git -C "$repo_dir" config user.email "github-actions[bot]@users.noreply.github.com" |
| 139 | +
|
| 140 | + if git -C "$repo_dir" ls-remote --exit-code --heads origin "$branch" >/dev/null 2>&1; then |
| 141 | + git -C "$repo_dir" fetch origin "$branch" |
| 142 | + git -C "$repo_dir" checkout "$branch" |
| 143 | + git -C "$repo_dir" rebase "origin/$FLEET_MANAGER_REF" |
| 144 | + else |
| 145 | + git -C "$repo_dir" checkout -b "$branch" |
| 146 | + fi |
| 147 | +
|
| 148 | + read -r -a changed_files <<< "${{ steps.update_file.outputs.changed_files }}" |
| 149 | + git -C "$repo_dir" add "${changed_files[@]}" |
| 150 | + if git -C "$repo_dir" diff --cached --quiet; then |
| 151 | + echo "No changes to commit." |
| 152 | + exit 0 |
| 153 | + fi |
| 154 | +
|
| 155 | + git -C "$repo_dir" commit -m "Update OTEL changelog artifacts" |
| 156 | + git -C "$repo_dir" push origin "$branch" |
| 157 | +
|
| 158 | + existing_pr="$(gh pr list -R "$FLEET_MANAGER_REPO" --head "$branch" --state open --json number --jq '.[0].number')" |
| 159 | + if [ -n "$existing_pr" ]; then |
| 160 | + echo "PR already exists: #$existing_pr" |
| 161 | + exit 0 |
| 162 | + fi |
| 163 | +
|
| 164 | + gh pr create \ |
| 165 | + -R "$FLEET_MANAGER_REPO" \ |
| 166 | + --base "$FLEET_MANAGER_REF" \ |
| 167 | + --head "$branch" \ |
| 168 | + --title "Update OTEL changelog artifacts" \ |
| 169 | + --body "Automated update of OTEL changelog JSON artifacts generated from telemetry-shippers changelog sources." |
0 commit comments