forked from homeassistant-ai/ha-mcp
-
Notifications
You must be signed in to change notification settings - Fork 0
212 lines (174 loc) · 5.91 KB
/
Copy path_build-and-release.yml
File metadata and controls
212 lines (174 loc) · 5.91 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
name: Build Binaries and Attach to Release
# Reusable workflow for building and releasing binaries
# Can be called from any release workflow (semver, dev, hotfix, manual)
on:
workflow_call:
inputs:
release_tag:
description: 'Release tag to attach binaries to (e.g., v5.0.1)'
required: true
type: string
is_prerelease:
description: 'Whether this is a prerelease (dev build)'
required: false
type: boolean
default: false
permissions:
contents: write # Required to upload release assets
jobs:
build:
name: Build on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
include:
- os: ubuntu-latest
artifact_name: ha-mcp-linux
binary_ext: ''
platform: linux
- os: windows-latest
artifact_name: ha-mcp-windows
binary_ext: '.exe'
platform: win32
- os: macos-latest
artifact_name: ha-mcp-macos-arm64
binary_ext: ''
platform: darwin
steps:
- name: Checkout code
uses: actions/checkout@v7
with:
submodules: true
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
version: "latest"
- name: Create virtual environment and install dependencies
run: |
uv venv .venv
uv pip install -e . pyinstaller
shell: bash
- name: Activate venv (Unix)
if: runner.os != 'Windows'
run: echo "$PWD/.venv/bin" >> $GITHUB_PATH
- name: Activate venv (Windows)
if: runner.os == 'Windows'
run: echo "$PWD/.venv/Scripts" >> $env:GITHUB_PATH
shell: pwsh
- name: Build binary
run: pyinstaller packaging/binary/ha-mcp.spec
- name: Test binary (Linux/macOS)
if: runner.os != 'Windows'
run: |
chmod +x dist/ha-mcp
dist/ha-mcp --smoke-test
- name: Test binary (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
& "dist\ha-mcp.exe" --smoke-test
if ($LASTEXITCODE -ne 0) {
Write-Host "Smoke test failed with exit code $LASTEXITCODE"
exit $LASTEXITCODE
}
- name: Rename binary for artifact
shell: bash
run: |
mv dist/ha-mcp${{ matrix.binary_ext }} dist/${{ matrix.artifact_name }}${{ matrix.binary_ext }}
- name: Upload binary artifact
uses: actions/upload-artifact@v7
with:
name: ${{ matrix.artifact_name }}
path: dist/${{ matrix.artifact_name }}${{ matrix.binary_ext }}
if-no-files-found: error
create-mcpb:
name: Create MCPB Bundle
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Set up Python
uses: actions/setup-python@v6
with:
python-version: '3.13'
- name: Download Windows binary
uses: actions/download-artifact@v8
with:
name: ha-mcp-windows
path: mcpb-bundle
- name: Download macOS binary
uses: actions/download-artifact@v8
with:
name: ha-mcp-macos-arm64
path: mcpb-bundle
- name: Create MCPB bundle
run: |
VERSION="${{ inputs.release_tag }}"
VERSION="${VERSION#v}" # Remove 'v' prefix
# Rename binaries to standard names
mv mcpb-bundle/ha-mcp-windows.exe mcpb-bundle/ha-mcp.exe
mv mcpb-bundle/ha-mcp-macos-arm64 mcpb-bundle/ha-mcp
# Copy icons to bundle
cp packaging/mcpb/icon-*.png mcpb-bundle/
cp packaging/mcpb/icon-512.png mcpb-bundle/icon.png
# Generate manifest.json
python packaging/mcpb/generate_manifest.py "$VERSION"
# Create .mcpb file (zip archive)
cd mcpb-bundle
zip -r ../ha-mcp.mcpb *
cd ..
echo "=== MCPB Contents ==="
unzip -l ha-mcp.mcpb
- name: Upload MCPB artifact
uses: actions/upload-artifact@v7
with:
name: ha-mcp-mcpb
path: ha-mcp.mcpb
if-no-files-found: error
upload-to-release:
name: Upload Binaries to Release
needs: [build, create-mcpb]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v7
- name: Download all artifacts
uses: actions/download-artifact@v8
with:
pattern: ha-mcp-*
path: artifacts
- name: Display artifact structure
run: ls -R artifacts/
- name: Upload binaries to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
TAG="${{ inputs.release_tag }}"
echo "Uploading binaries to release $TAG..."
# Check if release exists and is draft
RELEASE_INFO=$(gh api repos/${{ github.repository }}/releases/tags/$TAG 2>/dev/null || echo "")
if [ -z "$RELEASE_INFO" ]; then
echo "Error: Release $TAG not found"
exit 1
fi
IS_DRAFT=$(echo "$RELEASE_INFO" | jq -r '.draft')
echo "Release $TAG draft status before upload: $IS_DRAFT"
# Upload all binaries
gh release upload "$TAG" \
artifacts/ha-mcp-linux/ha-mcp-linux \
artifacts/ha-mcp-windows/ha-mcp-windows.exe \
artifacts/ha-mcp-macos-arm64/ha-mcp-macos-arm64 \
artifacts/ha-mcp-mcpb/ha-mcp.mcpb \
--clobber
echo "✓ Uploaded binaries to $TAG"
echo "Publishing release..."
# Always attempt to undraft. This is safe and idempotent.
# If it's already published, this does nothing but returns success.
gh release edit "$TAG" --draft=false
echo "✓ Published release $TAG"