Skip to content

Publish Release

Publish Release #11

---
name: Publish Release
on:
workflow_dispatch:
inputs:
branch:
description: "The branch to create the release from"
required: false
type: string
default: ""
version:
description: "The version to tag the release as"
required: false
type: string
default: ""
permissions: {}
jobs:
release:
runs-on: ubuntu-24.04
timeout-minutes: 10
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
contents: read
id-token: write
steps:
- name: Get GitHub token
id: get-token
uses: grafana/shared-workflows/actions/create-github-app-token@ae92934a14a48b94494dbc06d74a81d47fe08a40 # v0.2.2
with:
github_app: grafana-otel-bot
permission_set: default
- name: Determine next version
id: get-version
shell: pwsh
env:
GH_TOKEN: ${{ steps.get-token.outputs.token }}
NEXT_VERSION: ${{ inputs.version }}
run: |
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
# Get the Java instrumentation version from the specified Git reference
function Get-Instrumentation-Version {
param([string]$Reference)
$url = "https://raw.githubusercontent.com/${env:GITHUB_REPOSITORY}/${Reference}/build.gradle"
$gradle = (Invoke-WebRequest -Uri $url -UseBasicParsing).Content
$OTelVersion = 'otelInstrumentationVersion\s*=\s*["''](?<version>[^"'']+)["'']'
$match = [regex]::Match($gradle, $OTelVersion)
if (-Not $match.Success) {
throw "Failed to determine OpenTelemetry instrumentation version from $Reference"
}
$version = $match.Groups['version'].Value
if ([string]::IsNullOrEmpty($version)) {
throw "Failed to get OpenTelemetry instrumentation version from $Reference"
}
$version
}
function Get-Next-Distro-Version {
param([string]$NextVersion)
# Use the version as provided
if (-Not [string]::IsNullOrEmpty($NextVersion)) {
[System.Version]::new($NextVersion.TrimStart('v')).ToString()
return
}
# Get the version from the current branch
$current = Get-Instrumentation-Version ${env:GITHUB_REF_NAME}
$currentVersion = [System.Version]::new($current)
# Get the current release version from the latest GitHub release
$latest = (gh api "/repos/${env:GITHUB_REPOSITORY}/releases/latest" --jq .tag_name).TrimStart('v')
if ($LASTEXITCODE -ne 0) {
throw "Failed to get latest release version"
}
$latestVersion = [System.Version]::new($latest)
if ($currentVersion -gt $latestVersion) {
# There are changes to release
$currentVersion.ToString()
} else {
# No changes to release
""
}
}
$releaseVersion = Get-Next-Distro-Version ${env:NEXT_VERSION}
"version=${releaseVersion}" >> ${env:GITHUB_OUTPUT}
- name: Checkout code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
if: steps.get-version.outputs.version != ''
with:
fetch-depth: 0
persist-credentials: true # zizmor: ignore[artipacked] Needed to push commits
ref: ${{ github.event.inputs.branch || github.event.repository.default_branch }}
show-progress: false
token: ${{ steps.get-token.outputs.token }}
- name: Configure Git
shell: bash
if: steps.get-version.outputs.version != ''
env:
GH_APP_NAME: grafana-otel-bot
GH_TOKEN: ${{ steps.get-token.outputs.token }}
run: |
GIT_COMMIT_USER_NAME="${GH_APP_NAME}[bot]"
GIT_COMMIT_USER_EMAIL="$(gh api "/users/${GIT_COMMIT_USER_NAME}" --jq ".id")+${GIT_COMMIT_USER_NAME}@users.noreply.github.com"
git config user.email "${GIT_COMMIT_USER_EMAIL}"
git config user.name "${GIT_COMMIT_USER_NAME}"
- name: Create and push release tag
shell: bash
if: steps.get-version.outputs.version != ''
env:
TAG: "v${{ steps.get-version.outputs.version }}"
run: |
git tag "${TAG}" -m "Release ${TAG}" && git push origin "refs/tags/$TAG"