Skip to content

Commit

Permalink
Provide binary builds with Github
Browse files Browse the repository at this point in the history
  • Loading branch information
kimtore committed Aug 14, 2022
1 parent 2660625 commit d22bbb0
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 6 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/build.yml
@@ -0,0 +1,82 @@
name: Build
on:
push:
paths:
- 'Makefile'
- 'go.mod'
- '**.go'
- '.github/workflows/build.yml'
env:
go_version: '1.17'

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ env.go_version }}
- name: run tests
run: |
go mod download
make test
make pms
make_release:
if: ${{ github.ref == 'refs/heads/master' }}
needs:
- test
runs-on: ubuntu-latest
outputs:
upload_url: ${{ steps.create_release.outputs.upload_url }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- name: Delete latest release
uses: dev-drprasad/delete-tag-and-release@v0.2.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
delete_release: true
tag_name: latest
- name: Create release
id: create_release
uses: actions/create-release@v1
with:
tag_name: latest
release_name: Latest build
draft: false
prerelease: false
release:
if: ${{ github.ref == 'refs/heads/master' }}
needs:
- make_release
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
strategy:
matrix:
os_arch:
- darwin-amd64
- darwin-arm64
- linux-amd64
- linux-arm64
- linux-arm
- windows-amd64.exe
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ env.go_version }}
- name: Download dependencies
run: |
go mod download
- name: Build binary
run: make ${{ matrix.os_arch }}
- name: Upload binary
uses: actions/upload-release-asset@v1
with:
upload_url: ${{ needs.make_release.outputs.upload_url }}
asset_path: build/pms-${{ matrix.os_arch }}
asset_name: pms-${{ matrix.os_arch }}
asset_content_type: application/octet-stream
34 changes: 28 additions & 6 deletions Makefile
@@ -1,13 +1,35 @@
VERSION := $(shell git describe --always --long --dirty)
DATE := $(shell date +%s)
LDFLAGS := -ldflags="-X main.buildVersion=${VERSION}"

.PHONY: install pms test
.PHONY: pms test linux-amd64 linux-arm64 linux-arm darwin-amd64 darwin-arm64 windows-amd64.exe

pms:
mkdir -p build/
go build -o build/pms -ldflags="-X main.buildVersion=${VERSION}" main.go

install:
go install -ldflags="-X main.buildVersion=${VERSION}"
go build ${LDFLAGS} -o build/pms main.go

test:
go test ./...

linux-amd64:
GOOS=linux GOARCH=amd64 \
go build ${LDFLAGS} -o build/pms-linux-amd64 main.go

linux-arm64:
GOOS=linux GOARCH=arm64 \
go build ${LDFLAGS} -o build/pms-linux-arm64 main.go

linux-arm:
GOOS=linux GOARCH=arm \
go build ${LDFLAGS} -o build/pms-linux-arm main.go

darwin-amd64:
GOOS=darwin GOARCH=amd64 \
go build ${LDFLAGS} -o build/pms-darwin-amd64 main.go

darwin-arm64:
GOOS=darwin GOARCH=arm64 \
go build ${LDFLAGS} -o build/pms-darwin-arm64 main.go

windows-amd64.exe:
GOOS=windows GOARCH=amd64 \
go build ${LDFLAGS} -o build/pms-windows-amd64.exe main.go

0 comments on commit d22bbb0

Please sign in to comment.