diff options
author | talyz <kim.lindberger@gmail.com> | 2019-10-08 15:52:11 +0200 |
---|---|---|
committer | talyz <kim.lindberger@gmail.com> | 2019-10-08 15:52:11 +0200 |
commit | afa3abf632a07a627a651ae7f8fdaad0c6e8919b (patch) | |
tree | 5e6639d8b0ef8ba7ac59a2c9d2c3e3a1f3867cd6 /pkgs/applications/version-management/gitlab/update.py | |
parent | 59324d1fb9d7deddcec3e7a4db705567880ca59c (diff) | |
download | nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.tar nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.tar.gz nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.tar.bz2 nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.tar.lz nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.tar.xz nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.tar.zst nixpkgs-afa3abf632a07a627a651ae7f8fdaad0c6e8919b.zip |
gitlab: Refactor for new repo structure
GitLab recently restructured their repos; whereas previously they had one gitlab-ce and one gitlab-ee repo, they're now one and the same. All proprietary components are put into the ee subdirectory - removing it gives us the foss / community version of GitLab. For more info, see https://about.gitlab.com/2019/02/21/merging-ce-and-ee-codebases/ This gives us the opportunity to simplify things quite a bit, since we don't have to keep track of two separate versions of either the base data or rubyEnv.
Diffstat (limited to 'pkgs/applications/version-management/gitlab/update.py')
-rwxr-xr-x | pkgs/applications/version-management/gitlab/update.py | 101 |
1 files changed, 33 insertions, 68 deletions
diff --git a/pkgs/applications/version-management/gitlab/update.py b/pkgs/applications/version-management/gitlab/update.py index 7b6afebcd97..38acf41c6f2 100755 --- a/pkgs/applications/version-management/gitlab/update.py +++ b/pkgs/applications/version-management/gitlab/update.py @@ -20,7 +20,7 @@ logger = logging.getLogger(__name__) class GitLabRepo: version_regex = re.compile(r"^v\d+\.\d+\.\d+(\-rc\d+)?(\-ee)?") - def __init__(self, owner: str, repo: str): + def __init__(self, owner: str = 'gitlab-org', repo: str = 'gitlab'): self.owner = owner self.repo = repo @@ -68,7 +68,7 @@ class GitLabRepo: """ return requests.get(self.url + f"/raw/{rev}/{filepath}").text - def get_data(self, rev, flavour): + def get_data(self, rev): version = self.rev2version(rev) passthru = {v: self.get_file(v, rev).strip() for v in ['GITALY_SERVER_VERSION', 'GITLAB_PAGES_VERSION', @@ -81,34 +81,6 @@ class GitLabRepo: passthru=passthru) -def _flavour2gitlabrepo(flavour: str): - if flavour not in ['ce', 'ee']: - raise Exception(f"unknown gitlab flavour: {flavour}, needs to be ce or ee") - - owner = 'gitlab-org' - if flavour == 'ce': - repo = 'gitlab-foss' - else: - repo = 'gitlab' - - return GitLabRepo(owner, repo) - - -def _update_data_json(filename: str, repo: GitLabRepo, rev: str, flavour: str): - flavour_data = repo.get_data(rev, flavour) - - if not os.path.exists(filename): - with open(filename, 'w') as f: - json.dump({flavour: flavour_data}, f, indent=2) - else: - with open(filename, 'r+') as f: - data = json.load(f) - data[flavour] = flavour_data - f.seek(0) - f.truncate() - json.dump(data, f, indent=2) - - def _get_data_json(): data_file_path = pathlib.Path(__file__).parent / 'data.json' with open(data_file_path, 'r') as f: @@ -129,44 +101,39 @@ def cli(): @cli.command('update-data') @click.option('--rev', default='latest', help='The rev to use, \'latest\' points to the latest (stable) tag') -@click.argument('flavour') -def update_data(rev: str, flavour: str): - """Update data.nix for a selected flavour""" - r = _flavour2gitlabrepo(flavour) +def update_data(rev: str): + """Update data.nix""" + repo = GitLabRepo() if rev == 'latest': # filter out pre and re releases - rev = next(filter(lambda x: not ('rc' in x or x.endswith('pre')), r.tags)) + rev = next(filter(lambda x: not ('rc' in x or x.endswith('pre')), repo.tags)) logger.debug(f"Using rev {rev}") - version = r.rev2version(rev) + version = repo.rev2version(rev) logger.debug(f"Using version {version}") data_file_path = pathlib.Path(__file__).parent / 'data.json' - _update_data_json(filename=data_file_path.as_posix(), - repo=r, - rev=rev, - flavour=flavour) + data = repo.get_data(rev) + with open(data_file_path.as_posix(), 'w') as f: + json.dump(data, f, indent=2) -@cli.command('update-rubyenv') -@click.argument('flavour') -def update_rubyenv(flavour): - """Update rubyEnv-${flavour}""" - if flavour not in ['ce', 'ee']: - raise Exception(f"unknown gitlab flavour: {flavour}, needs to be ce or ee") - r = _flavour2gitlabrepo(flavour) - rubyenv_dir = pathlib.Path(__file__).parent / f"rubyEnv-{flavour}" +@cli.command('update-rubyenv') +def update_rubyenv(): + """Update rubyEnv""" + repo = GitLabRepo() + rubyenv_dir = pathlib.Path(__file__).parent / f"rubyEnv" # load rev from data.json data = _get_data_json() - rev = data[flavour]['rev'] + rev = data['rev'] for fn in ['Gemfile.lock', 'Gemfile']: with open(rubyenv_dir / fn, 'w') as f: - f.write(r.get_file(fn, rev)) + f.write(repo.get_file(fn, rev)) subprocess.check_output(['bundix'], cwd=rubyenv_dir) @@ -175,13 +142,12 @@ def update_rubyenv(flavour): def update_yarnpkgs(): """Update yarnPkgs""" - # yarn.lock is identical between the repos - repo = _flavour2gitlabrepo('ee') + repo = GitLabRepo() yarnpkgs_dir = pathlib.Path(__file__).parent # load rev from data.json data = _get_data_json() - rev = data['ee']['rev'] + rev = data['rev'] with open(yarnpkgs_dir / 'yarn.lock', 'w') as f: f.write(repo.get_file('yarn.lock', rev)) @@ -196,17 +162,17 @@ def update_yarnpkgs(): def update_gitaly(): """Update gitaly""" data = _get_data_json() - gitaly_server_version = data['ce']['passthru']['GITALY_SERVER_VERSION'] - r = GitLabRepo('gitlab-org', 'gitaly') + gitaly_server_version = data['passthru']['GITALY_SERVER_VERSION'] + repo = GitLabRepo(repo='gitaly') gitaly_dir = pathlib.Path(__file__).parent / 'gitaly' for fn in ['Gemfile.lock', 'Gemfile']: with open(gitaly_dir / fn, 'w') as f: - f.write(r.get_file(f"ruby/{fn}", f"v{gitaly_server_version}")) + f.write(repo.get_file(f"ruby/{fn}", f"v{gitaly_server_version}")) for fn in ['go.mod', 'go.sum']: with open(gitaly_dir / fn, 'w') as f: - f.write(r.get_file(fn, f"v{gitaly_server_version}")) + f.write(repo.get_file(fn, f"v{gitaly_server_version}")) subprocess.check_output(['bundix'], cwd=gitaly_dir) subprocess.check_output(['vgo2nix'], cwd=gitaly_dir) @@ -221,19 +187,19 @@ def update_gitaly(): def update_gitlab_shell(): """Update gitlab-shell""" data = _get_data_json() - gitlab_shell_version = data['ce']['passthru']['GITLAB_SHELL_VERSION'] + gitlab_shell_version = data['passthru']['GITLAB_SHELL_VERSION'] _call_update_source_version('gitlab-shell', gitlab_shell_version) - r = GitLabRepo('gitlab-org', 'gitlab-shell') + repo = GitLabRepo(repo='gitlab-shell') gitlab_shell_dir = pathlib.Path(__file__).parent / 'gitlab-shell' for fn in ['Gemfile.lock', 'Gemfile']: with open(gitlab_shell_dir / fn, 'w') as f: - f.write(r.get_file(fn, f"v{gitlab_shell_version}")) + f.write(repo.get_file(fn, f"v{gitlab_shell_version}")) for fn in ['go.mod', 'go.sum']: with open(gitlab_shell_dir / fn, 'w') as f: - f.write(r.get_file(f"go/{fn}", f"v{gitlab_shell_version}")) + f.write(repo.get_file(f"go/{fn}", f"v{gitlab_shell_version}")) subprocess.check_output(['bundix'], cwd=gitlab_shell_dir) subprocess.check_output(['vgo2nix'], cwd=gitlab_shell_dir) @@ -246,15 +212,15 @@ def update_gitlab_shell(): def update_gitlab_workhorse(): """Update gitlab-workhorse""" data = _get_data_json() - gitlab_workhorse_version = data['ce']['passthru']['GITLAB_WORKHORSE_VERSION'] + gitlab_workhorse_version = data['passthru']['GITLAB_WORKHORSE_VERSION'] _call_update_source_version('gitlab-workhorse', gitlab_workhorse_version) - r = GitLabRepo('gitlab-org', 'gitlab-workhorse') + repo = GitLabRepo('gitlab-org', 'gitlab-workhorse') gitlab_workhorse_dir = pathlib.Path(__file__).parent / 'gitlab-workhorse' for fn in ['go.mod', 'go.sum']: with open(gitlab_workhorse_dir / fn, 'w') as f: - f.write(r.get_file(fn, f"v{gitlab_workhorse_version}")) + f.write(repo.get_file(fn, f"v{gitlab_workhorse_version}")) subprocess.check_output(['vgo2nix'], cwd=gitlab_workhorse_dir) @@ -264,10 +230,9 @@ def update_gitlab_workhorse(): @cli.command('update-all') @click.pass_context def update_all(ctx): - """Update gitlab ce and ee data.nix and rubyenvs to the latest stable release""" - for flavour in ['ce', 'ee']: - ctx.invoke(update_data, rev='latest', flavour=flavour) - ctx.invoke(update_rubyenv, flavour=flavour) + """Update all gitlab components to the latest stable release""" + ctx.invoke(update_data, rev='latest') + ctx.invoke(update_rubyenv) ctx.invoke(update_yarnpkgs) ctx.invoke(update_gitaly) ctx.invoke(update_gitlab_shell) |