-
Notifications
You must be signed in to change notification settings - Fork 0
267 lines (223 loc) · 8.15 KB
/
build-release.yml
File metadata and controls
267 lines (223 loc) · 8.15 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
name: Build and Release
on:
push:
branches:
- "*release*"
tags:
- "v*"
jobs:
build_and_package:
name: Build & Package ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
include:
- os: windows-latest
platform: windows
exe_name: cst.exe
- os: ubuntu-latest
platform: linux
exe_name: cst
- os: macos-latest
platform: macos
exe_name: cst
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
lfs: true
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: "pip"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
# Switched to PyInstaller
pip install pyinstaller
# Install the project so PyInstaller can find dependencies in the environment
pip install -e .
# --- BUILD STEP ---
- name: Build Executable (PyInstaller)
run: python build_exe.py
# --- TEST STEPS ---
- name: Install Test Dependencies
run: |
pip install pytest
- name: Create Integration Test Config
shell: bash
run: echo "model = 'no-model'"> codestoryconfig.toml
- name: Test Built Executable
shell: bash
run: |
echo ">>> Testing Standalone Build"
EXE_PATH="dist/cst/${{ matrix.exe_name }}"
echo "Target Exe: $EXE_PATH"
# Validation: Ensure it exists before testing
if [ ! -f "$EXE_PATH" ]; then
echo "Error: Executable not found at $EXE_PATH"
ls -R dist/
exit 1
fi
# Set the env var for tests to use this specific binary
export CLI_ARTIFACT_PATH="$EXE_PATH"
pytest -vv src/tests/integration
# --- PACKAGING STEPS ---
# 1. WINDOWS: Inno Setup
- name: Install Inno Setup
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
choco install innosetup --no-progress
echo "C:\Program Files (x86)\Inno Setup 6" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
- name: Create & Compile Windows Installer
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
# Extract version from git tag
$VERSION = "${{ github.ref_name }}"
$VERSION = $VERSION -replace '^(v|release[-/]?)', ''
if ([string]::IsNullOrEmpty($VERSION) -or $VERSION -notmatch '^\d') { $VERSION = "0.0.1" }
# Package entire cli.dist directory
$issContent = @"
[Setup]
AppName=codestory
AppVersion=$VERSION
DefaultDirName={autopf}\codestory
DefaultGroupName=codestory
OutputBaseFilename=codestory-windows-installer
OutputDir=dist\installers
Compression=lzma
SolidCompression=yes
ChangesEnvironment=yes
ArchitecturesInstallIn64BitMode=x64
[Files]
Source: "dist\cst\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs
[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; \
Check: NeedsAddPath('{app}')
[Code]
function NeedsAddPath(Param: string): boolean;
var
OrigPath: string;
begin
if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
'Path', OrigPath)
then begin
Result := True;
exit;
end;
Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;
"@
$issContent | Out-File -FilePath "setup.iss" -Encoding ASCII
New-Item -ItemType Directory -Force -Path "dist\installers"
ISCC.exe setup.iss
# 2. LINUX: Build .deb
- name: Create Linux Installer (.deb)
if: matrix.os == 'ubuntu-latest'
run: |
VERSION="${{ github.ref_name }}"
VERSION=$(echo "$VERSION" | sed -E 's/^(v|release[-/]?)//')
if [[ -z "$VERSION" || ! "$VERSION" =~ ^[0-9] ]]; then VERSION="0.0.1"; fi
mkdir -p dist/package/opt/codestory
mkdir -p dist/package/usr/bin
mkdir -p dist/installers
# Copy entire cst directory to /opt/codestory
cp -r dist/cst/* dist/package/opt/codestory/
chmod +x dist/package/opt/codestory/cst
# Create wrapper script in /usr/bin
cat > dist/package/usr/bin/cst <<'EOF'
#!/bin/bash
exec /opt/codestory/cst "$@"
EOF
chmod +x dist/package/usr/bin/cst
mkdir -p dist/package/DEBIAN
cat > dist/package/DEBIAN/control <<EOF
Package: codestory
Version: $VERSION
Section: utils
Priority: optional
Architecture: amd64
Maintainer: Adem Can <ademfcan@gmail.com>
Description: An AI-powered abstraction layer above Git.
EOF
dpkg-deb --build dist/package dist/installers/codestory-linux-installer.deb
# 3. MACOS: Build .pkg
- name: Create macOS Installer (.pkg)
if: matrix.os == 'macos-latest'
run: |
VERSION="${{ github.ref_name }}"
VERSION=$(echo "$VERSION" | sed -E 's/^(v|release[-/]?)//')
if [[ -z "$VERSION" || ! "$VERSION" =~ ^[0-9] ]]; then VERSION="1.0"; fi
mkdir -p dist/installers
# Prepare a root folder for pkgbuild
mkdir -p dist/pkg_root/opt/codestory
mkdir -p dist/pkg_root/usr/local/bin
# Copy entire cst directory to /opt/codestory
cp -r dist/cst/* dist/pkg_root/opt/codestory/
# Create wrapper script in /usr/local/bin
cat > dist/pkg_root/usr/local/bin/cst <<'EOF'
#!/bin/bash
exec /opt/codestory/cst "$@"
EOF
chmod +x dist/pkg_root/usr/local/bin/cst
# Generate PKG from the root folder
pkgbuild --root dist/pkg_root \
--identifier com.codestory.cli \
--version "$VERSION" \
--install-location / \
dist/installers/codestory-macos-installer.pkg
# --- PREPARE ARTIFACTS ---
- name: Prepare Standalone & Installers
shell: bash
run: |
mkdir -p dist/ready_for_upload
# Package the standalone directory as a zip/tar.gz
if [ "${{ matrix.platform }}" == "windows" ]; then
cd dist
7z a -tzip ready_for_upload/cst-${{ matrix.platform }}-standalone.zip cst/*
cd ..
else
tar -czf dist/ready_for_upload/cst-${{ matrix.platform }}-standalone.tar.gz -C dist cst
fi
# Copy installers
cp dist/installers/* dist/ready_for_upload/
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: release-assets-${{ matrix.platform }}
path: dist/ready_for_upload/*
release:
permissions:
contents: write
name: Create Release
needs: [build_and_package]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags/')
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure
run: ls -R artifacts/
- name: Extract version
id: get_version
run: |
echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
- name: Create Release
uses: softprops/action-gh-release@v1
with:
name: Release ${{ steps.get_version.outputs.version }}
files: |
artifacts/release-assets-windows/*
artifacts/release-assets-linux/*
artifacts/release-assets-macos/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}