|
| 1 | +name: "Release" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + draft: |
| 7 | + description: 'Create as draft release?' |
| 8 | + required: false |
| 9 | + default: false |
| 10 | + type: boolean |
| 11 | + custom_notes: |
| 12 | + description: 'Custom release notes (optional, prepended to auto-generated)' |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + |
| 16 | +jobs: |
| 17 | + release: |
| 18 | + name: "Create Release" |
| 19 | + runs-on: "ubuntu-latest" |
| 20 | + permissions: |
| 21 | + contents: write |
| 22 | + steps: |
| 23 | + - name: "Checkout the repository" |
| 24 | + uses: "actions/checkout@v6.0.2" |
| 25 | + with: |
| 26 | + fetch-depth: 0 # Fetch all history for release notes |
| 27 | + |
| 28 | + - name: "Read version from manifest" |
| 29 | + id: version |
| 30 | + run: | |
| 31 | + # Extract version from manifest.json |
| 32 | + VERSION=$(jq -r '.version' custom_components/bhyve/manifest.json) |
| 33 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 34 | + echo "📦 Version: $VERSION" |
| 35 | +
|
| 36 | + # Validate version format (semver with optional prerelease) |
| 37 | + if ! echo "$VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?$'; then |
| 38 | + echo "❌ ERROR: Invalid version format: $VERSION" |
| 39 | + echo "Expected format: X.Y.Z or X.Y.Z-suffix (e.g., 4.1.0 or 4.1.0-beta1)" |
| 40 | + exit 1 |
| 41 | + fi |
| 42 | +
|
| 43 | + # Detect prerelease |
| 44 | + if [[ "$VERSION" =~ -beta|-alpha|-rc ]]; then |
| 45 | + echo "prerelease=true" >> $GITHUB_OUTPUT |
| 46 | + echo "🔶 This will be marked as a prerelease" |
| 47 | + else |
| 48 | + echo "prerelease=false" >> $GITHUB_OUTPUT |
| 49 | + echo "✅ This will be a stable release" |
| 50 | + fi |
| 51 | +
|
| 52 | + - name: "Check if tag exists" |
| 53 | + id: check_tag |
| 54 | + run: | |
| 55 | + if git rev-parse "${{ steps.version.outputs.version }}" >/dev/null 2>&1; then |
| 56 | + echo "❌ ERROR: Tag ${{ steps.version.outputs.version }} already exists" |
| 57 | + echo "Please update the version in manifest.json or delete the existing tag" |
| 58 | + exit 1 |
| 59 | + fi |
| 60 | + echo "✅ Tag does not exist, safe to proceed" |
| 61 | +
|
| 62 | + - name: "Create and push tag" |
| 63 | + run: | |
| 64 | + git config user.name "github-actions[bot]" |
| 65 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 66 | + git tag -a "${{ steps.version.outputs.version }}" -m "Release ${{ steps.version.outputs.version }}" |
| 67 | + git push origin "${{ steps.version.outputs.version }}" |
| 68 | + echo "🏷️ Created and pushed tag: ${{ steps.version.outputs.version }}" |
| 69 | +
|
| 70 | + - name: "Generate release notes" |
| 71 | + id: notes |
| 72 | + uses: actions/github-script@v8 |
| 73 | + with: |
| 74 | + script: | |
| 75 | + const version = '${{ steps.version.outputs.version }}'; |
| 76 | +
|
| 77 | + try { |
| 78 | + // Generate release notes using GitHub's API |
| 79 | + const { data } = await github.rest.repos.generateReleaseNotes({ |
| 80 | + owner: context.repo.owner, |
| 81 | + repo: context.repo.repo, |
| 82 | + tag_name: version, |
| 83 | + }); |
| 84 | +
|
| 85 | + // Optionally prepend custom notes |
| 86 | + const customNotes = `${{ inputs.custom_notes }}`.trim(); |
| 87 | + let fullNotes = data.body; |
| 88 | +
|
| 89 | + if (customNotes) { |
| 90 | + fullNotes = customNotes + '\n\n---\n\n' + data.body; |
| 91 | + } |
| 92 | +
|
| 93 | + core.setOutput('notes', fullNotes); |
| 94 | + console.log('✅ Release notes generated successfully'); |
| 95 | + } catch (error) { |
| 96 | + // Fallback if release notes generation fails |
| 97 | + console.log('⚠️ Could not generate release notes, using fallback'); |
| 98 | + const customNotes = `${{ inputs.custom_notes }}`.trim(); |
| 99 | + const fallbackNotes = customNotes || `Release ${version}`; |
| 100 | + core.setOutput('notes', fallbackNotes); |
| 101 | + } |
| 102 | +
|
| 103 | + - name: "Create ZIP file" |
| 104 | + run: | |
| 105 | + cd custom_components/bhyve |
| 106 | + zip -r ../../bhyve.zip ./ -x "*.pyc" -x "__pycache__/*" -x "*.pyo" |
| 107 | + cd ../.. |
| 108 | + echo "📦 ZIP file created:" |
| 109 | + ls -lh bhyve.zip |
| 110 | +
|
| 111 | + - name: "Create GitHub Release" |
| 112 | + uses: softprops/action-gh-release@v2.6.1 |
| 113 | + with: |
| 114 | + tag_name: ${{ steps.version.outputs.version }} |
| 115 | + name: Release ${{ steps.version.outputs.version }} |
| 116 | + body: ${{ steps.notes.outputs.notes }} |
| 117 | + files: bhyve.zip |
| 118 | + draft: ${{ inputs.draft }} |
| 119 | + prerelease: ${{ steps.version.outputs.prerelease }} |
| 120 | + |
| 121 | + - name: "Release summary" |
| 122 | + run: | |
| 123 | + echo "## ✅ Release Created Successfully" >> $GITHUB_STEP_SUMMARY |
| 124 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 125 | + echo "- **Version:** ${{ steps.version.outputs.version }}" >> $GITHUB_STEP_SUMMARY |
| 126 | + echo "- **Type:** ${{ steps.version.outputs.prerelease == 'true' && 'Prerelease' || 'Stable' }}" >> $GITHUB_STEP_SUMMARY |
| 127 | + echo "- **Draft:** ${{ inputs.draft }}" >> $GITHUB_STEP_SUMMARY |
| 128 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 129 | + echo "[View Release](https://github.com/${{ github.repository }}/releases/tag/${{ steps.version.outputs.version }})" >> $GITHUB_STEP_SUMMARY |
0 commit comments