Files
grafana/.github/workflows/release-pr.yml
Kevin Minehart 4810e51743 CI: pin dagger version to match go.mod (#110638)
* pin dagger version to match go.mod

* set in e2e too
2025-09-05 00:28:27 +00:00

233 lines
8.3 KiB
YAML

# This workflow creates a new PR in Grafana which is triggered after a release is completed.
# It should include all code changes that are needed after a release is done. This includes the changelog update and
# version bumps, but could include more in the future.
# Please refrain from including any processes that do not result in code changes in this workflow. Instead, they should
# either be triggered in the release promotion process or in the release comms process (that is triggered by merging
# this PR).
name: Grafana Release PR
on:
workflow_dispatch:
inputs:
previous_version:
type: string
required: false
description: 'The release version (semver, git tag, branch or commit) to use for comparison'
version:
required: true
type: string
description: The version of Grafana that is being released (without the `v` prefix)`
target:
required: false
type: string
description: 'Unused: left here for backwards compatibility'
changelog:
required: false
type: boolean
default: true
bump:
required: false
type: boolean
default: true
dry_run:
required: false
default: false
type: boolean
latest:
required: false
default: false
type: boolean
release_date:
required: false
type: string
description: "Release date in format YYYY-MM-DD"
permissions:
contents: read
jobs:
capture-date:
runs-on: ubuntu-latest
outputs:
release_date: ${{ steps.set_release_date.outputs.release_date }}
steps:
- name: compute_release_date
run: |
if [ -n "$DATE" ]; then
echo "release_date=$DATE" >> "$GITHUB_ENV"
exit 0
fi
echo "Fetching workflow run creation date..."
created_at=$(gh run view "$GITHUB_RUN_ID" --repo "$GH_REPO" --json createdAt -q .createdAt)
formatted_date=$(date -d "$created_at" +%Y-%m-%d)
echo "release_date=$formatted_date" >> "$GITHUB_ENV"
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GH_REPO: ${{ github.repository }}
DATE: ${{ inputs.release_date }}
- id: set_release_date
run: echo "release_date=$release_date" >> "$GITHUB_OUTPUT"
push-changelog-to-main:
needs: capture-date
permissions:
contents: write
id-token: write
pull-requests: write
name: Create PR to main to update the changelog
uses: ./.github/workflows/changelog.yml
concurrency:
group: grafana-release-pr-update-changelog-main
cancel-in-progress: false
with:
previous_version: ${{inputs.previous_version}}
version: ${{ inputs.version }}
latest: ${{ inputs.latest }}
dry_run: ${{ inputs.dry_run }}
target: main
work_branch: changelog/update-changelog-${{ needs.capture-date.outputs.release_date }}
create-prs:
permissions:
contents: write
id-token: write
pull-requests: write
name: Create Release PR
runs-on: ubuntu-latest
if: github.repository == 'grafana/grafana'
env:
VERSION: ${{ inputs.version }}
LATEST: ${{ inputs.latest }}
DRY_RUN: ${{ inputs.dry_run }}
steps:
- name: "Get vault secrets"
id: vault-secrets
uses: grafana/shared-workflows/actions/get-vault-secrets@main
with:
repo_secrets: |
GRAFANA_DELIVERY_BOT_APP_PEM=delivery-bot-app:PRIVATE_KEY
- name: Generate token
id: generate_changelog_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a
with:
app_id: ${{ vars.DELIVERY_BOT_APP_ID }}
private_key: ${{ env.GRAFANA_DELIVERY_BOT_APP_PEM }}
repositories: "[\"grafana\", \"grafana-enterprise\"]"
permissions: "{\"contents\": \"write\", \"pull_requests\": \"write\", \"workflows\":\"write\"}"
- run: echo "RELEASE_BRANCH=release-${VERSION}" >> "$GITHUB_ENV"
- name: Checkout Grafana
uses: actions/checkout@v4
with:
token: ${{ steps.generate_changelog_token.outputs.token }}
ref: ${{ env.RELEASE_BRANCH }}
fetch-tags: true
fetch-depth: 0
- name: Checkout Grafana (main)
uses: actions/checkout@v4
with:
token: ${{ steps.generate_changelog_token.outputs.token }}
ref: main
fetch-depth: '0'
path: .grafana-main
- name: Setup nodejs environment
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
- uses: actions/setup-go@v5.5.0
with:
go-version-file: go.mod
- name: Configure git user
run: |
git config --local user.name "grafana-delivery-bot[bot]"
git config --local user.email "grafana-delivery-bot[bot]@users.noreply.github.com"
git config --local --add --bool push.autoSetupRemote true
- name: Create branch
run: git checkout -b "release/${{ github.run_number }}/$VERSION"
- name: Generate changelog
id: changelog
if: ${{ inputs.changelog == true || inputs.changelog == 'true' }}
uses: ./.grafana-main/.github/actions/changelog
with:
previous: ${{inputs.previous_version}}
github_token: ${{ steps.generate_changelog_token.outputs.token }}
target: v${{ env.VERSION }}
output_file: changelog_items.md
- name: Patch CHANGELOG.md
if: ${{ inputs.changelog == true || inputs.changelog == 'true' }}
run: |
# Prepare CHANGELOG.md content with version delimiters
(
echo
echo "# $VERSION ($(date '+%F'))"
echo
cat changelog_items.md
) > CHANGELOG.part
# Check if a version exists in the changelog
if grep -q "<!-- $VERSION START" CHANGELOG.md ; then
# Replace the content between START and END delimiters
echo "Version $VERSION is found in the CHANGELOG.md, patching contents..."
sed -i -e "/$VERSION START/,/$VERSION END/{//!d;}" \
-e "/$VERSION START/r CHANGELOG.part" CHANGELOG.md
else
# Prepend changelog part to the main changelog file
echo "Version $VERSION not found in the CHANGELOG.md"
(
echo "<!-- $VERSION START -->"
cat CHANGELOG.part
echo "<!-- $VERSION END -->"
cat CHANGELOG.md
) > CHANGELOG.tmp
mv CHANGELOG.tmp CHANGELOG.md
fi
rm -f CHANGELOG.part changelog_items.md
git diff CHANGELOG.md
- name: "Prettify CHANGELOG.md"
if: ${{ inputs.changelog == true || inputs.changelog == 'true' }}
run: npx prettier --write CHANGELOG.md
- name: Commit CHANGELOG.md changes
if: ${{ inputs.changelog == true || inputs.changelog == 'true' }}
run: git add CHANGELOG.md && git commit --allow-empty -m "Update changelog" CHANGELOG.md
- name: Bump versions
if: ${{ inputs.bump == true || inputs.bump == 'true' }}
uses: dagger/dagger-for-github@e47aba410ef9bb9ed81a4d2a97df31061e5e842e
with:
version: 0.18.8
verb: run
args: go run -C .grafana-main ./pkg/build/actions/bump-version -version="patch"
- name: make gen-cue
shell: bash
run: make gen-cue
- name: Add package.json changes
if: ${{ inputs.bump == true || inputs.bump == 'true' }}
run: |
git add package.json lerna.json yarn.lock packages public
test -e e2e-playwright/test-plugins && git add e2e-playwright/test-plugins
git commit -m "Update version to $VERSION"
- name: Git push
run: git push
- name: Create PR
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DRY_RUN: ${{ inputs.dry_run }}
run: |
LATEST_FLAG=()
if [ "$LATEST" = "true" ]; then
LATEST_FLAG=(-l "release/latest")
fi
gh pr create \
"${LATEST_FLAG[@]}" \
-l "no-changelog" \
--dry-run="$DRY_RUN" \
-B "${RELEASE_BRANCH}" \
--title "Release: $VERSION" \
--body "These code changes must be merged after a release is complete"