From 0679fbd95705955ad6990b441c12ed0a61161f72 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Dec 2025 16:27:33 +0000 Subject: [PATCH 1/8] Compute the next version from components Compute the next release version based on changes to components that are installed in the container. --- .github/workflows/publish-release.yml | 79 +++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 5a3fcb1..dcd8432 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -37,16 +37,51 @@ jobs: github_app: grafana-otel-bot permission_set: default - - name: Get version + - name: Determine next version id: get-version shell: pwsh env: GH_TOKEN: ${{ steps.get-token.outputs.token }} NEXT_VERSION: ${{ inputs.version }} run: | - if (-Not [string]::IsNullOrEmpty(${env:NEXT_VERSION})) { - $nextVersion = [System.Version]::new(${env:NEXT_VERSION}.TrimStart('v')) - } else { + # Get the component versions from the container image environment variables + function Get-Component-Versions { + param([string]$Image) + + $vars = docker image inspect --format '{{json .Config.Env}}' $Image | ConvertFrom-Json + + $result = [ordered]@{} + $suffix = "_VERSION" + + foreach ($var in $vars | Sort-Object) { + $parts = $var -split '=', 2 + + $key = $parts[0] + $value = $parts[1] + + if ($key.EndsWith($suffix)) { + $result[$key.Substring(0, $key.Length - $suffix.Length)] = [System.Version]::new($value.TrimStart("v")) + } + } + + $result + } + + function Get-Next-LGTM-Version { + + param([string]$NextVersion) + + # Use the version as provided + if (-Not [string]::IsNullOrEmpty($NextVersion)) { + [System.Version]::new($NextVersion.TrimStart('v')).ToString() + return + } + + # Get the versions of the components in the latest release and the main branch + $current = Get-Component-Versions "docker.io/grafana/otel-lgtm:latest" + $next = Get-Component-Versions "ghcr.io/grafana/docker-otel-lgtm:main" + + # Get the current release version from the latest GitHub release $latestUrl = "${env:GITHUB_API_URL}/repos/${env:GITHUB_REPOSITORY}/releases/latest" $headers = @{ Authorization = "Bearer ${env:GH_TOKEN}"; @@ -54,10 +89,42 @@ jobs: } $latest = (Invoke-RestMethod -Uri $latestUrl -Headers $headers -ErrorAction Stop).tag_name.TrimStart('v') $currentVersion = [System.Version]::new($latest) - $nextVersion = [System.Version]::new($currentVersion.Major, $currentVersion.Minor, $currentVersion.Build + 1) + + # Determine if any components have major or minor version changes + $major = $false + $minor = $false + + foreach ($key in $current.Keys) { + if ($null -eq $next[$key]) { + continue + } + + $currentComponent = $current[$key] + $nextComponent = $next[$key] + + if ($nextComponent.Major -gt $currentComponent.Major) { + $major = $true + break + } + + if ($nextComponent.Minor -gt $currentComponent.Minor) { + $minor = $true + } + } + + # For major or minor changes, bump the minor version and reset the patch version. + # For any other changes, just bump the patch version. + if ($major -or $minor) { + $nextVersion = [System.Version]::new($currentVersion.Major, $currentVersion.Minor + 1, 0) + } + else { + $nextVersion = [System.Version]::new($currentVersion.Major, $currentVersion.Minor, $currentVersion.Build + 1) + } + + $nextVersion.ToString() } - $releaseVersion = $nextVersion.ToString() + $releaseVersion = Get-Next-LGTM-Version ${env:NEXT_VERSION} "version=${releaseVersion}" >> ${env:GITHUB_OUTPUT} - name: Create release From ad5b7f3cb0013843d9dd3768704aab107975748e Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Dec 2025 16:51:51 +0000 Subject: [PATCH 2/8] Create automated publishing schedule Create a workflow that would automatically create a new release every Friday at 0900 UTC. --- .github/workflows/scheduled-release.yml | 48 +++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 .github/workflows/scheduled-release.yml diff --git a/.github/workflows/scheduled-release.yml b/.github/workflows/scheduled-release.yml new file mode 100644 index 0000000..20b2876 --- /dev/null +++ b/.github/workflows/scheduled-release.yml @@ -0,0 +1,48 @@ +--- +name: Scheduled Release + +on: + #schedule: + # - cron: '0 9 * * FRI' + workflow_dispatch: + +permissions: {} + +jobs: + release: + runs-on: ubuntu-24.04 + timeout-minutes: 10 + + permissions: + contents: write + + steps: + - name: Checkout repository + uses: actions/checkout@1af3b93b6815bc44a9784bd300feb67ff0d1eeb3 # v6.0.0 + with: + fetch-depth: 0 + persist-credentials: false + + - name: Get changes since last release + id: get-changes + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + LATEST="$(gh api /repos/${GITHUB_REPOSITORY}/releases/latest --jq .tag_name)" + CHANGED_FILES="$(git diff --name-only "${LATEST}" -- docker || true)" + if [ -n "${CHANGED_FILES}" ]; then + echo "docker/ has changes since ${LATEST}" + echo "has-changes=true" >> "${GITHUB_OUTPUT}" + else + echo "docker/ has no changes since ${LATEST}" + echo "has-changes=false" >> "${GITHUB_OUTPUT}" + fi + + - name: Publish release + if: steps.get-changes.outputs.has-changes == 'true' + shell: bash + env: + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + echo '{"draft":false}' | gh workflow run publish-release.yml --json From fcd761077803c7e9ba28b706b3723d1b9044bc02 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Dec 2025 16:55:21 +0000 Subject: [PATCH 3/8] Default to draft true Default to creating a draft. --- .github/workflows/scheduled-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scheduled-release.yml b/.github/workflows/scheduled-release.yml index 20b2876..6dac4de 100644 --- a/.github/workflows/scheduled-release.yml +++ b/.github/workflows/scheduled-release.yml @@ -45,4 +45,4 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - echo '{"draft":false}' | gh workflow run publish-release.yml --json + echo '{"draft":true}' | gh workflow run publish-release.yml --json From b3022e363fd965f9bdcbc48c37aacafdc118e068 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Dec 2025 17:02:09 +0000 Subject: [PATCH 4/8] Simplify command Use `gh` to get the latest release. --- .github/workflows/publish-release.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index dcd8432..0caf3f1 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -82,12 +82,7 @@ jobs: $next = Get-Component-Versions "ghcr.io/grafana/docker-otel-lgtm:main" # Get the current release version from the latest GitHub release - $latestUrl = "${env:GITHUB_API_URL}/repos/${env:GITHUB_REPOSITORY}/releases/latest" - $headers = @{ - Authorization = "Bearer ${env:GH_TOKEN}"; - Accept = "application/vnd.github+json"; - } - $latest = (Invoke-RestMethod -Uri $latestUrl -Headers $headers -ErrorAction Stop).tag_name.TrimStart('v') + $latest = (gh api "/repos/${env:GITHUB_REPOSITORY}/releases/latest" --jq .tag_name).TrimStart('v') $currentVersion = [System.Version]::new($latest) # Determine if any components have major or minor version changes From 2ba71981ea0ec4221980bf52f7eecec12c6d0718 Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Dec 2025 17:03:39 +0000 Subject: [PATCH 5/8] Fix lint warning Quote string to resolve SC2086 warning. --- .github/workflows/scheduled-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/scheduled-release.yml b/.github/workflows/scheduled-release.yml index 6dac4de..cb9a8ba 100644 --- a/.github/workflows/scheduled-release.yml +++ b/.github/workflows/scheduled-release.yml @@ -29,7 +29,7 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - LATEST="$(gh api /repos/${GITHUB_REPOSITORY}/releases/latest --jq .tag_name)" + LATEST="$(gh api "/repos/${GITHUB_REPOSITORY}/releases/latest" --jq .tag_name)" CHANGED_FILES="$(git diff --name-only "${LATEST}" -- docker || true)" if [ -n "${CHANGED_FILES}" ]; then echo "docker/ has changes since ${LATEST}" From c81c9b2d1894ba55d15cf23293c8ef57741e841b Mon Sep 17 00:00:00 2001 From: martincostello Date: Tue, 2 Dec 2025 17:17:09 +0000 Subject: [PATCH 6/8] Resolve review comments - Treat added or removed components as a major change. - Pull docker images before inspecting. - Fix incorrect workflow permission. - Simplify `gh` syntax for workflow dispatch. --- .github/workflows/publish-release.yml | 9 +++++++++ .github/workflows/scheduled-release.yml | 4 ++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 0caf3f1..92d6ec4 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -48,6 +48,7 @@ jobs: function Get-Component-Versions { param([string]$Image) + docker pull $Image 2>&1 | Out-Null $vars = docker image inspect --format '{{json .Config.Env}}' $Image | ConvertFrom-Json $result = [ordered]@{} @@ -91,6 +92,14 @@ jobs: foreach ($key in $current.Keys) { if ($null -eq $next[$key]) { + # If we remove a component, consider it a major change + $major = $true + continue + } + + if ($null -eq $current[$key]) { + # If we add a component, consider it a major change + $major = $true continue } diff --git a/.github/workflows/scheduled-release.yml b/.github/workflows/scheduled-release.yml index cb9a8ba..a72c4d2 100644 --- a/.github/workflows/scheduled-release.yml +++ b/.github/workflows/scheduled-release.yml @@ -14,7 +14,7 @@ jobs: timeout-minutes: 10 permissions: - contents: write + actions: write steps: - name: Checkout repository @@ -45,4 +45,4 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | - echo '{"draft":true}' | gh workflow run publish-release.yml --json + gh workflow run publish-release.yml --field draft=true From c7c7ff854b4bf15a29857567873524097be8c6c4 Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 3 Dec 2025 12:06:28 +0000 Subject: [PATCH 7/8] Add function for version diff Move the version diff to a function so it can be more easily tested. --- .github/workflows/publish-release.yml | 60 ++++++++++++++++----------- 1 file changed, 36 insertions(+), 24 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 92d6ec4..7da1271 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -68,43 +68,32 @@ jobs: $result } - function Get-Next-LGTM-Version { - - param([string]$NextVersion) - - # Use the version as provided - if (-Not [string]::IsNullOrEmpty($NextVersion)) { - [System.Version]::new($NextVersion.TrimStart('v')).ToString() - return - } - - # Get the versions of the components in the latest release and the main branch - $current = Get-Component-Versions "docker.io/grafana/otel-lgtm:latest" - $next = Get-Component-Versions "ghcr.io/grafana/docker-otel-lgtm:main" - - # Get the current release version from the latest GitHub release - $latest = (gh api "/repos/${env:GITHUB_REPOSITORY}/releases/latest" --jq .tag_name).TrimStart('v') - $currentVersion = [System.Version]::new($latest) + function Get-Next-Version { + param( + [System.Version]$Version, + [hashtable]$Current, + [hashtable]$Next + ) # Determine if any components have major or minor version changes $major = $false $minor = $false - foreach ($key in $current.Keys) { - if ($null -eq $next[$key]) { + foreach ($key in $Current.Keys) { + if ($null -eq $Next[$key]) { # If we remove a component, consider it a major change $major = $true continue } - if ($null -eq $current[$key]) { + if ($null -eq $Current[$key]) { # If we add a component, consider it a major change $major = $true continue } - $currentComponent = $current[$key] - $nextComponent = $next[$key] + $currentComponent = $Current[$key] + $nextComponent = $Next[$key] if ($nextComponent.Major -gt $currentComponent.Major) { $major = $true @@ -119,15 +108,38 @@ jobs: # For major or minor changes, bump the minor version and reset the patch version. # For any other changes, just bump the patch version. if ($major -or $minor) { - $nextVersion = [System.Version]::new($currentVersion.Major, $currentVersion.Minor + 1, 0) + $nextVersion = [System.Version]::new($Version.Major, $Version.Minor + 1, 0) } else { - $nextVersion = [System.Version]::new($currentVersion.Major, $currentVersion.Minor, $currentVersion.Build + 1) + $nextVersion = [System.Version]::new($Version.Major, $Version.Minor, $Version.Build + 1) } $nextVersion.ToString() } + function Get-Next-LGTM-Version { + + param([string]$NextVersion) + + # Use the version as provided + if (-Not [string]::IsNullOrEmpty($NextVersion)) { + [System.Version]::new($NextVersion.TrimStart('v')).ToString() + return + } + + # Get the versions of the components in the latest release and the main branch + $current = Get-Component-Versions "docker.io/grafana/otel-lgtm:latest" + $next = Get-Component-Versions "ghcr.io/grafana/docker-otel-lgtm:main" + + # Get the current release version from the latest GitHub release + $latest = (gh api "/repos/${env:GITHUB_REPOSITORY}/releases/latest" --jq .tag_name).TrimStart('v') + $currentVersion = [System.Version]::new($latest) + + $nextVersion = Get-Next-Version $currentVersion $current $next + + $nextVersion.ToString() + } + $releaseVersion = Get-Next-LGTM-Version ${env:NEXT_VERSION} "version=${releaseVersion}" >> ${env:GITHUB_OUTPUT} From cd8afb8a15e824fdcca307441fb1842dde161c8b Mon Sep 17 00:00:00 2001 From: martincostello Date: Wed, 3 Dec 2025 12:13:48 +0000 Subject: [PATCH 8/8] Fix review comment Fix incorrect code to detect added components. --- .github/workflows/publish-release.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 7da1271..44612d1 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -86,12 +86,6 @@ jobs: continue } - if ($null -eq $Current[$key]) { - # If we add a component, consider it a major change - $major = $true - continue - } - $currentComponent = $Current[$key] $nextComponent = $Next[$key] @@ -105,6 +99,14 @@ jobs: } } + foreach ($key in $Next.Keys) { + if ($null -eq $Current[$key]) { + # If we add a component, consider it a major change + $major = $true + continue + } + } + # For major or minor changes, bump the minor version and reset the patch version. # For any other changes, just bump the patch version. if ($major -or $minor) {