Skip to content

Build binaries v1.0.0 #3

Build binaries v1.0.0

Build binaries v1.0.0 #3

Workflow file for this run

name: Build binaries
run-name: Build binaries ${{ github.event.release.tag_name }}
on:
release:
types: [published]
jobs:
build:
name: Build binaries
runs-on: ubuntu-latest
strategy:
matrix:
platform:
- linux/arm64
- linux/arm/v7
- linux/arm/v6
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: "1.21"
- name: Build binary
run: |
export GOOS=$(echo ${{ matrix.platform }} | awk -F/ '{print $1}')
export GOARCH=$(echo ${{ matrix.platform }} | awk -F/ '{print $2}')
export GOARM=$(echo ${{ matrix.platform }} | awk -F/ '{print $3}' | sed 's/v//')
export CGO_ENABLED=0
reponame="${{ github.event.repository.name }}"
version="${{ github.event.release.tag_name }}"
fullarch="${GOARCH}$(echo ${{ matrix.platform }} | awk -F/ '{print $3}')"
filename="${reponame}_${version}_${GOOS}_${fullarch}"
noextfilename="$filename"
if [[ "$GOOS" == "windows" ]]; then
filename="$filename.exe"
fi
go build -ldflags "-w -s -X main.version=$version -extldflags '-static'" -o "$filename" cmd/$reponame/main.go
echo "FILENAME=$filename" >> $GITHUB_ENV
echo "NOEXTFILENAME=$noextfilename" >> $GITHUB_ENV
- name: Compress binary
run: |
tar -czvf "${{ env.NOEXTFILENAME }}.tar.gz" "${{ env.FILENAME }}"
- name: Upload binary
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ${{ env.NOEXTFILENAME }}.tar.gz
tag: ${{ github.event.release.tag_name }}
overwrite: false