|
| 1 | +name: Github Release |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + tag: |
| 6 | + description: "Release tag (e.g., v1.2.3)" |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + |
| 10 | +permissions: |
| 11 | + contents: write |
| 12 | + id-token: write |
| 13 | + |
| 14 | +jobs: |
| 15 | + create-draft-release: |
| 16 | + name: Create Draft Release |
| 17 | + runs-on: ubuntu-latest |
| 18 | + steps: |
| 19 | + - name: Validate semver tag |
| 20 | + run: | |
| 21 | + TAG="${{ github.event.inputs.tag }}" |
| 22 | +
|
| 23 | + # Check if tag matches semver pattern (v followed by MAJOR.MINOR.PATCH with optional pre-release and build metadata) |
| 24 | + # Supports: v1.2.3, v1.2.3-rc.4, v1.2.3-beta.1, v1.2.3-alpha.1+build.123 |
| 25 | + if ! echo "$TAG" | grep -qE '^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$'; then |
| 26 | + echo "::error::Invalid tag format: $TAG" |
| 27 | + echo "::error::Tag must be in semver format: v<MAJOR>.<MINOR>.<PATCH>[-PRERELEASE][+BUILD]" |
| 28 | + echo "::error::Examples: v1.2.3, v1.2.3-rc.4, v1.2.3-beta.1, v1.2.3-alpha.1+build.123" |
| 29 | + exit 1 |
| 30 | + fi |
| 31 | +
|
| 32 | + echo "::notice::Tag validation passed: $TAG" |
| 33 | +
|
| 34 | + - name: Checkout code |
| 35 | + uses: actions/checkout@v6 |
| 36 | + with: |
| 37 | + fetch-depth: 0 |
| 38 | + |
| 39 | + - name: Extract version from tag |
| 40 | + id: extract-version |
| 41 | + run: | |
| 42 | + TAG="${{ github.event.inputs.tag }}" |
| 43 | + VERSION="${TAG#v}" |
| 44 | + echo "tag=$TAG" >> $GITHUB_OUTPUT |
| 45 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 46 | + echo "::notice::Tag: $TAG" |
| 47 | + echo "::notice::Version: $VERSION" |
| 48 | +
|
| 49 | + - name: Find previous tag |
| 50 | + id: prev-tag |
| 51 | + run: | |
| 52 | + TAG="${{ steps.extract-version.outputs.tag }}" |
| 53 | + PREV_TAG=$(git tag -l "v*.*.*" --sort=-version:refname | grep -v "^${TAG}$" | head -n1) |
| 54 | +
|
| 55 | + if [ -z "$PREV_TAG" ]; then |
| 56 | + echo "::notice::No previous tag found, using initial commit" |
| 57 | + PREV_TAG=$(git rev-list --max-parents=0 HEAD) |
| 58 | + fi |
| 59 | +
|
| 60 | + echo "prev-tag=$PREV_TAG" >> $GITHUB_OUTPUT |
| 61 | + echo "::notice::Previous tag: $PREV_TAG" |
| 62 | +
|
| 63 | + - name: Get list of Docker images |
| 64 | + id: get-images |
| 65 | + run: | |
| 66 | + # Find all apps with Dockerfiles |
| 67 | + IMAGES="" |
| 68 | + for app_dir in apps/*/; do |
| 69 | + if [ -f "${app_dir}Dockerfile" ]; then |
| 70 | + APP_NAME=$(basename "$app_dir") |
| 71 | + IMAGE_NAME="ev-node-${APP_NAME}" |
| 72 | + IMAGES="${IMAGES}ghcr.io/${{ github.repository_owner }}/${IMAGE_NAME}:${{ steps.extract-version.outputs.tag }}\n" |
| 73 | + fi |
| 74 | + done |
| 75 | +
|
| 76 | + # Remove trailing newline |
| 77 | + IMAGES=$(echo -e "$IMAGES" | sed '/^$/d') |
| 78 | +
|
| 79 | + # Escape for GitHub Actions output |
| 80 | + IMAGES="${IMAGES//'%'/'%25'}" |
| 81 | + IMAGES="${IMAGES//$'\n'/'%0A'}" |
| 82 | + IMAGES="${IMAGES//$'\r'/'%0D'}" |
| 83 | +
|
| 84 | + echo "images=$IMAGES" >> $GITHUB_OUTPUT |
| 85 | + echo "::notice::Found Docker images" |
| 86 | +
|
| 87 | + - name: Generate changelog prompt |
| 88 | + id: changelog-prompt |
| 89 | + run: | |
| 90 | + PREV_TAG="${{ steps.prev-tag.outputs.prev-tag }}" |
| 91 | + TAG="${{ steps.extract-version.outputs.tag }}" |
| 92 | + VERSION="${{ steps.extract-version.outputs.version }}" |
| 93 | +
|
| 94 | + cat > claude-prompt.txt << 'EOF_PROMPT' |
| 95 | + Read the file CHANGELOG.md and find the section for version $VERSION (tag $TAG). |
| 96 | +
|
| 97 | + Generate professional release notes for GitHub based on the changes listed for this specific version. |
| 98 | +
|
| 99 | + Create release notes with the following structure: |
| 100 | +
|
| 101 | + ev-node VERSION |
| 102 | +
|
| 103 | + ⚠️ This is a draft release. Please verify its content before publishing |
| 104 | +
|
| 105 | + [Brief summary paragraph about this release - what type of release it is (feature/bugfix/maintenance), upgrade recommendations] |
| 106 | +
|
| 107 | + **Tested upgrade paths** |
| 108 | + - [List version upgrade paths that were tested, or state "TBD - to be tested before publishing"] |
| 109 | +
|
| 110 | + ## ⚠️ Breaking Changes |
| 111 | +
|
| 112 | + [If there are breaking changes, list each one with clear operational steps. If no breaking changes, state "None"] |
| 113 | +
|
| 114 | + ### [Breaking Change Title] |
| 115 | + **What changed:** [Clear description of what was changed/added/removed] |
| 116 | +
|
| 117 | + **Action required:** |
| 118 | + 1. [Step-by-step instructions on what operators need to do] |
| 119 | + 2. [Include configuration changes, file modifications, etc.] |
| 120 | + 3. [Provide examples where helpful] |
| 121 | +
|
| 122 | + **Reference:** [PR number if available] |
| 123 | +
|
| 124 | + --- |
| 125 | +
|
| 126 | + ## Full Changelog |
| 127 | +
|
| 128 | + For a complete list of all changes including new features, improvements, and bug fixes, see [CHANGELOG.md](https://github.com/${{ github.repository }}/blob/$TAG/CHANGELOG.md#$VERSION). |
| 129 | +
|
| 130 | + **Images** |
| 131 | + EOF_PROMPT |
| 132 | +
|
| 133 | + # Replace placeholders with actual values |
| 134 | + sed -i "s/\$VERSION/${VERSION}/g" claude-prompt.txt |
| 135 | + sed -i "s/\$TAG/${TAG}/g" claude-prompt.txt |
| 136 | +
|
| 137 | + # Add the images list |
| 138 | + echo "${{ steps.get-images.outputs.images }}" | while IFS= read -r image; do |
| 139 | + echo "- $image" >> claude-prompt.txt |
| 140 | + done |
| 141 | +
|
| 142 | + cat >> claude-prompt.txt << 'EOF_PROMPT' |
| 143 | +
|
| 144 | + Guidelines: |
| 145 | + - Replace VERSION with the actual version number |
| 146 | + - Replace YYYY-MM-DD with the actual release date |
| 147 | + - ONLY include BREAKING changes in the "Breaking Changes" section |
| 148 | + - For each breaking change, provide clear operational steps that operators must follow |
| 149 | + - Include specific configuration file changes, command modifications, or migration steps |
| 150 | + - Use numbered lists for action steps to make them easy to follow |
| 151 | + - Do NOT duplicate the full changelog content - just reference CHANGELOG.md |
| 152 | + - If there are no breaking changes, clearly state "None" in that section |
| 153 | + - Use clear, professional language focused on operational impact |
| 154 | + - Include PR numbers for breaking changes when available |
| 155 | + - Format as clean markdown |
| 156 | +
|
| 157 | + Output the release notes as your response. |
| 158 | + EOF_PROMPT |
| 159 | +
|
| 160 | + { |
| 161 | + echo 'prompt<<EOF_CLAUDE_PROMPT' |
| 162 | + cat claude-prompt.txt |
| 163 | + echo EOF_CLAUDE_PROMPT |
| 164 | + } >> $GITHUB_OUTPUT |
| 165 | +
|
| 166 | + - name: Generate release notes with Claude |
| 167 | + id: claude-release |
| 168 | + uses: anthropics/claude-code-action@v1 |
| 169 | + with: |
| 170 | + claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }} |
| 171 | + prompt: ${{ steps.changelog-prompt.outputs.prompt }} |
| 172 | + trusted_bots: "*" |
| 173 | + allowed_tools: "Read(CHANGELOG.md)" |
| 174 | + claude_args: | |
| 175 | + --json-schema '{"type":"object","properties":{"release_notes":{"type":"string"},"release_date":{"type":"string","description":"Release date in YYYY-MM-DD format"}},"required":["release_notes","release_date"]}' |
| 176 | +
|
| 177 | + - name: Create Draft GitHub Release |
| 178 | + id: create-release |
| 179 | + uses: softprops/action-gh-release@v2 |
| 180 | + with: |
| 181 | + draft: true |
| 182 | + name: ${{ steps.extract-version.outputs.tag }} (${{ fromJSON(steps.claude-release.outputs.structured_output).release_date }}) |
| 183 | + tag_name: ${{ steps.extract-version.outputs.tag }} |
| 184 | + body: ${{ fromJSON(steps.claude-release.outputs.structured_output).release_notes }} |
| 185 | + env: |
| 186 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 187 | + |
| 188 | + - name: Output release URL |
| 189 | + run: | |
| 190 | + RELEASE_URL="https://github.com/${{ github.repository }}/releases/tag/${{ steps.extract-version.outputs.tag }}" |
| 191 | + echo "::notice::Draft release created: $RELEASE_URL" |
0 commit comments