|
| 1 | +name: 'Generate Release Info' |
| 2 | +description: 'Generate version number and release notes using AI' |
| 3 | + |
| 4 | +inputs: |
| 5 | + service-name: |
| 6 | + description: 'The name of the service (used in release notes)' |
| 7 | + required: true |
| 8 | + prerelease: |
| 9 | + description: 'Whether this is a prerelease (appends -rc.N suffix)' |
| 10 | + required: false |
| 11 | + default: false |
| 12 | + openai-api-key: |
| 13 | + description: 'OpenAI API key for AI-powered version detection and notes' |
| 14 | + required: true |
| 15 | + |
| 16 | +outputs: |
| 17 | + version: |
| 18 | + description: 'The determined version (e.g., 1.2.3 or 1.2.3-rc.5)' |
| 19 | + value: ${{ steps.version.outputs.final }} |
| 20 | + release_notes: |
| 21 | + description: 'AI-generated release notes in markdown' |
| 22 | + value: ${{ steps.ai-notes.outputs.final-message }} |
| 23 | + |
| 24 | +runs: |
| 25 | + using: 'composite' |
| 26 | + steps: |
| 27 | + - name: Get last release info |
| 28 | + id: last-release |
| 29 | + uses: actions/github-script@v7 |
| 30 | + with: |
| 31 | + script: | |
| 32 | + try { |
| 33 | + const { data: releases } = await github.rest.repos.listReleases({ |
| 34 | + owner: context.repo.owner, |
| 35 | + repo: context.repo.repo, |
| 36 | + per_page: 1 |
| 37 | + }); |
| 38 | + |
| 39 | + if (releases.length > 0) { |
| 40 | + const tagName = releases[0].tag_name; |
| 41 | + const { data: ref } = await github.rest.git.getRef({ |
| 42 | + owner: context.repo.owner, |
| 43 | + repo: context.repo.repo, |
| 44 | + ref: `tags/${tagName}` |
| 45 | + }); |
| 46 | + core.setOutput('sha', ref.object.sha); |
| 47 | + core.setOutput('version', tagName.replace(/^v/, '')); |
| 48 | + } else { |
| 49 | + const allCommits = await github.paginate(github.rest.repos.listCommits, { |
| 50 | + owner: context.repo.owner, |
| 51 | + repo: context.repo.repo, |
| 52 | + per_page: 100 |
| 53 | + }); |
| 54 | + core.setOutput('sha', allCommits[allCommits.length - 1].sha); |
| 55 | + core.setOutput('version', '0.0.0'); |
| 56 | + } |
| 57 | + } catch (error) { |
| 58 | + core.setOutput('sha', context.sha); |
| 59 | + core.setOutput('version', '0.0.0'); |
| 60 | + } |
| 61 | +
|
| 62 | + - name: AI Determine Version |
| 63 | + id: ai-version |
| 64 | + uses: openai/codex-action@v1 |
| 65 | + with: |
| 66 | + openai-api-key: ${{ inputs.openai-api-key }} |
| 67 | + safety-strategy: read-only |
| 68 | + prompt: | |
| 69 | + Analyze commits between ${{ steps.last-release.outputs.sha }} and ${{ github.sha }}. |
| 70 | + Current version: ${{ steps.last-release.outputs.version }} |
| 71 | + Prerelease: ${{ inputs.prerelease }} |
| 72 | + |
| 73 | + Rules: |
| 74 | + - BREAKING CHANGE or ! = major bump |
| 75 | + - feat: = minor bump |
| 76 | + - fix:, perf:, or other = patch bump |
| 77 | + - Default to patch if unclear |
| 78 | + - For prereleases: use same version logic, suffix will be added automatically |
| 79 | + |
| 80 | + Respond with ONLY X.Y.Z |
| 81 | +
|
| 82 | + - name: Parse Version |
| 83 | + id: version |
| 84 | + shell: bash |
| 85 | + run: | |
| 86 | + NEXT=$(echo "${{ steps.ai-version.outputs.final-message }}" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' | head -1) |
| 87 | + [ -z "$NEXT" ] && { echo "::error::Invalid version"; exit 1; } |
| 88 | + |
| 89 | + if [ "${{ inputs.prerelease }}" == "true" ]; then |
| 90 | + echo "final=${NEXT}-rc.${GITHUB_RUN_NUMBER}" >> $GITHUB_OUTPUT |
| 91 | + else |
| 92 | + echo "final=${NEXT}" >> $GITHUB_OUTPUT |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: AI Generate Notes |
| 96 | + id: ai-notes |
| 97 | + uses: openai/codex-action@v1 |
| 98 | + with: |
| 99 | + prompt: | |
| 100 | + Generate release notes for ${{ inputs.service-name }} v${{ steps.version.outputs.final }}. |
| 101 | + Changes from ${{ steps.last-release.outputs.sha }} to ${{ github.sha }}. |
| 102 | + |
| 103 | + REQUIREMENTS: |
| 104 | + 1. NO title - start with content directly |
| 105 | + 2. Plain language - like explaining to a friend |
| 106 | + 3. SHORT - 1-2 sentences per item |
| 107 | + 4. Group: ## New Features, ## Bug Fixes, ## Improvement, if they exist. For example, |
| 108 | + if there are no new features, bug fixes, or improvements, don't include them. |
| 109 | + 5. Only include breaking changes if they exist |
| 110 | + 6. Include commit SHAs if necessary. If the commit is large, don't include it. |
| 111 | + 7. 1-2 emojis max for personality |
| 112 | + 8. Code diffs ONLY if necessary. If the diff is large, don't include it. |
| 113 | + |
| 114 | + The end goal is clear business technical writing that is easy to understand, use, and bring |
| 115 | + delight to the user |
0 commit comments