-
Notifications
You must be signed in to change notification settings - Fork 2
88 lines (75 loc) · 2.32 KB
/
Copy pathrelease.yml
File metadata and controls
88 lines (75 loc) · 2.32 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
name: Release
on:
release:
types: [created]
workflow_dispatch:
jobs:
release:
name: Release Build
runs-on: ubuntu-latest
permissions:
contents: write
actions: write
strategy:
matrix:
include:
- goos: linux
goarch: amd64
- goos: linux
goarch: arm64
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21'
- name: Cache Go modules
uses: actions/cache@v4
with:
path: ~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download dependencies
run: go mod download
- name: Build binary (Linux only)
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
run: |
mkdir -p build
BINARY_NAME=coderaft
# Get version from git tag or use commit hash
if [ "${{ github.event_name }}" = "release" ]; then
VERSION=${{ github.event.release.tag_name }}
else
VERSION=$(git rev-parse --short HEAD)
fi
CGO_ENABLED=0 go build \
-ldflags="-w -s -X main.version=${VERSION}" \
-o build/${BINARY_NAME}-${GOOS}-${GOARCH} \
./cmd/coderaft
- name: Create archive (tar.gz)
run: |
cd build
BINARY_NAME=coderaft
ARCHIVE_NAME="coderaft-${{ matrix.goos }}-${{ matrix.goarch }}"
tar -czf ${ARCHIVE_NAME}.tar.gz ${BINARY_NAME}-${{ matrix.goos }}-${{ matrix.goarch }}
- name: Upload Release Asset
if: github.event_name == 'release'
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./build/coderaft-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
asset_name: coderaft-${{ matrix.goos }}-${{ matrix.goarch }}.tar.gz
asset_content_type: application/gzip
- name: Upload artifacts (manual trigger)
if: github.event_name == 'workflow_dispatch'
uses: actions/upload-artifact@v4
with:
name: coderaft-${{ matrix.goos }}-${{ matrix.goarch }}
path: build/coderaft-*
retention-days: 30