1+ name : Build and Release
2+
3+ # Only trigger on pushes to main branch that modify code files
4+ # Manual workflow dispatch is also supported for testing
5+ on :
6+ push :
7+ branches : [ main ]
8+ paths-ignore :
9+ - ' **.md'
10+ - ' docs/**'
11+ workflow_dispatch :
12+
13+ env :
14+ # Cache key version - increment to invalidate caches
15+ CACHE_VERSION : v1
16+
17+ jobs :
18+ build :
19+ runs-on : ubuntu-latest
20+
21+ permissions :
22+ contents : write # Required for creating releases and uploading assets
23+
24+ outputs :
25+ version : ${{ steps.version.outputs.version }}
26+ tag : ${{ steps.tag.outputs.tag }}
27+
28+ steps :
29+ - name : Checkout code
30+ uses : actions/checkout@v4
31+
32+ - name : Setup Bun
33+ uses : oven-sh/setup-bun@v1
34+ with :
35+ bun-version : latest
36+
37+ - name : Cache dependencies
38+ uses : actions/cache@v4
39+ with :
40+ path : ~/.bun/install/cache
41+ key : bun-${{ env.CACHE_VERSION }}-${{ hashFiles('**/bun.lockb', '**/package.json') }}
42+ restore-keys : |
43+ bun-${{ env.CACHE_VERSION }}-
44+
45+ - name : Install dependencies
46+ run : bun install --frozen-lockfile
47+
48+ - name : Extract version
49+ id : version
50+ run : |
51+ VERSION=$(cat package.json | jq -r '.version')
52+ if [[ -z "$VERSION" || "$VERSION" == "null" ]]; then
53+ echo "❌ Failed to extract version from package.json"
54+ exit 1
55+ fi
56+ echo "version=$VERSION" >> $GITHUB_OUTPUT
57+ echo "✅ Extracted version: $VERSION"
58+
59+ - name : Validate build script
60+ run : |
61+ if [[ ! -x "build.sh" ]]; then
62+ echo "❌ build.sh is not executable"
63+ exit 1
64+ fi
65+
66+ - name : Build binaries
67+ run : |
68+ echo "🔨 Building binaries for version ${{ steps.version.outputs.version }}"
69+ ./build.sh
70+
71+ - name : Verify build artifacts
72+ run : |
73+ VERSION="${{ steps.version.outputs.version }}"
74+ BUILD_DIR="build"
75+
76+ # Expected binaries based on current build script behavior
77+ declare -A EXPECTED_BINARIES=(
78+ ["linux-x64"]="justinstall-$VERSION-linux-x64"
79+ ["linux-arm64"]="justinstall-$VERSION-linux-arm64"
80+ ["windows-x64"]="justinstall-$VERSION-windows-x64.exe"
81+ ["darwin-x64"]="justinstall-$VERSION-darwin-x64"
82+ ["darwin-arm64"]="justinstall-$VERSION-darwin-arm64"
83+ )
84+
85+ echo "📋 Verifying build artifacts..."
86+ ALL_FOUND=true
87+
88+ for platform in "${!EXPECTED_BINARIES[@]}"; do
89+ binary="${EXPECTED_BINARIES[$platform]}"
90+ if [[ -f "$BUILD_DIR/$binary" ]]; then
91+ size=$(stat -f%z "$BUILD_DIR/$binary" 2>/dev/null || stat -c%s "$BUILD_DIR/$binary" 2>/dev/null)
92+ echo "✅ $platform: $binary (${size} bytes)"
93+ else
94+ echo "❌ Missing $platform binary: $binary"
95+ ALL_FOUND=false
96+ fi
97+ done
98+
99+ if [[ "$ALL_FOUND" == "false" ]]; then
100+ echo "❌ Build verification failed - some binaries are missing"
101+ echo "📁 Contents of build directory:"
102+ ls -la "$BUILD_DIR/" || echo "Build directory not found"
103+ exit 1
104+ fi
105+
106+ echo "✅ All expected binaries verified successfully"
107+
108+ - name : Generate release tag
109+ id : tag
110+ run : |
111+ VERSION="${{ steps.version.outputs.version }}"
112+ TIMESTAMP=$(date -u +%Y%m%d-%H%M%S)
113+ TAG="$VERSION-$TIMESTAMP"
114+
115+ # Validate tag format
116+ if [[ ! "$TAG" =~ ^[a-zA-Z0-9v][a-zA-Z0-9v._-]*$ ]]; then
117+ echo "❌ Invalid tag format: $TAG"
118+ exit 1
119+ fi
120+
121+ echo "tag=$TAG" >> $GITHUB_OUTPUT
122+ echo "✅ Generated release tag: $TAG"
123+
124+ - name : Create Pre-Release
125+ uses : softprops/action-gh-release@v2
126+ with :
127+ tag_name : ${{ steps.tag.outputs.tag }}
128+ name : " Pre-release ${{ steps.tag.outputs.tag }}"
129+ body : |
130+ 🤖 **Automated pre-release build**
131+
132+ **Version:** `${{ steps.version.outputs.version }}`
133+ **Commit:** [`${{ github.sha }}`](${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }})
134+ **Build:** [#${{ github.run_number }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
135+ **Built:** ${{ steps.tag.outputs.tag }}
136+
137+ ## 📦 Available Binaries
138+
139+ | Platform | Binary | Architecture |
140+ |----------|--------|--------------|
141+ | Linux | `justinstall-${{ steps.version.outputs.version }}-linux-x64` | x86_64 |
142+ | Linux | `justinstall-${{ steps.version.outputs.version }}-linux-arm64` | ARM64 |
143+ | Windows | `justinstall-${{ steps.version.outputs.version }}-windows-x64.exe` | x86_64 |
144+ | macOS | `justinstall-${{ steps.version.outputs.version }}-darwin-x64` | x86_64 |
145+ | macOS | `justinstall-${{ steps.version.outputs.version }}-darwin-arm64` | ARM64 (Apple Silicon) |
146+
147+ ## 📥 Installation
148+
149+ Download the appropriate binary for your platform and add it to your PATH.
150+
151+ ---
152+
153+ > This is an automated pre-release. For stable releases, see the main releases.
154+ files : build/*
155+ prerelease : true
156+ draft : false
157+ fail_on_unmatched_files : true
158+ generate_release_notes : false
159+ env :
160+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments