Skip to content

Commit c79b3ce

Browse files
committed
CI: convert galaxy version check to pre-commit + autodetect
1 parent 0c59cc8 commit c79b3ce

File tree

5 files changed

+57
-23
lines changed

5 files changed

+57
-23
lines changed

Diff for: .gitlab-ci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ before_script:
5757
needs:
5858
- pipeline-image
5959
- ci-not-authorized
60-
- check-galaxy-version # lint
6160
- pre-commit # lint
6261
- vagrant-validate # lint
6362

Diff for: .gitlab-ci/lint.yml

-10
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,3 @@ vagrant-validate:
2424
script:
2525
- ./tests/scripts/vagrant-validate.sh
2626
except: ['triggers', 'master']
27-
28-
29-
# TODO: convert to pre-commit hook
30-
check-galaxy-version:
31-
needs: []
32-
stage: test
33-
tags: [ffci]
34-
image: python:3
35-
script:
36-
- tests/scripts/check_galaxy_version.sh

Diff for: .pre-commit-config.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,14 @@ repos:
7070
- pathlib
7171
- pyaml
7272

73+
- id: check-galaxy-version
74+
name: Verify correct version for galaxy.yml
75+
entry: scripts/galaxy_version.py
76+
language: python
77+
pass_filenames: false
78+
additional_dependencies:
79+
- ruamel.yaml
80+
7381
- id: jinja-syntax-check
7482
name: jinja-syntax-check
7583
entry: tests/scripts/check-templates.py

Diff for: scripts/galaxy_version.py

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env python
2+
3+
import subprocess
4+
import ruamel.yaml
5+
import os
6+
7+
last_tag = (
8+
subprocess.Popen(
9+
["git", "describe", "--tags", "--abbrev=0"], stdout=subprocess.PIPE
10+
)
11+
.communicate()[0]
12+
.rstrip()
13+
.decode("utf-8")
14+
.removeprefix("v")
15+
.split(".")
16+
)
17+
# Use CI provided base ref if available, else use HEAD to guess
18+
git_branch = os.getenv(
19+
"GITHUB_BASE_REF",
20+
(
21+
subprocess.Popen(
22+
["git", "rev-parse", "--abbrev-ref", "HEAD"], stdout=subprocess.PIPE
23+
)
24+
.communicate()[0]
25+
.rstrip()
26+
.decode("utf-8")
27+
),
28+
)
29+
if git_branch.startswith("release"):
30+
version_comp_index = 2
31+
else:
32+
version_comp_index = 1
33+
34+
last_tag[version_comp_index] = str(int(last_tag[version_comp_index]) + 1)
35+
new_tag = ".".join(last_tag)
36+
37+
yaml = ruamel.yaml.YAML()
38+
yaml.indent(mapping=2, sequence=4, offset=2)
39+
yaml.explicit_start = True
40+
41+
with open(
42+
"galaxy.yml",
43+
) as galaxy_yml:
44+
config = yaml.load(galaxy_yml)
45+
46+
config["version"] = new_tag
47+
48+
with open("galaxy.yml", "w") as galaxy_yml:
49+
yaml.dump(config, galaxy_yml)

Diff for: tests/scripts/check_galaxy_version.sh

-12
This file was deleted.

0 commit comments

Comments
 (0)