Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
135 changes: 135 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
---
name: Publish Release

on:
workflow_dispatch:
inputs:
draft:
description: "If true, creates the release as a draft."
required: false
type: boolean
default: true
version:
description: "The optional version number to use for the release."
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: Create release
uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
if: steps.get-version.outputs.version != ''
env:
DEFAULT_BRANCH: ${{ github.event.repository.default_branch }}
DRAFT: ${{ inputs.draft == true }}
VERSION: ${{ steps.get-version.outputs.version }}
with:
github-token: ${{ steps.get-token.outputs.token }}
script: |
const { repo, owner } = context.repo;
const draft = process.env.DRAFT === 'true';
const version = process.env.VERSION;
const tag_name = `v${version}`;
const target_commitish = process.env.DEFAULT_BRANCH;
const name = tag_name;

const { data: release } = await github.rest.repos.createRelease({
owner,
repo,
tag_name,
target_commitish,
name,
draft,
generate_release_notes: true,
});

core.notice(`Created release ${release.name}: ${release.html_url}`);
21 changes: 17 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,37 +5,50 @@ on:
tags:
- "v*.*.*"

permissions:
contents: write
id-token: write
permissions: {}

jobs:
release:
runs-on: ubuntu-24.04
timeout-minutes: 10

concurrency:
group: "${{ github.workflow }}-${{ github.sha }}"
cancel-in-progress: false

permissions:
contents: write
id-token: write

steps:
- name: Check out
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
with:
persist-credentials: false
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1

- name: Set up JDK
uses: actions/setup-java@dded0888837ed1f317902acf8a20df0ad188d165 # v5.0.0
with:
java-version: 17
distribution: temurin

- name: Setup Gradle and run build
uses: gradle/actions/setup-gradle@4d9f0ba0025fe599b4ebab900eb7f3a1d93ef4c2 # v5.0.0
with:
cache-disabled: "true"

- name: Build
run: ./scripts/build-release.sh
env:
TAG: ${{ github.ref_name }}

- name: Release
uses: softprops/action-gh-release@a06a81a03ee405af7f2048a818ed3f03bbf83c7b # v2.5.0
with:
files: |
agent/build/libs/grafana-opentelemetry-java.jar
LICENSE

- name: Push to Docker (for OpenTelemetry Operator)
uses: grafana/shared-workflows/actions/push-to-gar-docker@dc66ed7a5dc1f49848b06068ae024e96e26d4761 # push-to-gar-docker/v0.5.2
with:
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/scheduled-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
name: Scheduled Release

on:
schedule:
- cron: "0 9 * * FRI"
workflow_dispatch:

permissions: {}

jobs:
release:
if: github.event.repository.fork == false
runs-on: ubuntu-24.04
timeout-minutes: 10

concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

permissions:
actions: write

steps:
- name: Checkout repository
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
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)"

SOURCE_PATHS=("build.gradle")
CHANGED_FILES="$(git diff --name-only "${LATEST}" -- "${SOURCE_PATHS[@]}" || true)"

if [ -n "${CHANGED_FILES}" ]; then
echo "Repository has changes since ${LATEST}"
echo "has-changes=true" >> "${GITHUB_OUTPUT}"
else
echo "Repository has no changes since ${LATEST}"
echo "has-changes=false" >> "${GITHUB_OUTPUT}"
fi

- name: Publish release
if: steps.get-changes.outputs.has-changes == 'true'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will trigger the workflow if any changes happen to build.gradle, but the other workflow will no-op if there's no actual relevant changes.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could move the logic from the other workflow to this one to avoid that if desired.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could also look at the output of git diff here - but I'm not sure what's best

shell: bash
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh workflow run publish-release.yml --field draft=false
52 changes: 41 additions & 11 deletions RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
# Releasing

1. Go to <https://github.com/grafana/grafana-opentelemetry-java/releases/new>
2. Click on "Choose a tag", enter the tag name (e.g. `v0.1.0`), and click "Create a new tag".
The version number should be the same as the
[upstream version](https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases) that we are using.
Bugfix releases should be `v2.3.4.1`, where `2.3.4` is the upstream version.
3. Click on "Generate release notes" to auto-generate the release notes based on the commits since the last release.
- Exclude the commits that are not relevant for the release notes, such as "Update dependencies".
- Usually, it's just updating the upstream version.
- Include a link to the upstream release notes, e.g. "Update to [OpenTelemetry 2.9.0](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/CHANGELOG.md#version-290-2024-10-17)".
4. Click on "Publish release".
5. The actual release is done by GitHub Actions, which will build the distribution and upload it to the release.
> [!IMPORTANT]
> Releases are [immutable][immutable-releases] and cannot be changed or their associated tag
> deleted once published.
>
> However, the description can still be edited to fix any mistakes or omissions after publishing.

## Scheduled Releases

Releases are automatically published on a weekly basis via a
[scheduled GitHub Actions workflow][scheduled-release]. The workflow runs every Friday at 09:00 UTC
and will publish a new release if any changes have been made to the
[`otelInstrumentationVersion` variable][otel-java-instrumentation-version] which tracks the latest
version of the [OpenTelemetry Instrumentation for Java][otel-java-instrumentation-latest] since the
[latest release][latest-release] of the Grafana Java distribution for OpenTelemetry.

The release version will match the version specified by the `otelInstrumentationVersion` variable.

## Manual Releases

1. Open the [Publish Release workflow][publish-release]
1. Click on the **Run workflow** button
1. If required, enter a specific version number (e.g. `x.y.z`) in the version field. If left
blank, the version will track the version in [`otelInstrumentationVersion`][otel-java-instrumentation-version].
Bugfix releases should be `x.y.z.1`, where `x.y.z` is the upstream version.
1. Wait for the workflow to complete successfully.
1. Click the link in the workflow run summary to the untagged release created by the workflow.
1. Click the edit button (pencil icon) at the top right of the release notes.
1. Verify that the release notes are correct. Make any manual adjustments if necessary.
- Include a link to the upstream release notes,
e.g. _"Update to [OpenTelemetry 2.9.0](https://github.com/open-telemetry/opentelemetry-java-instrumentation/blob/main/CHANGELOG.md#version-290-2024-10-17)"_.
1. Click on **Publish release**.

<!-- editorconfig-checker-disable -->
<!-- markdownlint-disable MD013 -->

[immutable-releases]: https://docs.github.com/code-security/supply-chain-security/understanding-your-software-supply-chain/immutable-releases
[otel-java-instrumentation-latest]: https://github.com/open-telemetry/opentelemetry-java-instrumentation/releases/latest
[otel-java-instrumentation-version]: https://github.com/grafana/grafana-opentelemetry-java/blob/main/build.gradle#L6
[latest-release]: https://github.com/grafana/grafana-opentelemetry-java/releases/latest
[publish-release]: https://github.com/grafana/grafana-opentelemetry-java/actions/workflows/publish-release.yml
[scheduled-release]: https://github.com/grafana/grafana-opentelemetry-java/blob/main/.github/workflows/scheduled-release.yml
Loading