1+ name : Build and Release
2+
3+ on :
4+ push :
5+ branches : [ main, master ]
6+ paths-ignore :
7+ - ' **.md'
8+ - ' docs/**'
9+ - ' LICENSE'
10+ - ' .gitignore'
11+ - ' *.txt'
12+ tags : [ 'v*' ]
13+ pull_request :
14+ branches : [ main, master ]
15+ paths-ignore :
16+ - ' **.md'
17+ - ' docs/**'
18+ - ' LICENSE'
19+ - ' .gitignore'
20+ - ' *.txt'
21+
22+ env :
23+ GO_VERSION : ' 1.23'
24+ BINARY_NAME : ' llm-caller'
25+ CGO_ENABLED : ' 0'
26+
27+ jobs :
28+ test :
29+ name : Test
30+ runs-on : ubuntu-latest
31+ steps :
32+ - name : Checkout code
33+ uses : actions/checkout@v4
34+
35+ - name : Set up Go
36+ uses : actions/setup-go@v5
37+ with :
38+ go-version : ${{ env.GO_VERSION }}
39+
40+ - name : Cache Go modules
41+ uses : actions/cache@v4
42+ with :
43+ path : |
44+ ~/.cache/go-build
45+ ~/go/pkg/mod
46+ key : ${{ runner.os }}-go-${{ env.GO_VERSION }}-${{ hashFiles('**/go.sum') }}
47+ restore-keys : |
48+ ${{ runner.os }}-go-${{ env.GO_VERSION }}-
49+
50+ - name : Download dependencies
51+ run : go mod download
52+
53+ - name : Run tests
54+ run : go test -v ./...
55+
56+ - name : Run go vet
57+ run : go vet ./...
58+
59+ - name : Check formatting
60+ run : |
61+ if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
62+ echo "Code is not formatted. Run: gofmt -s -w ."
63+ gofmt -s -l .
64+ exit 1
65+ fi
66+
67+ build :
68+ name : Build
69+ runs-on : ubuntu-latest
70+ needs : test
71+ strategy :
72+ matrix :
73+ goos : [linux, windows, darwin]
74+ goarch : [amd64, arm64]
75+ include :
76+ - goos : linux
77+ goarch : arm
78+ goarm : 7
79+ exclude :
80+ - goos : windows
81+ goarch : arm64
82+
83+ steps :
84+ - name : Checkout code
85+ uses : actions/checkout@v4
86+ with :
87+ fetch-depth : 0
88+
89+ - name : Set up Go
90+ uses : actions/setup-go@v5
91+ with :
92+ go-version : ${{ env.GO_VERSION }}
93+
94+ - name : Get version info
95+ id : version
96+ run : |
97+ if git describe --tags --exact-match >/dev/null 2>&1; then
98+ VERSION=$(git describe --tags --exact-match)
99+ else
100+ COMMIT_SHORT=$(git rev-parse --short HEAD)
101+ VERSION="v1.0.0-dev+${COMMIT_SHORT}"
102+ fi
103+
104+ GIT_COMMIT=$(git rev-parse HEAD)
105+ BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
106+
107+ echo "version=$VERSION" >> $GITHUB_OUTPUT
108+ echo "git_commit=$GIT_COMMIT" >> $GITHUB_OUTPUT
109+ echo "build_time=$BUILD_TIME" >> $GITHUB_OUTPUT
110+
111+ - name : Build binary
112+ env :
113+ GOOS : ${{ matrix.goos }}
114+ GOARCH : ${{ matrix.goarch }}
115+ GOARM : ${{ matrix.goarch == 'arm' && matrix.goarm || '' }}
116+ run : |
117+ mkdir -p dist
118+
119+ # Set binary name with proper extension
120+ if [ "${{ matrix.goos }}" = "windows" ]; then
121+ BINARY_NAME="${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}.exe"
122+ else
123+ if [ "${{ matrix.goarch }}" = "arm" ] && [ -n "${{ matrix.goarm }}" ]; then
124+ BINARY_NAME="${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}v${{ matrix.goarm }}"
125+ else
126+ BINARY_NAME="${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}"
127+ fi
128+ fi
129+
130+ # Build with version info
131+ go build \
132+ -ldflags "-s -w \
133+ -X 'main.Version=${{ steps.version.outputs.version }}' \
134+ -X 'main.GitCommit=${{ steps.version.outputs.git_commit }}' \
135+ -X 'main.BuildTime=${{ steps.version.outputs.build_time }}'" \
136+ -o "dist/${BINARY_NAME}" .
137+
138+ # Create checksum
139+ cd dist
140+ sha256sum "${BINARY_NAME}" > "${BINARY_NAME}.sha256"
141+
142+ - name : Upload artifacts
143+ uses : actions/upload-artifact@v4
144+ with :
145+ name : ${{ env.BINARY_NAME }}_${{ matrix.goos }}_${{ matrix.goarch }}${{ matrix.goarm && format('v{0}', matrix.goarm) || '' }}
146+ path : dist/*
147+ retention-days : 7
148+
149+ release :
150+ name : Release
151+ runs-on : ubuntu-latest
152+ needs : build
153+ if : startsWith(github.ref, 'refs/tags/')
154+ permissions :
155+ contents : write
156+
157+ steps :
158+ - name : Checkout code
159+ uses : actions/checkout@v4
160+ with :
161+ fetch-depth : 0
162+
163+ - name : Download all artifacts
164+ uses : actions/download-artifact@v4
165+ with :
166+ path : artifacts
167+
168+ - name : Generate release notes
169+ id : release_notes
170+ run : |
171+ VERSION=${GITHUB_REF#refs/tags/}
172+ GIT_COMMIT=$(git rev-parse HEAD)
173+ BUILD_TIME=$(date -u '+%Y-%m-%dT%H:%M:%SZ')
174+
175+ cat > release_notes.md << EOF
176+ ## Release $VERSION
177+
178+ ### Build Information
179+ - **Version**: $VERSION
180+ - **Commit**: $GIT_COMMIT
181+ - **Build Time**: $BUILD_TIME
182+
183+ ### Downloads
184+ Choose the appropriate binary for your platform:
185+
186+ **Linux:**
187+ - Linux AMD64: \`${{ env.BINARY_NAME }}_linux_amd64\`
188+ - Linux ARM64: \`${{ env.BINARY_NAME }}_linux_arm64\`
189+ - Linux ARMv7: \`${{ env.BINARY_NAME }}_linux_armv7\`
190+
191+ **macOS:**
192+ - macOS Intel: \`${{ env.BINARY_NAME }}_darwin_amd64\`
193+ - macOS Apple Silicon: \`${{ env.BINARY_NAME }}_darwin_arm64\`
194+
195+ **Windows:**
196+ - Windows AMD64: \`${{ env.BINARY_NAME }}_windows_amd64.exe\`
197+
198+ ### Installation
199+ 1. Download the binary for your platform
200+ 2. Verify checksum (optional): \`sha256sum -c filename.sha256\`
201+ 3. Make executable (Unix): \`chmod +x filename\`
202+ 4. Run: \`./filename --help\`
203+ EOF
204+
205+ - name : Create Release
206+ uses : softprops/action-gh-release@v2
207+ with :
208+ files : artifacts/**/*
209+ body_path : release_notes.md
210+ draft : false
211+ prerelease : ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
212+ make_latest : true
213+ env :
214+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments