-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add GitHub Actions workflow for build and release process
- Loading branch information
Showing
1 changed file
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
name: Build and Release | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' # Match version tags | ||
|
||
jobs: | ||
build: | ||
runs-on: ${{ matrix.os }} | ||
|
||
strategy: | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macos-latest] | ||
|
||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.21.6' # Specify the Go version | ||
|
||
- name: Install dependencies | ||
run: go mod tidy | ||
|
||
- name: Build project | ||
run: | | ||
if [[ ${{ matrix.os }} == 'ubuntu-latest' ]]; then | ||
GOOS=linux GOARCH=amd64 go build -o myproject-linux | ||
elif [[ ${{ matrix.os }} == 'windows-latest' ]]; then | ||
GOOS=windows GOARCH=amd64 go build -o myproject-windows.exe | ||
elif [[ ${{ matrix.os }} == 'macos-latest' ]]; then | ||
GOOS=darwin GOARCH=amd64 go build -o myproject-macos | ||
fi | ||
- name: Upload artifact | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: myproject-${{ matrix.os }} | ||
path: | | ||
myproject-linux | ||
myproject-windows.exe | ||
myproject-macos | ||
release: | ||
needs: build | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: myproject-${{ matrix.os }} | ||
path: . | ||
|
||
- name: Create GitHub Release | ||
id: create_release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ github.ref }} | ||
release_name: Release ${{ github.ref }} | ||
draft: false | ||
prerelease: false | ||
|
||
- name: Upload Release Asset (Linux) | ||
if: always() | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: myproject-linux | ||
asset_name: myproject-linux | ||
asset_content_type: application/octet-stream | ||
|
||
- name: Upload Release Asset (Windows) | ||
if: always() | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: myproject-windows.exe | ||
asset_name: myproject-windows.exe | ||
asset_content_type: application/octet-stream | ||
|
||
- name: Upload Release Asset (macOS) | ||
if: always() | ||
uses: actions/upload-release-asset@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ steps.create_release.outputs.upload_url }} | ||
asset_path: myproject-macos | ||
asset_name: myproject-macos | ||
asset_content_type: application/octet-stream |