Build formula file from template with Makefile.

This commit is contained in:
David Newhall II 2019-06-12 14:32:28 -07:00
parent 49b224cbe1
commit 50b2c07548
3 changed files with 22 additions and 12 deletions

2
.gitignore vendored
View File

@ -7,6 +7,8 @@
/unifi-poller*.pkg /unifi-poller*.pkg
/unifi-poller.macos /unifi-poller.macos
/unifi-poller.linux /unifi-poller.linux
/unifi-poller.rb
*.sha256
/vendor /vendor
.DS_Store .DS_Store
*~ *~

View File

@ -20,13 +20,13 @@ before_install:
- chmod +x $GOPATH/bin/dep - chmod +x $GOPATH/bin/dep
# download super-linter: golangci-lint # 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 -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: install:
- dep ensure - dep ensure
- rvm $brew_ruby do gem install --no-document fpm - rvm $brew_ruby do gem install --no-document fpm
script: script:
- rvm $brew_ruby do make release - 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: deploy:
provider: releases provider: releases
api_key: api_key:

View File

@ -1,7 +1,7 @@
BINARY:=unifi-poller BINARY:=unifi-poller
URL=https://github.com/davidnewhall/unifi-poller URL=https://github.com/davidnewhall/unifi-poller
MAINT="David Newhall II <david at sleepers dot pro>" MAINT=David Newhall II <david at sleepers dot pro>
DESC="This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database." DESC=This daemon polls a Unifi controller at a short interval and stores the collected metric data in an Influx Database.
PACKAGE:=./cmd/$(BINARY) PACKAGE:=./cmd/$(BINARY)
ifeq ($(VERSION),) ifeq ($(VERSION),)
VERSION:=$(shell git tag -l --merged | tail -n1 | tr -d v||echo development) 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. # Delete all build assets.
clean: clean:
# Cleaning up. # Cleaning up.
rm -f $(BINARY){.macos,.linux,.1,}{,.gz} rm -f $(BINARY){.macos,.linux,.1,}{,.gz} $(BINARY).rb
rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff rm -f $(BINARY){_,-}*.{deb,rpm,pkg} md2roff v$(VERSION).tar.gz.sha256
rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html rm -f cmd/$(BINARY)/README{,.html} README{,.html} ./$(BINARY)_manual.html
rm -rf package_build_* release 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 \ --before-remove scripts/before-remove.sh \
--license MIT \ --license MIT \
--url $(URL) \ --url $(URL) \
--maintainer $(MAINT) \ --maintainer "$(MAINT)" \
--description $(DESC) \ --description "$(DESC)" \
--chdir package_build_linux --chdir package_build_linux
deb: clean $(BINARY)_$(VERSION)-$(ITERATION)_amd64.deb 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 \ --before-remove scripts/before-remove.sh \
--license MIT \ --license MIT \
--url $(URL) \ --url $(URL) \
--maintainer $(MAINT) \ --maintainer "$(MAINT)" \
--description $(DESC) \ --description "$(DESC)" \
--chdir package_build_linux --chdir package_build_linux
osxpkg: clean $(BINARY)-$(VERSION).pkg osxpkg: clean $(BINARY)-$(VERSION).pkg
@ -110,8 +110,8 @@ $(BINARY)-$(VERSION).pkg: check_fpm package_build_osx
--osxpkg-identifier-prefix com.github.davidnewhall \ --osxpkg-identifier-prefix com.github.davidnewhall \
--license MIT \ --license MIT \
--url $(URL) \ --url $(URL) \
--maintainer $(MAINT) \ --maintainer "$(MAINT)" \
--description $(DESC) \ --description "$(DESC)" \
--chdir package_build_osx --chdir package_build_osx
# OSX packages use /usr/local because Apple doesn't allow writing many other places. # 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: check_fpm:
@fpm --version > /dev/null || (echo "FPM missing. Install FPM: https://fpm.readthedocs.io/en/latest/installing.html" && false) @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}}/$$(<v$(VERSION).tar.gz.sha256)/g;s/{{Desc}}/$(DESC)/g;s%{{URL}}%$(URL)%g" templates/$(BINARY).rb.tmpl | tee $(BINARY).rb
# Extras # Extras
# Run code tests and lint. # Run code tests and lint.