diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml new file mode 100644 index 00000000..a2f19eb1 --- /dev/null +++ b/.github/workflows/publish-release.yml @@ -0,0 +1,89 @@ +--- +name: Publish Release + +on: + workflow_dispatch: + inputs: + draft: + description: "If true, creates the release as a draft." + required: false + type: boolean + default: false + version: + description: "The optional version number to use for the release." + required: false + type: string + default: "" + +permissions: {} + +jobs: + release: + runs-on: [ubuntu-latest] + + 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: Get 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 { + $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') + $currentVersion = [System.Version]::new($latest) + $nextVersion = [System.Version]::new($currentVersion.Major, $currentVersion.Minor, $currentVersion.Build + 1) + } + + $releaseVersion = $nextVersion.ToString() + "version=${releaseVersion}" >> ${env:GITHUB_OUTPUT} + + - name: Create release + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + 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}`); diff --git a/RELEASING.md b/RELEASING.md index da2e137e..5b7b73a6 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -1,7 +1,18 @@ # Releasing -1. Go to -2. Click on "Choose a tag", enter the tag name (e.g. `v0.1.0`), and click "Create a new tag". -3. Click on "Generate release notes" to auto-generate the release notes based on - the commits since the last release. -4. Click on "Publish release". +1. Open the [Publish Release workflow][publish-release] +2. Click on the **Run workflow** button +3. If required, enter a specific version number (e.g. `1.2.3`) in the version field. If left + blank, the version will be auto-incremented to the next patch version based on the + [latest release][latest-release]. +4. Wait for the workflow to complete successfully. +5. Click the link in the workflow run summary to the untagged release created by the workflow. +6. Click the edit button (pencil icon) at the top right of the release notes. +7. Verify that the release notes are correct. Make any manual adjustments if necessary. +8. Click on **Publish release**. + + + + +[latest-release]: https://github.com/grafana/docker-otel-lgtm/releases/latest +[publish-release]: https://github.com/grafana/docker-otel-lgtm/actions/workflows/publish-release.yml