Skip to content

Commit 3636ca1

Browse files
committed
feat(pre-commit): adds linting and diamond compliance checks to pre-commit
1 parent f2bbe7f commit 3636ca1

13 files changed

Lines changed: 381 additions & 6 deletions

File tree

.github/workflows/_tox.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
description: What to run under tox
77
required: true
88

9-
109
jobs:
1110
run:
1211
runs-on: "ubuntu-latest"
@@ -18,5 +17,12 @@ jobs:
1817
- name: Install uv
1918
uses: astral-sh/setup-uv@v7
2019

20+
- name: Install Argo
21+
run: |
22+
curl -sLO https://github.com/argoproj/argo-workflows/releases/download/v4.0.6/argo-linux-amd64.gz
23+
gunzip argo-linux-amd64.gz
24+
chmod +x argo-linux-amd64
25+
sudo mv argo-linux-amd64 /usr/local/bin/argo
26+
2127
- name: Run tox
2228
run: uv run --locked tox -e ${{ inputs.tox }}

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,30 @@ repos:
1717
types: [python]
1818
require_serial: true
1919

20+
- id: create-workflow-templates
21+
name: creates workflow templates
22+
language: system
23+
entry: bash runthefiles
24+
types: [python]
25+
pass_filenames: true
26+
require_serial: true
27+
28+
- id: confirm-diamond-compatability
29+
name: ensure yaml is diamond-compatible
30+
language: system
31+
entry: python checkyamlcompliance
32+
types: [yaml]
33+
pass_filenames: true
34+
require_serial: true
35+
36+
- id: lint-yaml-files
37+
name: run argo lint on the yaml files
38+
language: system
39+
entry: bash lintyaml
40+
types: [yaml]
41+
pass_filenames: true
42+
require_serial: true
43+
2044
- id: ruff-format
2145
name: format with ruff
2246
language: system

Dockerfile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,13 @@ RUN curl -sLO "https://github.com/argoproj/argo-workflows/releases/download/v4.0
1010
RUN gunzip "argo-linux-amd64.gz"
1111
RUN chmod +x "argo-linux-amd64"
1212
RUN mv "./argo-linux-amd64" /usr/local/bin/argo
13+
# Source - https://stackoverflow.com/a/53749426
14+
# Posted by Alain Gauthier
15+
# Retrieved 2026-06-25, License - CC BY-SA 4.0
16+
#change to proper kubectl intstaller
17+
RUN curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl"
18+
RUN chmod +x ./kubectl
19+
RUN mv ./kubectl /usr/local/bin
1320

1421
# The build stage installs the context into the venv
1522
FROM developer AS build

checkyamlcompliance

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/bin/python
2+
import os
3+
import re
4+
5+
yamlpath = "src/python_interface_to_workflows/templates/"
6+
yamllist: list[str] = []
7+
for x in os.listdir(yamlpath):
8+
if x.endswith(".yaml"):
9+
yamllist.append(x)
10+
11+
for file in yamllist:
12+
x = 0
13+
y = 0
14+
z = 0
15+
with open(yamlpath + file) as s:
16+
filelist = s.readlines()
17+
cleanfilenames: list[str] = []
18+
for line in filelist:
19+
line = line.rstrip()
20+
cleanfilenames.append(line)
21+
required_labels: list[str] = [
22+
r"apiVersion:\sargoproj\.io\/v1alpha",
23+
r"kind:\sClusterWorkflowTemplate",
24+
r"metadata:",
25+
r"\s\sannotations:",
26+
r"\s\s\s\sworkflows.argoproj.io/title:\s.+",
27+
r"\s\s\s\sworkflows.diamond.ac.uk/repository:\s.+",
28+
r"\s\slabels:",
29+
r"\s\s\s\sworkflows.diamond.ac.uk/science-group-.+:\s.+",
30+
]
31+
for x in range(0, len(required_labels)):
32+
for y in range(0, len(cleanfilenames)):
33+
if re.match(required_labels[x], cleanfilenames[y]):
34+
print(required_labels[x])
35+
z += 1
36+
37+
gen_name = any(re.search(r"\s\sgenerateName:\s.+", line) for line in cleanfilenames)
38+
normal_name = any(re.search(r"^\s\sname:\s.+", line) for line in cleanfilenames)
39+
if gen_name and not normal_name:
40+
z += 1
41+
elif normal_name and not gen_name:
42+
z += 1
43+
else:
44+
z -= 1
45+
46+
if z == 9:
47+
exit(0)
48+
else:
49+
print("Error! missing a label or name!")
50+
exit(1)

lintyaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
cd src/python_interface_to_workflows/templates
3+
for file in *
4+
do
5+
argo lint "$file" --offline
6+
SUCCESSFULLINT=$?
7+
[ $SUCCESSFULLINT -ne 0 ] && exit 1
8+
done
9+
exit 0

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ description = " Python alternative to creating and running argo workflows in the
1616
dependencies = [
1717
"gql",
1818
"aiohttp",
19+
"hera",
20+
"requests",
1921
] # Add project dependencies here, e.g. ["click", "numpy"]
2022
dynamic = ["version"]
2123
license.file = "LICENSE"

runthefiles

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/bash
2+
cd src/python_interface_to_workflows/workflow_definitions
3+
for file in *
4+
do
5+
uv run "$file"
6+
done
7+
mv *.yaml ../templates/
8+
git add -u ../templates/

src/.env

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"HOST" = "https://argo-workflows.staging.workflows.diamond.ac.uk/"
2+
"IMAGE" = "python:3.10"
3+
"TOKEN" = "Token"
File renamed without changes.

src/python_interface_to_workflows/submit_to_graphql.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ def submit_to_graphql():
1414
mutation = gql("""
1515
mutation SubmitDivision {
1616
submitWorkflowTemplate(
17-
name: "division"
17+
name: "division.yaml"
1818
visit: {
1919
proposalCode: "ks",
2020
proposalNumber: 10000,
2121
number: 3
2222
}
23-
parameters: {
24-
numinput: "19",
25-
numdivisor: "10"
26-
}
23+
parameters: {
24+
numinput: "19",
25+
numdivisor: "10"
26+
}
2727
){
2828
name
2929
}

0 commit comments

Comments
 (0)