Skip to content

Commit

Permalink
Added make release and Github Action to auto-release packages with …
Browse files Browse the repository at this point in the history
…each version.
  • Loading branch information
colinmcintosh committed Nov 12, 2020
1 parent dc7089e commit cc25dbc
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Testing
name: Build and Test Commits

on:
push:
Expand All @@ -8,7 +8,7 @@ on:

jobs:
build:
name: Test
name: Build and Test
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down
67 changes: 67 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
on:
release:
types: [published]

name: Build Assets for Release Tag

jobs:
build:
name: Upload Asset to Release
runs-on: ubuntu-latest
strategy:
matrix:
platform: [ 'linux', 'freebsd', 'windows', 'darwin' ]
architecture: [ 'amd64' ]
include:
- platform: linux
architecture: arm
- platform: linux
architecture: arm64
steps:
- name: Set up timezone
uses: zcong1993/[email protected]
with:
timezone: America/Los_Angeles

- name: Set up Golang
uses: actions/setup-go@v2
with:
go-version: 1.15
id: go

- name: Checkout code
uses: actions/checkout@v2

- name: Build asset
env:
GOOS: ${{ matrix.platform }}
GOARCH: ${{ matrix.architecture }}
run: make release

- name: Get release
id: get-release
uses: bruceadams/[email protected]
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Upload zip asset
id: upload-release-zip-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get-release.outputs.upload_url }}
asset_path: ./release/gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip
asset_name: gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip
asset_content_type: application/zip

- name: Upload sha256 asset
id: upload-release-sha256-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.get-release.outputs.upload_url }}
asset_path: ./release/gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip.sha256
asset_name: gnmi-gateway-${{ steps.get-release.outputs.tag_name }}-${{ matrix.platform }}-${{ matrix.architecture }}.zip.sha256
asset_content_type: text/plain
26 changes: 13 additions & 13 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
scratch.txt
targets.json

# Certificates
server.crt
server.key

# Emitted binary and releases
gnmi-gateway
release/

# OpenConfig models download
oc-models/

# pprof debugging web server
cpu.pprof

# GoLang-specific ignores
# Binaries for programs and plugins
Expand Down Expand Up @@ -172,16 +185,3 @@ com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Certificates
server.crt
server.key

# Emitted binary
gnmi-gateway

# OpenConfig models download
oc-models/

# pprof debugging web server
cpu.pprof
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ GOLDFLAGS += -X github.com/openconfig/gnmi-gateway/gateway.Version=$(VERSION)
GOLDFLAGS += -X github.com/openconfig/gnmi-gateway/gateway.Buildtime=$(BUILDTIME)
GOFLAGS = -ldflags "$(GOLDFLAGS)"

.PHONY: build release

build: clean
go build -o gnmi-gateway $(GOFLAGS) .
./gnmi-gateway -version
Expand Down Expand Up @@ -37,6 +39,18 @@ lint: imports
go fmt ./ ./gateway/...
go vet

release:
mkdir -p release
rm -f release/gnmi-gateway release/gnmi-gateway.exe
ifeq ($(shell go env GOOS), windows)
go build -o release/gnmi-gateway.exe $(GOFLAGS) .
cd release; zip -m "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip" gnmi-gateway.exe
else
go build -o release/gnmi-gateway $(GOFLAGS) .
cd release; zip -m "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip" gnmi-gateway
endif
cd release; sha256sum "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip" > "gnmi-gateway-$(shell git describe --tags --abbrev=0)-$(shell go env GOOS)-$(shell go env GOARCH).zip.sha256"

run: build
./gnmi-gateway -EnableGNMIServer -ServerTLSCert=server.crt -ServerTLSKey=server.key -TargetLoaders=json -TargetJSONFile=targets.json

Expand Down

0 comments on commit cc25dbc

Please sign in to comment.