Skip to content

Commit

Permalink
Add workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
ezhische committed Oct 9, 2024
1 parent 5826a77 commit 9bb706c
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: build

on:
push:
tags:
- '*' # Trigger on all tag pushes

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v4
with:
go-version: '1.22'

- name: Set repo base name
id: repo-name
run: echo "REPO_NAME=$(basename ${{ github.repository }})" >> $GITHUB_ENV

- name: Extract tag
id: extract-tag
run: echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV

- name: Set target platforms
id: platforms
run: |
echo "PLATFORMS=linux/amd64,linux/arm64,windows/amd64,darwin/amd64,darwin/arm64" >> $GITHUB_ENV
- name: Build for different platforms
env:
REPO_NAME: ${{ env.REPO_NAME }}
PLATFORMS: ${{ env.PLATFORMS }}
VERSION: ${{ env.TAG }}
run: |
platforms=(${PLATFORMS//,/ })
for platform in "${platforms[@]}"; do
os=$(echo $platform | cut -d'/' -f1)
arch=$(echo $platform | cut -d'/' -f2)
output_name="${REPO_NAME}-${os}-${arch}"
if [ "$os" = "windows" ]; then
output_name="${output_name}.exe"
fi
# Build the binary
GOOS=$os GOARCH=$arch CGO_ENABLED=0 go build -buildvcs=false -ldflags="-s -w -X main.version=${VERSION}" -o "$output_name" ./cmd
# Archive the binary as .tar.gz or .zip for Windows
if [ "$os" = "windows" ]; then
zip "${output_name}.zip" "$output_name"
else
tar czf "${output_name}.tar.gz" "$output_name"
fi
done
- name: Upload artifacts for release
uses: softprops/action-gh-release@v2
with:
files: |
${{ github.workspace }}/*.tar.gz
${{ github.workspace }}/*.zip

0 comments on commit 9bb706c

Please sign in to comment.