Skip to content

Commit

Permalink
Merge pull request #523 from smira/versioning
Browse files Browse the repository at this point in the history
Automatic versioning for aptly
  • Loading branch information
smira authored Mar 27, 2017
2 parents 91219e3 + a138d01 commit 8ae61f9
Show file tree
Hide file tree
Showing 14 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ before_install:
- mkdir -p $GOPATH/src/github.com/smira
- ln -s $TRAVIS_BUILD_DIR $GOPATH/src/github.com/smira || true
- cd $GOPATH/src/github.com/smira/aptly
- make version
install:
- make prepare

Expand Down
11 changes: 7 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GOVERSION=$(shell go version | awk '{print $$3;}')
VERSION=$(shell git describe --tags | sed 's@^v@@' | sed 's@-@+@g')
PACKAGES=context database deb files http query swift s3 utils
ALL_PACKAGES=api aptly context cmd console database deb files http query swift s3 utils
PYTHON?=python
TESTS?=
BINPATH?=$(GOPATH)/bin
Expand Down Expand Up @@ -39,12 +39,12 @@ check:
gometalinter --vendor --vendored-linters --config=linter.json ./...

install:
go install -v
go install -v -ldflags "-X main.Version=$(VERSION)"

system-test: install
if [ ! -e ~/aptly-fixture-db ]; then git clone https://github.com/aptly-dev/aptly-fixture-db.git ~/aptly-fixture-db/; fi
if [ ! -e ~/aptly-fixture-pool ]; then git clone https://github.com/aptly-dev/aptly-fixture-pool.git ~/aptly-fixture-pool/; fi
PATH=$(BINPATH)/:$(PATH) $(PYTHON) system/run.py --long $(TESTS)
APTLY_VERSION=$(VERSION) PATH=$(BINPATH)/:$(PATH) $(PYTHON) system/run.py --long $(TESTS)

travis: $(TRAVIS_TARGET) check system-test

Expand Down Expand Up @@ -79,4 +79,7 @@ goxc:
man:
make -C man

.PHONY: coverage.out man
version:
@echo $(VERSION)

.PHONY: coverage.out man version
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ If you have Go environment set up, you can build aptly from source by running (g
mkdir -p $GOPATH/src/github.com/smira/aptly
git clone https://github.com/smira/aptly $GOPATH/src/github.com/smira/aptly
cd $GOPATH/src/github.com/smira/aptly
go install .
make install

Binary would be installed to ```$GOPATH/bin/aptly``.

Expand Down
4 changes: 2 additions & 2 deletions aptly/version.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package aptly

// Version of aptly
const Version = "0.9.8~dev"
// Version of aptly (filled in at link time)
var Version string

// EnableDebug triggers some debugging features
const EnableDebug = false
3 changes: 3 additions & 0 deletions deb/version_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@ func (s *VersionSuite) TestCompareVersions(c *C) {

c.Check(CompareVersions("1.0~beta1~svn1245", "1.0~beta1"), Equals, -1)
c.Check(CompareVersions("1.0~beta1", "1.0"), Equals, -1)

c.Check(CompareVersions("1.0-133-avc", "1.1"), Equals, -1)
c.Check(CompareVersions("1.0-133-avc", "1.0"), Equals, 1)
}

func (s *VersionSuite) TestParseDependency(c *C) {
Expand Down
10 changes: 10 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ package main
import (
"os"

"github.com/smira/aptly/aptly"
"github.com/smira/aptly/cmd"
)

// Version variable, filled in at link time
var Version string

func main() {
if Version == "" {
Version = "unknown"
}

aptly.Version = Version

os.Exit(cmd.Run(cmd.RootCommand(), os.Args[1:], true))
}
6 changes: 6 additions & 0 deletions system/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ def run(include_long_tests=False, capture_results=False, tests=None, filters=Non
sys.exit(1)

if __name__ == "__main__":
if 'APTLY_VERSION' not in os.environ:
try:
os.environ['APTLY_VERSION'] = os.popen("make version").read().strip()
except BaseException, e:
print "Failed to capture current version: ", e

os.chdir(os.path.realpath(os.path.dirname(sys.argv[0])))
random.seed()
include_long_tests = False
Expand Down
2 changes: 1 addition & 1 deletion system/t01_version/VersionTest_gold
Original file line number Diff line number Diff line change
@@ -1 +1 @@
aptly version: 0.9.8~dev
aptly version: ${APTLY_VERSION}
1 change: 1 addition & 0 deletions system/t01_version/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ class VersionTest(BaseTest):
"""
version should match
"""
gold_processor = BaseTest.expand_environ

runCmd = "aptly version"
2 changes: 1 addition & 1 deletion system/t10_task/RunTask1Test_gold
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ End command output: ------------------------------
4) [Running]: version

Begin command output: ----------------------------
aptly version: 0.9.8~dev
aptly version: ${APTLY_VERSION}

End command output: ------------------------------
2 changes: 2 additions & 0 deletions system/t10_task/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ class RunTask1Test(BaseTest):
"""
task run: simple commands, 1-word command
"""
gold_processor = BaseTest.expand_environ

runCmd = "aptly task run repo list, repo create local, repo drop local, version"


Expand Down
7 changes: 4 additions & 3 deletions system/t12_api/systemd_handover.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import requests_unixsocket
import time
import urllib
import os
import os.path

from lib import BaseTest


class SystemdAPIHandoverTest(BaseTest):
aptly_server = None
socket_path = "/tmp/_aptly_systemdapihandovertest.sock"
Expand Down Expand Up @@ -37,9 +38,9 @@ def run(self):
Verify we can listen on a unix domain socket.
"""
def check(self):
if self.aptly_server == None:
if self.aptly_server is None:
print("Skipping test as we failed to setup a listener.")
return
session = requests_unixsocket.Session()
r = session.get('http+unix://%s/api/version' % urllib.quote(self.socket_path, safe=''))
self.check_equal(r.json(), {'Version': '0.9.8~dev'})
self.check_equal(r.json(), {'Version': os.environ['APTLY_VERSION']})
4 changes: 3 additions & 1 deletion system/t12_api/unix_socket.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import requests_unixsocket
import time
import os
import urllib

from lib import BaseTest


class UnixSocketAPITest(BaseTest):
aptly_server = None
socket_path = "/tmp/_aptly_test.sock"
Expand Down Expand Up @@ -33,4 +35,4 @@ def check(self):
r = session.get('http+unix://%s/api/version' % urllib.quote(UnixSocketAPITest.socket_path, safe=''))
# Just needs to come back, we actually don't care much about the code.
# Only needs to verify that the socket is actually responding.
self.check_equal(r.json(), {'Version': '0.9.8~dev'})
self.check_equal(r.json(), {'Version': os.environ['APTLY_VERSION']})
3 changes: 2 additions & 1 deletion system/t12_api/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from api_lib import APITest
import os


class VersionAPITest(APITest):
Expand All @@ -7,4 +8,4 @@ class VersionAPITest(APITest):
"""

def check(self):
self.check_equal(self.get("/api/version").json(), {'Version': '0.9.8~dev'})
self.check_equal(self.get("/api/version").json(), {'Version': os.environ['APTLY_VERSION']})

0 comments on commit 8ae61f9

Please sign in to comment.