Skip to content

Commit 919c95e

Browse files
committed
add GitHub Actions workflow for build and release process
1 parent 6fdf979 commit 919c95e

File tree

1 file changed

+99
-0
lines changed

1 file changed

+99
-0
lines changed

.github/workflows/release.yml

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
name: Build and Release
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*.*.*' # Match version tags
7+
8+
jobs:
9+
build:
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macos-latest]
15+
16+
steps:
17+
- name: Checkout code
18+
uses: actions/checkout@v2
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: '1.21.6' # Specify the Go version
24+
25+
- name: Install dependencies
26+
run: go mod tidy
27+
28+
- name: Build project
29+
run: |
30+
if [[ ${{ matrix.os }} == 'ubuntu-latest' ]]; then
31+
GOOS=linux GOARCH=amd64 go build -o myproject-linux
32+
elif [[ ${{ matrix.os }} == 'windows-latest' ]]; then
33+
GOOS=windows GOARCH=amd64 go build -o myproject-windows.exe
34+
elif [[ ${{ matrix.os }} == 'macos-latest' ]]; then
35+
GOOS=darwin GOARCH=amd64 go build -o myproject-macos
36+
fi
37+
38+
- name: Upload artifact
39+
uses: actions/upload-artifact@v2
40+
with:
41+
name: myproject-${{ matrix.os }}
42+
path: |
43+
myproject-linux
44+
myproject-windows.exe
45+
myproject-macos
46+
47+
release:
48+
needs: build
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Download artifacts
52+
uses: actions/download-artifact@v2
53+
with:
54+
name: myproject-${{ matrix.os }}
55+
path: .
56+
57+
- name: Create GitHub Release
58+
id: create_release
59+
uses: actions/create-release@v1
60+
env:
61+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
62+
with:
63+
tag_name: ${{ github.ref }}
64+
release_name: Release ${{ github.ref }}
65+
draft: false
66+
prerelease: false
67+
68+
- name: Upload Release Asset (Linux)
69+
if: always()
70+
uses: actions/upload-release-asset@v1
71+
env:
72+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
73+
with:
74+
upload_url: ${{ steps.create_release.outputs.upload_url }}
75+
asset_path: myproject-linux
76+
asset_name: myproject-linux
77+
asset_content_type: application/octet-stream
78+
79+
- name: Upload Release Asset (Windows)
80+
if: always()
81+
uses: actions/upload-release-asset@v1
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
with:
85+
upload_url: ${{ steps.create_release.outputs.upload_url }}
86+
asset_path: myproject-windows.exe
87+
asset_name: myproject-windows.exe
88+
asset_content_type: application/octet-stream
89+
90+
- name: Upload Release Asset (macOS)
91+
if: always()
92+
uses: actions/upload-release-asset@v1
93+
env:
94+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
95+
with:
96+
upload_url: ${{ steps.create_release.outputs.upload_url }}
97+
asset_path: myproject-macos
98+
asset_name: myproject-macos
99+
asset_content_type: application/octet-stream

0 commit comments

Comments
 (0)