-
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.
[.github] - devops: Add GitHub Actions workflow for build and release
- Trigger build and release on push with 'v*.*.*' tag pattern - Build binary for multiple OS and architectures using Go 1.21 - Create and upload release assets on successful build
- Loading branch information
Showing
1 changed file
with
65 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,65 @@ | ||
name: Build and Release | ||
on: | ||
push: | ||
tags: | ||
- 'v*.*.*' | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
strategy: | ||
matrix: | ||
goos: [linux, windows, darwin] | ||
goarch: [amd64, arm64] | ||
steps: | ||
- name: Set up Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: 1.21 | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Build binary | ||
run: | | ||
GO111MODULE=on GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build -o build/sgpt_${{ matrix.goos }}_${{ matrix.goarch }} ./cmd/sgpt | ||
- name: Upload Artifact as Release Asset | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: sgpt_${{ matrix.goos }}_${{ matrix.goarch }} | ||
path: build/sgpt_${{ matrix.goos }}_${{ matrix.goarch }} | ||
|
||
release: | ||
needs: build | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- name: Download artifacts | ||
uses: actions/download-artifact@v2 | ||
with: | ||
path: build/ | ||
|
||
- name: Check out code | ||
uses: actions/checkout@v3 | ||
|
||
- name: Set up GitHub CLI | ||
run: | | ||
sudo apt-get update | ||
sudo apt-get install -y git | ||
sudo apt-get install -y gh | ||
git config --global user.name "GitHub Actions" | ||
git config --global user.email "[email protected]" | ||
- name: Create Release | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
export TAG_NAME=$(echo ${GITHUB_REF#refs/tags/}) | ||
export RELEASE_NAME="sgpt Release $TAG_NAME" | ||
gh release create --title "$RELEASE_NAME" --notes "Automated release" --target "${GITHUB_SHA}" $TAG_NAME | ||
- name: Upload Release Assets | ||
env: | ||
GH_TOKEN: ${{ github.token }} | ||
run: | | ||
find build/ -type f | while read f; do gh release upload "$(echo ${GITHUB_REF#refs/tags/})" "$f"; done; |