CI: convert galaxy version check to pre-commit + autodetect

This commit is contained in:
Max Gautier
2025-03-17 18:02:58 +01:00
parent 0c59cc84dd
commit c79b3ce46b
5 changed files with 57 additions and 23 deletions

View File

@@ -57,7 +57,6 @@ before_script:
needs: needs:
- pipeline-image - pipeline-image
- ci-not-authorized - ci-not-authorized
- check-galaxy-version # lint
- pre-commit # lint - pre-commit # lint
- vagrant-validate # lint - vagrant-validate # lint

View File

@@ -24,13 +24,3 @@ vagrant-validate:
script: script:
- ./tests/scripts/vagrant-validate.sh - ./tests/scripts/vagrant-validate.sh
except: ['triggers', 'master'] 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

View File

@@ -70,6 +70,14 @@ repos:
- pathlib - pathlib
- pyaml - 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 - id: jinja-syntax-check
name: jinja-syntax-check name: jinja-syntax-check
entry: tests/scripts/check-templates.py entry: tests/scripts/check-templates.py

49
scripts/galaxy_version.py Executable file
View File

@@ -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)

View File

@@ -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