Browse Source
CI: convert galaxy version check to pre-commit + autodetect
pull/12050/head
Max Gautier
6 months ago
Failed to extract signature
5 changed files with
57 additions and
23 deletions
-
.gitlab-ci.yml
-
.gitlab-ci/lint.yml
-
.pre-commit-config.yaml
-
scripts/galaxy_version.py
-
tests/scripts/check_galaxy_version.sh
|
|
@ -57,7 +57,6 @@ before_script: |
|
|
|
needs: |
|
|
|
- pipeline-image |
|
|
|
- ci-not-authorized |
|
|
|
- check-galaxy-version # lint |
|
|
|
- pre-commit # lint |
|
|
|
- vagrant-validate # lint |
|
|
|
|
|
|
|
|
|
@ -24,13 +24,3 @@ vagrant-validate: |
|
|
|
script: |
|
|
|
- ./tests/scripts/vagrant-validate.sh |
|
|
|
except: ['triggers', 'master'] |
|
|
|
|
|
|
|
|
|
|
|
# TODO: convert to pre-commit hook |
|
|
|
check-galaxy-version: |
|
|
|
needs: [] |
|
|
|
stage: test |
|
|
|
tags: [ffci] |
|
|
|
image: python:3 |
|
|
|
script: |
|
|
|
- tests/scripts/check_galaxy_version.sh |
|
|
@ -70,6 +70,14 @@ repos: |
|
|
|
- pathlib |
|
|
|
- pyaml |
|
|
|
|
|
|
|
- id: check-galaxy-version |
|
|
|
name: Verify correct version for galaxy.yml |
|
|
|
entry: scripts/galaxy_version.py |
|
|
|
language: python |
|
|
|
pass_filenames: false |
|
|
|
additional_dependencies: |
|
|
|
- ruamel.yaml |
|
|
|
|
|
|
|
- id: jinja-syntax-check |
|
|
|
name: jinja-syntax-check |
|
|
|
entry: tests/scripts/check-templates.py |
|
|
|
|
|
@ -0,0 +1,49 @@ |
|
|
|
#!/usr/bin/env python |
|
|
|
|
|
|
|
import subprocess |
|
|
|
import ruamel.yaml |
|
|
|
import os |
|
|
|
|
|
|
|
last_tag = ( |
|
|
|
subprocess.Popen( |
|
|
|
["git", "describe", "--tags", "--abbrev=0"], stdout=subprocess.PIPE |
|
|
|
) |
|
|
|
.communicate()[0] |
|
|
|
.rstrip() |
|
|
|
.decode("utf-8") |
|
|
|
.removeprefix("v") |
|
|
|
.split(".") |
|
|
|
) |
|
|
|
# Use CI provided base ref if available, else use HEAD to guess |
|
|
|
git_branch = os.getenv( |
|
|
|
"GITHUB_BASE_REF", |
|
|
|
( |
|
|
|
subprocess.Popen( |
|
|
|
["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE |
|
|
|
) |
|
|
|
.communicate()[0] |
|
|
|
.rstrip() |
|
|
|
.decode("utf-8") |
|
|
|
), |
|
|
|
) |
|
|
|
if git_branch.startswith("release"): |
|
|
|
version_comp_index = 2 |
|
|
|
else: |
|
|
|
version_comp_index = 1 |
|
|
|
|
|
|
|
last_tag[version_comp_index] = str(int(last_tag[version_comp_index]) + 1) |
|
|
|
new_tag = ".".join(last_tag) |
|
|
|
|
|
|
|
yaml = ruamel.yaml.YAML() |
|
|
|
yaml.indent(mapping=2, sequence=4, offset=2) |
|
|
|
yaml.explicit_start = True |
|
|
|
|
|
|
|
with open( |
|
|
|
"galaxy.yml", |
|
|
|
) as galaxy_yml: |
|
|
|
config = yaml.load(galaxy_yml) |
|
|
|
|
|
|
|
config["version"] = new_tag |
|
|
|
|
|
|
|
with open("galaxy.yml", "w") as galaxy_yml: |
|
|
|
yaml.dump(config, galaxy_yml) |
|
|
@ -1,12 +0,0 @@ |
|
|
|
#!/bin/bash |
|
|
|
set -e |
|
|
|
|
|
|
|
version_from_galaxy=$(grep "^version:" galaxy.yml | awk '{print $2}') |
|
|
|
|
|
|
|
# TODO: compute the next expected version somehow |
|
|
|
if [[ $KUBESPRAY_VERSION == "v${version_from_galaxy}" ]] |
|
|
|
then |
|
|
|
echo "Please update galaxy.yml version to match the next KUBESPRAY_VERSION." |
|
|
|
echo "Be sure to remove the \"v\" to adhere to semantic versioning" |
|
|
|
exit 1 |
|
|
|
fi |