From 50b2c07548e9fa05d09cda9a79f04ee0706bcb6e Mon Sep 17 00:00:00 2001 From: David Newhall II Date: Wed, 12 Jun 2019 14:32:28 -0700 Subject: [PATCH] Build formula file from template with Makefile. --- .gitignore | 2 ++ .travis.yml | 4 ++-- Makefile | 28 ++++++++++++++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index f99dc2a2..2cde1178 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ /unifi-poller*.pkg /unifi-poller.macos /unifi-poller.linux +/unifi-poller.rb +*.sha256 /vendor .DS_Store *~ diff --git a/.travis.yml b/.travis.yml index d48e8e87..84b7666d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,13 +20,13 @@ before_install: - chmod +x $GOPATH/bin/dep # download super-linter: golangci-lint - curl -sL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s -- -b $(go env GOPATH)/bin latest -- curl -sLo ./up.tgz https://github.com/davidnewhall/unifi-poller/archive/${TRAVIS_TAG}.tar.gz install: - dep ensure - rvm $brew_ruby do gem install --no-document fpm script: - rvm $brew_ruby do make release -- openssl dgst -sha256 ./up.tgz | tee release/${TRAVIS_TAG}.tar.gz.sha256 +# TODO: upload the formula somewhere. +- make formula deploy: provider: releases api_key: diff --git a/Makefile b/Makefile index c884c635..3eb44d79 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ BINARY:=unifi-poller URL=https://github.com/davidnewhall/unifi-poller -MAINT="David Newhall II " -DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." +MAINT=David Newhall II +DESC=This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database. PACKAGE:=./cmd/$(BINARY) ifeq ($(VERSION),) VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v||echo development) @@ -24,8 +24,8 @@ release: clean test $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm $(BINARY)_$(VER # Delete all build assets. clean: # Cleaning up. - rm -f $(BINARY){.macos,.linux,.1,}{,.gz} - rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff + rm -f $(BINARY){.macos,.linux,.1,}{,.gz} $(BINARY).rb + rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff v$(VERSION).tar.gz.sha256 rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rm -rf package_build_* release @@ -80,8 +80,8 @@ $(BINARY)-$(VERSION)-$(ITERATION).x86_64.rpm: check_fpm package_build_linux --before-remove scripts/before-remove.sh \ --license MIT \ --url $(URL) \ - --maintainer $(MAINT) \ - --description $(DESC) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ --chdir package_build_linux deb: clean $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb @@ -95,8 +95,8 @@ $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb: check_fpm package_build_linux --before-remove scripts/before-remove.sh \ --license MIT \ --url $(URL) \ - --maintainer $(MAINT) \ - --description $(DESC) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ --chdir package_build_linux osxpkg: clean $(BINARY)-$(VERSION).pkg @@ -110,8 +110,8 @@ $(BINARY)-$(VERSION).pkg: check_fpm package_build_osx --osxpkg-identifier-prefix com.github.davidnewhall \ --license MIT \ --url $(URL) \ - --maintainer $(MAINT) \ - --description $(DESC) \ + --maintainer "$(MAINT)" \ + --description "$(DESC)" \ --chdir package_build_osx # OSX packages use /usr/local because Apple doesn't allow writing many other places. @@ -146,6 +146,14 @@ package_build_linux: readme man linux check_fpm: @fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false) +formula: $(BINARY).rb +v$(VERSION).tar.gz.sha256: + # Calculate the SHA from the Github source file. + curl -sL https://github.com/davidnewhall/unifi-poller/archive/v$(VERSION).tar.gz | openssl dgst -sha256 | tee v$(VERSION).tar.gz.sha256 +$(BINARY).rb: v$(VERSION).tar.gz.sha256 + # Creating formula from template using sed. + sed "s/{{Version}}/$(VERSION)/g;s/{{SHA256}}/$$(