forked from cesanta/docker_auth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request cesanta#110 from cesanta/version
Version-tag builds
- Loading branch information
Showing
4 changed files
with
75 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
ca-certificates.crt | ||
auth_server | ||
Godeps/ | ||
version.* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/env python | ||
|
||
import datetime | ||
import sys | ||
|
||
# Debian/Ubuntu: apt-get install python-git | ||
# PIP: pip install GitPython | ||
import git | ||
|
||
repo = git.Repo('.', search_parent_directories=True) | ||
|
||
|
||
def get_tag_for_commit(repo, commit): | ||
for tag in repo.tags: | ||
if tag.commit == commit: | ||
return tag.name | ||
return None | ||
|
||
|
||
if repo.head.is_detached: | ||
branch_or_tag = get_tag_for_commit(repo, repo.head.commit) | ||
if branch_or_tag is None: | ||
branch_or_tag = '?' | ||
else: | ||
branch_or_tag = repo.active_branch | ||
|
||
dirty = repo.is_dirty() | ||
|
||
ts = datetime.datetime.utcnow() | ||
build_id = '%s/%s@%s%s' % (ts.strftime('%Y%m%d-%H%M%S'), | ||
branch_or_tag, | ||
str(repo.head.commit)[:8], | ||
'+' if dirty else '') | ||
|
||
version = None | ||
if not dirty: | ||
version = get_tag_for_commit(repo, repo.head.commit) | ||
if version is None: | ||
version = ts.strftime('%Y%m%d%H%M%S') | ||
|
||
|
||
if len(sys.argv) == 1 or sys.argv[1] == '-': | ||
f = sys.stdout | ||
else: | ||
f = open(sys.argv[1], 'w') | ||
|
||
with open('version.go', 'w') as f: | ||
f.write("""\ | ||
package main | ||
const ( | ||
\tVersion = "{version}" | ||
\tBuildId = "{build_id}" | ||
) | ||
""".format(version=version, build_id=build_id)) | ||
|
||
with open('version.txt', 'w') as f: | ||
f.write(version) | ||
|
||
f.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters