-
Notifications
You must be signed in to change notification settings - Fork 2
100 lines (90 loc) · 2.9 KB
/
release.yml
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
89
90
91
92
93
94
95
96
97
98
99
100
name: Build and Release
on:
push:
branches:
- main
env:
TAG: latest
RELEASE_NAME: Latest release
RELEASE_BODY: Latest release
BINARY_PREFIX: viterbiCli # Updated to match your new project name
jobs:
build_and_release:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 'stable'
- name: Install dependencies
run: go mod download
- name: Build binaries
run: |
mkdir -p build
PLATFORMS=(
"darwin/arm64"
"darwin/amd64"
"linux/arm64"
"linux/amd64"
"windows/amd64"
"windows/arm64"
"freebsd/386"
"freebsd/amd64"
"freebsd/arm"
"freebsd/arm64"
"openbsd/386"
"openbsd/amd64"
"openbsd/arm"
"openbsd/arm64"
"dragonfly/amd64"
"netbsd/386"
"netbsd/amd64"
"netbsd/arm"
"netbsd/arm64"
)
for PLATFORM in "${PLATFORMS[@]}"; do
GOOS=${PLATFORM%/*}
GOARCH=${PLATFORM#*/}
OUTPUT_NAME=${{ env.BINARY_PREFIX }}.$GOOS.$GOARCH
if [ "$GOOS" = "windows" ]; then
OUTPUT_NAME=$OUTPUT_NAME.exe
fi
echo "Building for $GOOS/$GOARCH..."
GOOS=$GOOS GOARCH=$GOARCH go build -ldflags "-X 'main.Version=$(date +'%Y-%m-%d_%H:%M:%S')'" -o "build/$OUTPUT_NAME" ./cmd/viterbiCli
done
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.TAG }}
release_name: ${{ env.RELEASE_NAME }}
body: ${{ env.RELEASE_BODY }}
draft: false
prerelease: false
- name: Upload Release Assets
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs').promises;
const path = require('path');
const uploadUrl = '${{ steps.create_release.outputs.upload_url }}';
const buildDir = 'build';
const files = await fs.readdir(buildDir);
for (const file of files) {
const filePath = path.join(buildDir, file);
const stat = await fs.stat(filePath);
if (stat.isFile()) {
console.log(`Uploading ${file}...`);
await github.rest.repos.uploadReleaseAsset({
url: uploadUrl,
headers: { 'content-type': 'application/octet-stream' },
name: file,
data: await fs.readFile(filePath)
});
}
}