-
Notifications
You must be signed in to change notification settings - Fork 7
Add automated releases #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add automated releases #1127
Changes from all commits
d14fe08
749c6f1
2e70e46
5bc3e78
c02f661
091bc75
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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" | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| $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}`); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| name: Scheduled Release | ||
|
|
||
| on: | ||
| schedule: | ||
| - cron: "0 9 * * FRI" | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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}" | ||
martincostello marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| echo "has-changes=false" >> "${GITHUB_OUTPUT}" | ||
| fi | ||
|
|
||
| - name: Publish release | ||
| if: steps.get-changes.outputs.has-changes == 'true' | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will trigger the workflow if any changes happen to
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we could also look at the output of |
||
| shell: bash | ||
| env: | ||
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| run: | | ||
| gh workflow run publish-release.yml --field draft=false | ||
| 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 |
Uh oh!
There was an error while loading. Please reload this page.