---
name: "Gemini Release Drafter"
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
current_tag:
description: 'The new tag to create the release for (e.g., v1.1.0)'
required: true
previous_tag:
description: 'The old tag to start the changelog from (e.g., v1.0.0)'
required: true
concurrency:
group: '${{ github.workflow }}-invoke-${{ github.event_name }}-${{ github.event.pull_request.number || github.event.issue.number }}'
cancel-in-progress: false
jobs:
draft_release:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write # Added for identity token minting
issues: write # Added for identity token minting
pull-requests: write # Added for identity token minting
steps:
# Step 1: Check out the repository's code.
# `fetch-depth: 0` is crucial as it fetches the entire git history,
# which is needed to compare tags and get commit logs.
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
- name: 'Mint identity token'
id: 'mint_identity_token'
if: |-
${{ vars.APP_ID }}
uses: 'actions/create-github-app-token@a8d616148505b5069dccd32f177bb87d7f39123b' # ratchet:actions/create-github-app-token@v2
with:
app-id: '${{ vars.APP_ID }}'
private-key: '${{ secrets.APP_PRIVATE_KEY }}'
permission-contents: 'read'
permission-issues: 'write'
permission-pull-requests: 'write'
- name: Determine Tags
id: determine_tags
run: |
CURRENT_TAG="${{ github.event.inputs.current_tag || github.ref_name }}"
PREVIOUS_TAG="${{ github.event.inputs.previous_tag }}"
if [ -z "$PREVIOUS_TAG" ]; then
# If previous_tag input is not provided, try to find it using git describe
# This is for push:tags or when workflow_dispatch doesn't provide previous_tag
PREVIOUS_TAG=$(git describe --tags --abbrev=0 "$CURRENT_TAG^" 2>/dev/null || echo "")
fi
echo "current_tag=$CURRENT_TAG" >> $GITHUB_OUTPUT
echo "previous_tag=$PREVIOUS_TAG" >> $GITHUB_OUTPUT
- name: Get commit log
id: gitlog
run: |
CURRENT_TAG="${{ steps.determine_tags.outputs.current_tag }}"
PREVIOUS_TAG="${{ steps.determine_tags.outputs.previous_tag }}"
if [ -z "$PREVIOUS_TAG" ]; then
log=$(git log "$CURRENT_TAG" --pretty=format:'- %s')
else
log=$(git log "$PREVIOUS_TAG"...$CURRENT_TAG --pretty=format:'- %s')
fi
echo "log<<EOF" >> $GITHUB_OUTPUT
echo "$log" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
# Step 4: Generate release notes using the official Gemini CLI action.
# This action handles the installation and execution of the Gemini CLI.
- name: "Generate release notes with Gemini"
id: 'run_gemini' # Changed id to 'run_gemini'
uses: 'google-github-actions/run-gemini-cli@v0' # ratchet:exclude
env:
TITLE: '${{ github.event.pull_request.title || github.event.issue.title }}'
DESCRIPTION: '${{ github.event.pull_request.body || github.event.issue.body }}'
EVENT_NAME: '${{ github.event_name }}'
GITHUB_TOKEN: '${{ steps.mint_identity_token.outputs.token || secrets.GITHUB_TOKEN || github.token }}'
IS_PULL_REQUEST: '${{ !!github.event.pull_request }}'
ISSUE_NUMBER: '${{ github.event.pull_request.number || github.event.issue.number }}'
REPOSITORY: '${{ github.repository }}'
ADDITIONAL_CONTEXT: '${{ inputs.additional_context }}'
with:
gemini_api_key: '${{ secrets.GEMINI_API_KEY }}'
gcp_workload_identity_provider: '${{ vars.GCP_WIF_PROVIDER }}'
gcp_project_id: '${{ vars.GOOGLE_CLOUD_PROJECT }}'
gcp_location: '${{ vars.GOOGLE_CLOUD_LOCATION }}'
gcp_service_account: '${{ vars.SERVICE_ACCOUNT_EMAIL }}'
use_vertex_ai: '${{ vars.GOOGLE_GENAI_USE_VERTEXAI }}'
use_gemini_code_assist: '${{ vars.GOOGLE_GENAI_USE_GCA }}'
settings: |-
{
"maxSessionTurns": 25,
"telemetry": {
"enabled": ${{ vars.GOOGLE_CLOUD_PROJECT != '' }},
"target": "gcp"
},
"mcpServers": {
"github": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-e",
"GITHUB_PERSONAL_ACCESS_TOKEN",
"ghcr.io/github/github-mcp-server"
],
"includeTools": [
"add_issue_comment",
"get_issue",
"get_issue_comments",
"list_issues",
"search_issues",
"create_pull_request",
"get_pull_request",
"get_pull_request_comments",
"get_pull_request_diff",
"get_pull_request_files",
"list_pull_requests",
"search_pull_requests",
"create_branch",
"create_or_update_file",
"delete_file",
"fork_repository",
"get_commit",
"get_file_contents",
"list_commits",
"push_files",
"search_code"
],
"env": {
"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"
}
}
},
"coreTools": [
"run_shell_command(cat)",
"run_shell_command(echo)",
"run_shell_command(grep)",
"run_shell_command(head)",
"run_shell_command(tail)"
]
}
prompt: |
Please act as a release notes author. Based on the following git commit messages, create a summary for a software release. The output should be in markdown format. Group the changes into logical sections like '✨ New Features', '🐛 Bug Fixes', and '🔨 Other Changes'. The commit messages are:
${{ steps.gitlog.outputs.log }}
# Step 5: Create the draft release on GitHub.
# This uses the official GitHub action to create a release,
# using the notes generated by Gemini as the body.
- name: "Create Draft Release"
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref_name }}
release_name: Release ${{ github.ref_name }}
body: ${{ steps.run_gemini.outputs.summary }} # Changed from steps.gemini.outputs.result
draft: true
prerelease: false