Skip to content

Commit f6566f3

Browse files
committed
ci: release via gh actions
1 parent 300a37b commit f6566f3

1 file changed

Lines changed: 141 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
workflow_dispatch: # Allows manual triggering
8+
9+
env:
10+
GO_VERSION: '1.24'
11+
12+
jobs:
13+
build:
14+
name: Build Cross-Platform Binaries
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
include:
19+
- goos: windows
20+
goarch: amd64
21+
name: discord-time-presence-windows-amd64.exe
22+
- goos: windows
23+
goarch: arm64
24+
name: discord-time-presence-windows-arm64.exe
25+
- goos: linux
26+
goarch: amd64
27+
name: discord-time-presence-linux-amd64
28+
- goos: linux
29+
goarch: arm64
30+
name: discord-time-presence-linux-arm64
31+
- goos: darwin
32+
goarch: amd64
33+
name: discord-time-presence-darwin-amd64
34+
- goos: darwin
35+
goarch: arm64
36+
name: discord-time-presence-darwin-arm64
37+
38+
steps:
39+
- name: Checkout code
40+
uses: actions/checkout@v4
41+
42+
- name: Set up Go
43+
uses: actions/setup-go@v4
44+
with:
45+
go-version: ${{ env.GO_VERSION }}
46+
47+
- name: Cache Go modules
48+
uses: actions/cache@v3
49+
with:
50+
path: |
51+
~/.cache/go-build
52+
~/go/pkg/mod
53+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
54+
restore-keys: |
55+
${{ runner.os }}-go-
56+
57+
- name: Get dependencies
58+
run: go mod download
59+
60+
- name: Build binary
61+
env:
62+
GOOS: ${{ matrix.goos }}
63+
GOARCH: ${{ matrix.goarch }}
64+
CGO_ENABLED: 0
65+
run: go build -ldflags="-s -w" -o ${{ matrix.name }} .
66+
67+
- name: Upload artifacts
68+
uses: actions/upload-artifact@v3
69+
with:
70+
name: ${{ matrix.name }}
71+
path: ${{ matrix.name }}
72+
retention-days: 1
73+
74+
release:
75+
name: Create GitHub Release
76+
needs: build
77+
runs-on: ubuntu-latest
78+
if: startsWith(github.ref, 'refs/tags/')
79+
80+
steps:
81+
- name: Checkout code
82+
uses: actions/checkout@v4
83+
84+
- name: Download all artifacts
85+
uses: actions/download-artifact@v3
86+
with:
87+
path: ./binaries
88+
89+
- name: Flatten artifacts directory
90+
run: |
91+
mkdir -p ./release-binaries
92+
find ./binaries -name "discord-time-presence-*" -exec cp {} ./release-binaries/ \;
93+
94+
- name: Generate release notes
95+
run: |
96+
echo "# Discord Time Presence ${GITHUB_REF#refs/tags/}" > RELEASE_NOTES.md
97+
echo "" >> RELEASE_NOTES.md
98+
echo "## Downloads" >> RELEASE_NOTES.md
99+
echo "" >> RELEASE_NOTES.md
100+
echo "Choose the appropriate binary for your operating system:" >> RELEASE_NOTES.md
101+
echo "" >> RELEASE_NOTES.md
102+
echo "### Windows" >> RELEASE_NOTES.md
103+
echo "- **64-bit (Intel/AMD)**: \`discord-time-presence-windows-amd64.exe\`" >> RELEASE_NOTES.md
104+
echo "- **64-bit (ARM)**: \`discord-time-presence-windows-arm64.exe\`" >> RELEASE_NOTES.md
105+
echo "" >> RELEASE_NOTES.md
106+
echo "### Linux" >> RELEASE_NOTES.md
107+
echo "- **64-bit (Intel/AMD)**: \`discord-time-presence-linux-amd64\`" >> RELEASE_NOTES.md
108+
echo "- **64-bit (ARM)**: \`discord-time-presence-linux-arm64\`" >> RELEASE_NOTES.md
109+
echo "" >> RELEASE_NOTES.md
110+
echo "### macOS" >> RELEASE_NOTES.md
111+
echo "- **Intel Macs**: \`discord-time-presence-darwin-amd64\`" >> RELEASE_NOTES.md
112+
echo "- **Apple Silicon (M1/M2/M3)**: \`discord-time-presence-darwin-arm64\`" >> RELEASE_NOTES.md
113+
echo "" >> RELEASE_NOTES.md
114+
echo "## Installation" >> RELEASE_NOTES.md
115+
echo "" >> RELEASE_NOTES.md
116+
echo "1. Download the appropriate binary for your system" >> RELEASE_NOTES.md
117+
echo "2. Make it executable (Linux/macOS): \`chmod +x discord-time-presence-*\`" >> RELEASE_NOTES.md
118+
echo "3. Set your Discord Client ID: \`export DISCORD_CLIENT_ID=\"your_client_id\"\`" >> RELEASE_NOTES.md
119+
echo "4. Run the binary" >> RELEASE_NOTES.md
120+
echo "" >> RELEASE_NOTES.md
121+
122+
- name: Create checksums
123+
run: |
124+
cd release-binaries
125+
sha256sum * > checksums.txt
126+
echo "## Checksums (SHA256)" >> ../RELEASE_NOTES.md
127+
echo '```' >> ../RELEASE_NOTES.md
128+
cat checksums.txt >> ../RELEASE_NOTES.md
129+
echo '```' >> ../RELEASE_NOTES.md
130+
131+
- name: Create Release
132+
uses: softprops/action-gh-release@v1
133+
with:
134+
files: |
135+
release-binaries/*
136+
body_path: RELEASE_NOTES.md
137+
draft: false
138+
prerelease: false
139+
generate_release_notes: true
140+
env:
141+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)