Skip to content

Commit a846e1e

Browse files
committed
chore: optimize CI builds
1 parent 62bb681 commit a846e1e

File tree

2 files changed

+82
-173
lines changed

2 files changed

+82
-173
lines changed

.github/workflows/build.yml

Lines changed: 0 additions & 123 deletions
This file was deleted.

.github/workflows/release.yml

Lines changed: 82 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ permissions:
99
contents: write
1010
packages: write
1111

12+
env:
13+
GO_VERSION: '1.25.1'
14+
1215
jobs:
13-
release:
14-
name: Create Release
16+
test:
17+
name: Run Tests
1518
runs-on: ubuntu-latest
1619

1720
steps:
@@ -20,65 +23,96 @@ jobs:
2023
- name: Set up Go
2124
uses: actions/setup-go@v6
2225
with:
23-
go-version: '1.25.1'
26+
go-version: ${{ env.GO_VERSION }}
2427

2528
- name: Get dependencies
2629
run: go mod download
2730

2831
- name: Run tests
2932
run: go test -v ./...
3033

31-
- name: Build all platforms
34+
build:
35+
name: Build
36+
runs-on: ubuntu-latest
37+
needs: [test]
38+
strategy:
39+
matrix:
40+
goos: [linux, windows, darwin]
41+
goarch: [amd64, arm64, "386", arm]
42+
exclude:
43+
# Exclude unsupported combinations
44+
- goos: darwin
45+
goarch: "386"
46+
- goos: darwin
47+
goarch: arm
48+
- goos: windows
49+
goarch: arm
50+
51+
steps:
52+
- uses: actions/checkout@v5
53+
54+
- name: Set up Go
55+
uses: actions/setup-go@v6
56+
with:
57+
go-version: ${{ env.GO_VERSION }}
58+
59+
- name: Get dependencies
60+
run: go mod download
61+
62+
- name: Build
63+
env:
64+
GOOS: ${{ matrix.goos }}
65+
GOARCH: ${{ matrix.goarch }}
3266
run: |
67+
# Create output directory
3368
mkdir -p dist
3469
35-
# Build for all platforms
36-
platforms=(
37-
"linux/amd64"
38-
"linux/arm64"
39-
"linux/386"
40-
"linux/arm"
41-
"windows/amd64"
42-
"windows/arm64"
43-
"windows/386"
44-
"darwin/amd64"
45-
"darwin/arm64"
46-
)
70+
# Set output filename with architecture info
71+
OUTPUT_NAME="lilt-${{ matrix.goos }}-${{ matrix.goarch }}"
72+
if [ "${{ matrix.goos }}" = "windows" ]; then
73+
OUTPUT_NAME="lilt-${{ matrix.goos }}-${{ matrix.goarch }}.exe"
74+
fi
4775
48-
for platform in "${platforms[@]}"; do
49-
GOOS=${platform%/*}
50-
GOARCH=${platform#*/}
51-
52-
output_name="lilt-${GOOS}-${GOARCH}"
53-
if [ "$GOOS" = "windows" ]; then
54-
output_name="${output_name}.exe"
55-
fi
56-
57-
echo "Building for $GOOS/$GOARCH..."
58-
env GOOS=$GOOS GOARCH=$GOARCH go build \
59-
-ldflags="-s -w -X main.version=${GITHUB_REF#refs/tags/}" \
60-
-o "dist/${output_name}" .
61-
done
62-
63-
- name: Create archives
64-
run: |
65-
cd dist
76+
# Build the binary with version info
77+
go build \
78+
-ldflags="-s -w -X main.version=${GITHUB_REF#refs/tags/}" \
79+
-o "dist/${OUTPUT_NAME}" .
6680
67-
# Create tar.gz for Unix-like systems
68-
for file in lilt-linux-* lilt-darwin-*; do
69-
if [ -f "$file" ]; then
70-
tar -czf "${file}.tar.gz" "$file"
71-
rm "$file"
72-
fi
73-
done
81+
# Create archive
82+
cd dist
83+
if [ "${{ matrix.goos }}" = "windows" ]; then
84+
zip "${OUTPUT_NAME%.exe}.zip" "${OUTPUT_NAME}"
85+
else
86+
tar -czf "${OUTPUT_NAME}.tar.gz" "${OUTPUT_NAME}"
87+
fi
88+
89+
- name: Upload artifacts
90+
uses: actions/upload-artifact@v4
91+
with:
92+
name: lilt-${{ matrix.goos }}-${{ matrix.goarch }}
93+
path: |
94+
dist/*.tar.gz
95+
dist/*.zip
96+
97+
release:
98+
name: Create Release
99+
runs-on: ubuntu-latest
100+
needs: [build]
101+
102+
steps:
103+
- uses: actions/checkout@v5
104+
105+
- name: Download all artifacts
106+
uses: actions/download-artifact@v5
107+
with:
108+
path: artifacts
74109

75-
# Create zip for Windows
76-
for file in lilt-windows-*.exe; do
77-
if [ -f "$file" ]; then
78-
zip "${file%.exe}.zip" "$file"
79-
rm "$file"
80-
fi
81-
done
110+
- name: Prepare release assets
111+
run: |
112+
mkdir -p dist
113+
# Copy archives from all artifact directories
114+
find artifacts -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec cp {} dist/ \;
115+
ls -la dist/
82116
83117
- name: Create Release
84118
uses: softprops/action-gh-release@v2
@@ -99,5 +133,3 @@ jobs:
99133
draft: false
100134
prerelease: false
101135
make_latest: true
102-
env:
103-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)