Files
OSIT-Mailman3/get_latest_ref.py
Abhilash Raj 3434446987 Create rolling releases using the Gitlab API. (#171)
* Create rolling releases using the Gitlab API.

This commit builds rolling releases of Container images using the latest commit
on master branch if the pipeline passed for it. The script which gets the
references is still un-tested and should be tested.

The latest commit hashes are passed as arguments to the Dockerfile, which is
then used by PIP to install the specific version of the dependency.
2017-11-03 18:43:59 -07:00

39 lines
806 B
Python
Executable File

#! /usr/bin/env python
import os
import sys
import gitlab
def usage():
print("{} <project_name> <project_branch>")
def main():
if 2 > len(sys.argv) > 3:
usage()
project_name = sys.argv[1]
if len(sys.argv) > 2:
branch_name = sys.argv[2]
else:
branch_name = 'master'
gl_token = os.getenv('GITLAB_TOKEN')
if gl_token is None:
print('GITLAB_TOKEN not set!')
exit(1)
gl = gitlab.Gitlab('https://gitlab.com/', gl_token)
project = gl.projects.get(project_name)
branch = project.branches.get(branch_name)
top_commit = project.commits.get(branch.commit['short_id'])
if top_commit.last_pipeline['status'] == 'success':
print(top_commit.short_id)
else:
exit(1)
if __name__ == '__main__':
main()