Skip to content

Commit

Permalink
add GitHub Actions workflow for build and release process
Browse files Browse the repository at this point in the history
  • Loading branch information
mattrust committed Dec 26, 2024
1 parent 6fdf979 commit 919c95e
Showing 1 changed file with 99 additions and 0 deletions.
99 changes: 99 additions & 0 deletions .github/workflows/release.yml
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

0 comments on commit 919c95e

Please sign in to comment.