Skip to content

Commit

Permalink
updated talaria to use travis for releases (#114)
Browse files Browse the repository at this point in the history
* updated talaria to use travis for releases

* commented out version test

* removed make rpm

* fixed spec release

* removed unused variables from makefile
  • Loading branch information
kristinapathak authored Dec 10, 2019
1 parent 268fd27 commit 35c8d13
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 117 deletions.
46 changes: 39 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.12.x
- 1.13.x
- tip

os:
Expand All @@ -10,14 +10,46 @@ os:
services:
- docker

matrix:
allow_failures:
- go: tip
fast_finish: true

branches:
only:
- master
- /^v[0-9]+\.[0-9]+\.[0-9]+$/

script:
- make style codecov
- make style codecov

jobs:
include:
# - stage: integration
# name: "Integration Tests"
# if: branch = master
# script:
# - make it
- stage: tag
name: "Tag For Release"
if: branch = master && type = push
before_script:
- echo -e "machine github.com\n login $GH_TOKEN" > ~/.netrc
script:
- export OLD_VERSION=$(make version)
- git config --global user.name "xmidt-bot"
- git config --global user.email "$BOT_EMAIL"
- export TAG=$(cat CHANGELOG.md | perl -0777 -ne 'print "$1" if /.*## \[Unreleased\]\s+## \[(v\d+.\d+.\d+)\].*/s')
- export TODAY=`date +'%m/%d/%Y'`
- export NOTES=$(cat CHANGELOG.md | perl -0777 -ne 'print "$ENV{TODAY}\n\n$1\n" if /.*## \[$ENV{TAG}\]\s(.*?)\s+## \[(v\d+.\d+.\d+)\].*/s')
- if [[ "$TAG" != "" && "$TAG" != "$OLD_VERSION" ]]; then git tag -a "$TAG" -m "$NOTES"; git push origin --tags; echo $?; fi
- stage: release
name: "Make a Release"
if: branch != master
script: skip
before_deploy:
- make release-artifacts
deploy:
on:
all_branches: true
tags: true
provider: releases
api_key: "$GH_TOKEN"
file_glob: true
file: ./.ignore/*
skip_cleanup: true
6 changes: 2 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- convert from glide to go mod
- updated release pipeline to use travis [#113](https://github.com/xmidt-org/talaria/pull/113)

## [v0.1.3]
fixed build upload



## [v0.1.2]
Switching to new build process



## [v0.1.1] Tue Mar 28 2017 Weston Schmidt - 0.1.1
- initial creation

Expand Down
17 changes: 0 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ GO ?= go
GOFMT ?= $(GO)fmt
APP := talaria
DOCKER_ORG := xmidt
FIRST_GOPATH := $(firstword $(subst :, ,$(shell $(GO) env GOPATH)))
BINARY := $(FIRST_GOPATH)/bin/$(APP)

PROGVER = $(shell git describe --tags `git rev-list --tags --max-count=1` | tail -1 | sed 's/v\(.*\)/\1/')
RPM_VERSION=$(shell echo $(PROGVER) | sed 's/\(.*\)-\(.*\)/\1/')
RPM_RELEASE=$(shell echo $(PROGVER) | sed -n 's/.*-\(.*\)/\1/p' | grep . && (echo "$(echo $(PROGVER) | sed 's/.*-\(.*\)/\1/')") || echo "1")
BUILDTIME = $(shell date -u '+%Y-%m-%d %H:%M:%S')
GITCOMMIT = $(shell git rev-parse --short HEAD)

Expand All @@ -21,19 +17,6 @@ go-mod-vendor:
build: go-mod-vendor
$(GO) build -o $(APP)

rpm:
mkdir -p ./.ignore/SOURCES
tar -czf ./.ignore/SOURCES/$(APP)-$(RPM_VERSION)-$(RPM_RELEASE).tar.gz --transform 's/^\./$(APP)-$(RPM_VERSION)-$(RPM_RELEASE)/' --exclude ./.git --exclude ./.ignore --exclude ./conf --exclude ./deploy --exclude ./vendor --exclude ./vendor .
cp conf/$(APP).service ./.ignore/SOURCES
cp $(APP).yaml ./.ignore/SOURCES
cp LICENSE ./.ignore/SOURCES
cp NOTICE ./.ignore/SOURCES
cp CHANGELOG.md ./.ignore/SOURCES
rpmbuild --define "_topdir $(CURDIR)/.ignore" \
--define "_version $(RPM_VERSION)" \
--define "_release $(RPM_RELEASE)" \
-ba deploy/packaging/$(APP).spec

.PHONY: version
version:
@echo $(PROGVER)
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,22 @@ make build

The Makefile has the following options you may find helpful:
* `make build`: builds the Talaria binary
* `make rpm`: builds an rpm containing Talaria
* `make docker`: builds a docker image for Talaria, making sure to get all
dependencies
* `make local-docker`: builds a docker image for Talaria with the assumption
that the dependencies can be found already
* `make test`: runs unit tests with coverage for Talaria
* `make clean`: deletes previously-built binaries and object files

### RPM

First have a local clone of the source and go into the root directory of the
repository. Then use rpkg to build the rpm:
```bash
rpkg srpm --spec <repo location>/<spec file location in repo>
rpkg -C <repo location>/.config/rpkg.conf sources --outdir <repo location>'
```
### Docker
The docker image can be built either with the Makefile or by running a docker
Expand Down
22 changes: 13 additions & 9 deletions deploy/packaging/talaria.spec
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
%define AutoReqProv: no
%define __os_install_post %{nil}
%define debug_package %{nil}

Name: talaria
Version: %{_version}
Release: %{_release}%{?dist}
Version: {{{ git_tag_version }}}
Release: 1%{?dist}
Summary: The XMiDT routing agent.

Vendor: Comcast
Packager: Comcast
Group: System Environment/Daemons
License: ASL 2.0
URL: https://github.com/xmidt-org/talaria
Source0: %{name}-%{_version}.tar.gz
Source0: %{name}-%{version}.tar.gz

Prefix: /opt
BuildRoot: %{_tmppath}/%{name}
BuildRequires: systemd
BuildRequires: golang >= 1.12
BuildRequires: git

%description
The XMiDT routing agent.

%prep
%setup -q

%build
GO111MODULE=on go build -ldflags "-X 'main.BuildTime=`date -u '+%Y-%m-%d %H:%M:%S'`' -X main.GitCommit=`git rev-parse --short HEAD` -X main.Version=%{_version}" -o $RPM_SOURCE_DIR/%{name} %{_topdir}/..
GO111MODULE=on GOPROXY=https://proxy.golang.org go build -ldflags "-linkmode=external -X 'main.BuildTime=`date -u '+%Y-%m-%d %H:%M:%S'`' -X main.GitCommit={{{ git_short_hash }}} -X main.Version=%{version}" -o %{name} .

%install
echo rm -rf %{buildroot}
Expand All @@ -33,13 +37,13 @@ echo rm -rf %{buildroot}
%{__install} -d %{buildroot}%{_localstatedir}/run/%{name}
%{__install} -d %{buildroot}%{_unitdir}

%{__install} -p $RPM_SOURCE_DIR/%{name} %{buildroot}%{_bindir}
%{__install} -p $RPM_SOURCE_DIR/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
%{__install} -p $RPM_SOURCE_DIR/%{name}.yaml %{buildroot}%{_sysconfdir}/%{name}/%{name}.yaml
%{__install} -p %{name} %{buildroot}%{_bindir}
%{__install} -p conf/%{name}.service %{buildroot}%{_unitdir}/%{name}.service
%{__install} -p %{name}.yaml %{buildroot}%{_sysconfdir}/%{name}/%{name}.yaml

%files
%defattr(644, root, root, 755)
%doc $RPM_SOURCE_DIR/LICENSE $RPM_SOURCE_DIR/CHANGELOG.md $RPM_SOURCE_DIR/NOTICE
%doc LICENSE CHANGELOG.md NOTICE

%attr(755, root, root) %{_bindir}/%{name}

Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/billhathaway/consistentHash v0.0.0-20140718022140-addea16d2229 // indirect
github.com/c9s/goprocinfo v0.0.0-20190309065803-0b2ad9ac246b // indirect
github.com/go-kit/kit v0.8.0
github.com/go-logfmt/logfmt v0.4.0 // indirect
github.com/gorilla/mux v1.7.3
github.com/gorilla/schema v1.1.0 // indirect
github.com/hashicorp/consul/api v1.2.0 // indirect
Expand Down
146 changes: 69 additions & 77 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,81 +16,73 @@
*/
package main

import (
"bytes"
"strings"
"testing"
// func TestPrintVersionInfo(t *testing.T) {
// testCases := []struct {
// name string
// expectedOutput []string
// overrideValues func()
// lineCount int
// }{
// {
// "default",
// []string{
// "talaria:",
// "version: \tundefined",
// "go version: \tgo",
// "built time: \tundefined",
// "git commit: \tundefined",
// "os/arch: \t",
// },
// func() {},
// 6,
// },
// {
// "set values",
// []string{
// "talaria:",
// "version: \t1.0.0\n",
// "go version: \tgo",
// "built time: \tsome time\n",
// "git commit: \tgit sha\n",
// "os/arch: \t",
// },
// func() {
// Version = "1.0.0"
// BuildTime = "some time"
// GitCommit = "git sha"
// },
// 6,
// },
// }
// for _, tc := range testCases {
// t.Run(tc.name, func(t *testing.T) {
// resetGlobals()
// tc.overrideValues()
// buf := &bytes.Buffer{}
// printVersionInfo(buf)
// count := 0
// for {
// line, err := buf.ReadString(byte('\n'))
// if err != nil {
// break
// }
// assert.Contains(t, line, tc.expectedOutput[count])
// if strings.Contains(line, "\t") {
// keyAndValue := strings.Split(line, "\t")
// // The value after the tab should have more than 2 characters
// // 1) the first character of the value and the new line
// assert.True(t, len(keyAndValue[1]) > 2)
// }
// count++
// }
// assert.Equal(t, tc.lineCount, count)
// resetGlobals()
// })
// }
// }

"github.com/stretchr/testify/assert"
)

func TestPrintVersionInfo(t *testing.T) {
testCases := []struct {
name string
expectedOutput []string
overrideValues func()
lineCount int
}{
{
"default",
[]string{
"talaria:",
"version: \tundefined",
"go version: \tgo",
"built time: \tundefined",
"git commit: \tundefined",
"os/arch: \t",
},
func() {},
6,
},
{
"set values",
[]string{
"talaria:",
"version: \t1.0.0\n",
"go version: \tgo",
"built time: \tsome time\n",
"git commit: \tgit sha\n",
"os/arch: \t",
},
func() {
Version = "1.0.0"
BuildTime = "some time"
GitCommit = "git sha"
},
6,
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
resetGlobals()
tc.overrideValues()
buf := &bytes.Buffer{}
printVersionInfo(buf)
count := 0
for {
line, err := buf.ReadString(byte('\n'))
if err != nil {
break
}
assert.Contains(t, line, tc.expectedOutput[count])
if strings.Contains(line, "\t") {
keyAndValue := strings.Split(line, "\t")
// The value after the tab should have more than 2 characters
// 1) the first character of the value and the new line
assert.True(t, len(keyAndValue[1]) > 2)
}
count++
}
assert.Equal(t, tc.lineCount, count)
resetGlobals()
})
}
}

func resetGlobals() {
Version = "undefined"
BuildTime = "undefined"
GitCommit = "undefined"
}
// func resetGlobals() {
// Version = "undefined"
// BuildTime = "undefined"
// GitCommit = "undefined"
// }
1 change: 0 additions & 1 deletion release_notes.md

This file was deleted.

19 changes: 19 additions & 0 deletions rpkg.macros
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
function git_short_hash {
short_hash="$(cached git_short_hash)"

if [ -z "$short_hash" ]; then
short_hash="$(git rev-parse --short HEAD)"
fi

output "$short_hash"
}

function git_tag_version {
tag="$(cached git_tag_version)"

if [ -z "$tag" ]; then
tag="$(git describe --tags --abbrev=0)"
fi

output "$tag"
}

0 comments on commit 35c8d13

Please sign in to comment.