Skip to content

Commit 474cbf5

Browse files
committed
add github release.yml
1 parent 72a8e99 commit 474cbf5

File tree

1 file changed

+101
-0
lines changed

1 file changed

+101
-0
lines changed

.github/workflows/release.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Release dbq
2+
3+
on:
4+
push:
5+
tags:
6+
# trigger on tags like v1.0.0, v1.2.3 etc.
7+
- 'v*.*.*'
8+
9+
env:
10+
APP_NAME: dbq
11+
MAIN_PACKAGE_PATH: .
12+
13+
permissions:
14+
contents: write
15+
jobs:
16+
build:
17+
name: Build Binaries
18+
runs-on: ubuntu-latest
19+
strategy:
20+
matrix:
21+
include:
22+
- goos: linux
23+
goarch: amd64
24+
asset_suffix: linux-amd64
25+
compress_ext: .tar.gz
26+
- goos: linux
27+
goarch: arm64
28+
asset_suffix: linux-arm64
29+
compress_ext: .tar.gz
30+
- goos: darwin # macOS
31+
goarch: amd64
32+
asset_suffix: darwin-amd64
33+
compress_ext: .tar.gz
34+
- goos: darwin # macOS
35+
goarch: arm64
36+
asset_suffix: darwin-arm64
37+
compress_ext: .tar.gz
38+
39+
steps:
40+
- name: Checkout code
41+
uses: actions/checkout@v4
42+
with:
43+
fetch-depth: 0
44+
45+
- name: Set up Go
46+
uses: actions/setup-go@v5
47+
with:
48+
go-version: '1.24.2'
49+
50+
- name: Get dependencies
51+
run: go mod download
52+
53+
- name: Build Go application
54+
env:
55+
GOOS: ${{ matrix.goos }}
56+
GOARCH: ${{ matrix.goarch }}
57+
run: |
58+
# Construct the output binary name
59+
BINARY_NAME="${{ env.APP_NAME }}-${{ matrix.asset_suffix }}"
60+
go build -v -ldflags="-s -w" -o "build/${BINARY_NAME}" ${{ env.MAIN_PACKAGE_PATH }}
61+
echo "Built: build/${BINARY_NAME}"
62+
63+
- name: Compress binary (Linux/macOS)
64+
if: matrix.goos == 'linux' || matrix.goos == 'darwin'
65+
run: |
66+
BINARY_NAME="${{ env.APP_NAME }}-${{ matrix.asset_suffix }}"
67+
ARCHIVE_NAME="${BINARY_NAME}${matrix.compress_ext}"
68+
cd build
69+
tar czf "../${ARCHIVE_NAME}" "${BINARY_NAME}"
70+
cd ..
71+
echo "Compressed: ${ARCHIVE_NAME}"
72+
echo "ASSET_PATH=${ARCHIVE_NAME}" >> $GITHUB_ENV
73+
echo "ASSET_NAME=${ARCHIVE_NAME}" >> $GITHUB_ENV
74+
75+
- name: Upload artifact
76+
uses: actions/upload-artifact@v4
77+
with:
78+
name: ${{ env.ASSET_NAME }} # Use the compressed archive name as artifact name
79+
path: ${{ env.ASSET_PATH }} # Upload the compressed archive
80+
retention-days: 1 # Keep artifact only for a short time
81+
82+
release:
83+
name: Create GitHub Release
84+
needs: build
85+
runs-on: ubuntu-latest
86+
steps:
87+
- name: Download all build artifacts
88+
uses: actions/download-artifact@v4
89+
with:
90+
path: release-assets
91+
92+
- name: List downloaded files
93+
run: ls -lah release-assets
94+
95+
- name: Create GitHub Release
96+
uses: softprops/action-gh-release@v2
97+
with:
98+
tag_name: ${{ github.ref_name }}
99+
name: Release ${{ github.ref_name }}
100+
generate_release_notes: true
101+
files: release-assets/*/*

0 commit comments

Comments
 (0)