forked from Neo23x0/yarGen-Go
-
Notifications
You must be signed in to change notification settings - Fork 0
145 lines (122 loc) · 5.77 KB
/
release.yml
File metadata and controls
145 lines (122 loc) · 5.77 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Release
on:
push:
tags:
- 'v*.*.*'
workflow_dispatch:
inputs:
version:
description: 'Version to release (e.g., v1.0.0)'
required: true
type: string
jobs:
release:
name: Release Build
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'
cache-dependency-path: go.sum
- name: Determine version
id: version
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
VERSION="${{ github.event.inputs.version }}"
else
VERSION="${GITHUB_REF#refs/tags/}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "Release version: ${VERSION}"
- name: Download dependencies
run: go mod download
- name: Build binaries
run: |
mkdir -p release
# Linux
echo "Building for linux/amd64..."
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-linux-amd64 ./cmd/yargen
GOOS=linux GOARCH=amd64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-util-linux-amd64 ./cmd/yargen-util
echo "Building for linux/arm64..."
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-linux-arm64 ./cmd/yargen
GOOS=linux GOARCH=arm64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-util-linux-arm64 ./cmd/yargen-util
# macOS
echo "Building for darwin/amd64..."
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-darwin-amd64 ./cmd/yargen
GOOS=darwin GOARCH=amd64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-util-darwin-amd64 ./cmd/yargen-util
echo "Building for darwin/arm64..."
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-darwin-arm64 ./cmd/yargen
GOOS=darwin GOARCH=arm64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-util-darwin-arm64 ./cmd/yargen-util
# Windows
echo "Building for windows/amd64..."
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-windows-amd64.exe ./cmd/yargen
GOOS=windows GOARCH=amd64 go build -ldflags "-X main.version=${{ steps.version.outputs.version }}" -o release/yargen-util-windows-amd64.exe ./cmd/yargen-util
- name: Create checksums
run: |
cd release
sha256sum * > checksums.txt
cd ..
- name: Create release archive (Linux)
run: |
cd release
tar -czf yargen-${{ steps.version.outputs.version }}-linux-amd64.tar.gz yargen-linux-amd64 yargen-util-linux-amd64
tar -czf yargen-${{ steps.version.outputs.version }}-linux-arm64.tar.gz yargen-linux-arm64 yargen-util-linux-arm64
cd ..
- name: Create release archive (macOS)
run: |
cd release
tar -czf yargen-${{ steps.version.outputs.version }}-darwin-amd64.tar.gz yargen-darwin-amd64 yargen-util-darwin-amd64
tar -czf yargen-${{ steps.version.outputs.version }}-darwin-arm64.tar.gz yargen-darwin-arm64 yargen-util-darwin-arm64
cd ..
- name: Create release archive (Windows)
run: |
cd release
zip yargen-${{ steps.version.outputs.version }}-windows-amd64.zip yargen-windows-amd64.exe yargen-util-windows-amd64.exe
cd ..
- name: Sign binaries (Linux/macOS)
if: env.GPG_PRIVATE_KEY != ''
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
echo "$GPG_PRIVATE_KEY" | gpg --import --batch --yes
cd release
for file in yargen-*-linux-* yargen-*-darwin-*; do
gpg --armor --detach-sign --batch --yes --passphrase "$GPG_PASSPHRASE" "$file"
done
cd ..
continue-on-error: true
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.version }}
name: Release ${{ steps.version.outputs.version }}
body: |
## Release ${{ steps.version.outputs.version }}
### Binaries
#### Linux
- `yargen-${{ steps.version.outputs.version }}-linux-amd64.tar.gz` - Linux AMD64
- `yargen-${{ steps.version.outputs.version }}-linux-arm64.tar.gz` - Linux ARM64
#### macOS
- `yargen-${{ steps.version.outputs.version }}-darwin-amd64.tar.gz` - macOS Intel
- `yargen-${{ steps.version.outputs.version }}-darwin-arm64.tar.gz` - macOS Apple Silicon
#### Windows
- `yargen-${{ steps.version.outputs.version }}-windows-amd64.zip` - Windows AMD64
### Checksums
See `checksums.txt` for SHA256 checksums of all binaries.
files: |
release/*.tar.gz
release/*.zip
release/checksums.txt
release/*.asc
draft: false
prerelease: false
token: ${{ secrets.GITHUB_TOKEN }}