diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 8702832..6c5d362 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -1,4 +1,4 @@ -name: Testing +name: Build and Test Commits on: push: @@ -8,7 +8,7 @@ on: jobs: build: - name: Test + name: Build and Test runs-on: ubuntu-latest strategy: matrix: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..b6b5ef4 --- /dev/null +++ b/.github/workflows/release.yml @@ -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/setup-timezone@v1.0 + 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/get-release@v1.2.2 + 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 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4da8928..94f7cba 100644 --- a/.gitignore +++ b/.gitignore @@ -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 @@ -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 diff --git a/Makefile b/Makefile index c0c691f..39af822 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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