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