Skip to content

Commit aeba0a6

Browse files
committed
Merge remote-tracking branch 'origin/main' into 32-add-timeout-to-requeststhreads
2 parents f03482a + eb12e0e commit aeba0a6

File tree

9 files changed

+510
-118
lines changed

9 files changed

+510
-118
lines changed

.github/branch-protection.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
required_status_checks:
2+
strict: true
3+
4+
contexts:
5+
- "Lint and Format Check"
6+
7+
require_branches_up_to_date: true

.github/workflows/build-and-publish.yml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,42 @@ env:
1515
REGISTRY_PASSWORD: ${{ github.token }}
1616

1717
jobs:
18+
lint:
19+
name: Lint and Format Check
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
outputs:
24+
success: ${{ steps.lint.outputs.success }}
25+
26+
steps:
27+
- name: Checkout repository
28+
uses: actions/checkout@v4
29+
30+
- name: Setup Python
31+
uses: actions/setup-python@v4
32+
with:
33+
python-version: "3.11"
34+
35+
- name: Install ruff
36+
run: pip install ruff
37+
38+
- name: Run linting
39+
id: lint
40+
run: |
41+
echo "Running ruff check..."
42+
ruff check . --output-format=github
43+
44+
echo "Running ruff format check..."
45+
ruff format --check .
46+
47+
echo "success=true" >> $GITHUB_OUTPUT
48+
1849
build-and-push-image:
50+
name: Build and Push Docker Image
1951
runs-on: ubuntu-latest
52+
needs: [lint]
53+
if: needs.lint.outputs.success == 'true'
2054
permissions:
2155
contents: read
2256
packages: write
@@ -43,7 +77,7 @@ jobs:
4377
type=ref,event=tag
4478
type=ref,event=pr
4579
type=sha,format=long
46-
80+
4781
- name: Build and push Docker image
4882
uses: docker/build-push-action@91df6b874e498451163feb47610c87c4a218c1ee
4983
with:

KubernetesLogFormatter.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
1-
import json
2-
import os
31
import logging
2+
import os
3+
44

55
def get_kubernetes_namespace():
66
namespace_file = "/var/run/secrets/kubernetes.io/serviceaccount/namespace"
77
try:
8-
with open(namespace_file, "r") as f:
8+
with open(namespace_file) as f:
99
namespace = f.read().strip()
1010
return namespace
1111
except FileNotFoundError:
1212
return "Namespace file not found"
1313
except Exception as e:
1414
return f"Error reading namespace: {e}"
1515

16+
1617
class KubernetesLogFormatter(logging.Formatter):
1718
def format(self, record):
1819
timestamp = self.formatTime(record, self.datefmt or "%Y-%m-%d %H:%M:%S")
1920
level = record.levelname
2021
message = record.getMessage()
21-
pod_name = os.getenv('HOSTNAME', 'unknown-pod')
22+
pod_name = os.getenv("HOSTNAME", "unknown-pod")
2223
namespace = get_kubernetes_namespace()
2324

24-
return f"[{timestamp}] [{level}] [{namespace}/{pod_name}] {message}"
25+
return f"[{timestamp}] [{level}] [{namespace}/{pod_name}] {message}"

RunningJob.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
from typing import List
22

3+
34
class RunningJob:
4-
def __init__(self, repo: str, job_id: int, slurm_job_id: int, workflow_name: str, job_name: str, labels: List[str]):
5+
def __init__(
6+
self,
7+
repo: str,
8+
job_id: int,
9+
slurm_job_id: int,
10+
workflow_name: str,
11+
job_name: str,
12+
labels: List[str],
13+
):
514
"""Class to represent a running Github Actions Job on Slurm."""
615
self.repo = repo
716
self.job_id = job_id
@@ -11,9 +20,11 @@ def __init__(self, repo: str, job_id: int, slurm_job_id: int, workflow_name: str
1120
self.labels = labels
1221

1322
def __str__(self) -> str:
14-
return (f"RunningJob(job_id = {self.job_id}, slurm_job_id = {self.slurm_job_id}, "
15-
f"workflow_name = {self.workflow_name}, "
16-
f"job_name = {self.job_name}, labels = {self.labels})")
17-
23+
return (
24+
f"RunningJob(job_id = {self.job_id}, slurm_job_id = {self.slurm_job_id}, "
25+
f"workflow_name = {self.workflow_name}, "
26+
f"job_name = {self.job_name}, labels = {self.labels})"
27+
)
28+
1829
def __repr__(self) -> str:
19-
return self.__str__()
30+
return self.__str__()

config.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
GITHUB_API_BASE_URL = 'https://api.github.com/repos/WATonomous/infra-config'
2-
GITHUB_REPO_URL = 'https://github.com/WATonomous/infra-config'
3-
ALLOCATE_RUNNER_SCRIPT_PATH = "apptainer.sh" # relative path from '/allocation_script'
1+
GITHUB_API_BASE_URL = "https://api.github.com/repos/WATonomous/infra-config"
2+
GITHUB_REPO_URL = "https://github.com/WATonomous/infra-config"
3+
ALLOCATE_RUNNER_SCRIPT_PATH = "apptainer.sh" # relative path from '/allocation_script'
44

55
# Timeout configurations
66
NETWORK_TIMEOUT = 30 # seconds for HTTP requests (GitHub API calls)
@@ -9,8 +9,8 @@
99

1010
REPOS_TO_MONITOR = [
1111
{
12-
'name': 'WATonomous/infra-config',
13-
'api_base_url': 'https://api.github.com/repos/WATonomous/infra-config',
14-
'repo_url': 'https://github.com/WATonomous/infra-config'
12+
"name": "WATonomous/infra-config",
13+
"api_base_url": "https://api.github.com/repos/WATonomous/infra-config",
14+
"repo_url": "https://github.com/WATonomous/infra-config",
1515
},
1616
]

0 commit comments

Comments
 (0)