Skip to content

Commit 8e23c5e

Browse files
committed
Automate release process for v*.*.* tags.
1 parent d305d91 commit 8e23c5e

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

.github/workflows/release.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # e.g. v1.1.1, v2.0.0
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
strategy:
12+
matrix:
13+
os: [linux, macos, windows]
14+
arch: [amd64]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v3
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: '1.20'
24+
25+
- name: Build binary
26+
run: |
27+
mkdir -p dist/${{ matrix.os }}
28+
if [[ "${{ matrix.os }}" == "linux" ]]; then
29+
GOOS=linux GOARCH=${{ matrix.arch }} CGO_ENABLED=0 \
30+
go build -ldflags="-s -w" -o dist/linux/smartcommit-linux .
31+
elif [[ "${{ matrix.os }}" == "macos" ]]; then
32+
GOOS=darwin GOARCH=${{ matrix.arch }} CGO_ENABLED=0 \
33+
go build -ldflags="-s -w" -o dist/macos/smartcommit-macos .
34+
else
35+
GOOS=windows GOARCH=${{ matrix.arch }} CGO_ENABLED=0 \
36+
go build -ldflags="-s -w" -o dist/windows/smartcommit-windows.exe .
37+
fi
38+
39+
- name: Package archives
40+
run: |
41+
if [[ "${{ matrix.os }}" == "linux" ]]; then
42+
tar -czvf dist/smartcommit-linux.tar.gz -C dist/linux smartcommit-linux
43+
elif [[ "${{ matrix.os }}" == "macos" ]]; then
44+
tar -czvf dist/smartcommit-macos.tar.gz -C dist/macos smartcommit-macos
45+
else
46+
tar -czvf dist/smartcommit-windows.tar.gz -C dist/windows smartcommit-windows.exe
47+
fi
48+
49+
- name: Create GitHub Release
50+
id: create_release
51+
uses: softprops/action-gh-release@v1
52+
with:
53+
tag_name: ${{ github.ref_name }}
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
57+
- name: Upload Release Assets
58+
uses: softprops/action-gh-release@v1
59+
with:
60+
files: |
61+
dist/smartcommit-linux.tar.gz
62+
dist/smartcommit-macos.tar.gz
63+
dist/smartcommit-windows.tar.gz
64+
env:
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

0 commit comments

Comments
 (0)