Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
110 additions
and
6 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,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 |
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 |
---|---|---|
@@ -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 |