Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# numba-gha

Common code and utilities for using GitHub Actions (GHA) in Numba and related
projects.
105 changes: 105 additions & 0 deletions numba_gha.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
from dataclasses import dataclass
import textwrap

import yaml

# constants

# projects
NUMBA = "numba"
LLVMLITE = "llvmlite"
LLVMDVE = "llvmdev"

# architectures
WIN_64 = "win-64"
LINUX_64 = "linux-64"

# package flavours
CONDA = "conda"
WHEEL = "wheel"

# snippets

concurrency = textwrap.dedent("""
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
cancel-in-progress: true
""")

# configuration classes

@dataclass
class AbstractCondaBuilder:
""" Abstract config generator. """

def yaml_generate(self):
config = \
{"name": self.name,
"on": {
"pull-request": {
"paths": [self.path],
},
"workflow_dispatch" : {
"inputs": {
"artifact_run_id": {
"description": 'artifact workflow run ID (optional)',
"required": "false",
"type": "string",
}
}
}
}
}
config.update(yaml.safe_load(concurrency))
return yaml.dump(config,
default_flow_style=False,
sort_keys=False,
width=float("inf"),
)

def fstring_generate(self):
config = textwrap.dedent(f"""
name: {self.name}

on:
pull_request:
paths:
- {self.path}
workflow_dispatch:
inputs:
llvmlite_run_id:
description: 'llvmlite workflow run ID (optional)'
required: false
type: string

# Add concurrency control
concurrency:
group: ${{{{ github.workflow }}}}-${{{{ github.event.pull_request.number || github.sha }}}}
cancel-in-progress: true
""")
return config

@dataclass
class NumbaWin64CondaBuilder(AbstractCondaBuilder):
""" Concrete config for building conda packages on Win-64 for Numba. """
repo: str = NUMBA
arch: str = WIN_64
pack: str = CONDA

@property
def name(self):
return f"{self.repo}_{self.arch}_{self.pack}_builder"

@property
def path(self):
return f".github/workflows/{self.name}.yml"

print(80 * "-")
print("yaml_generate")
print(80 * "-")
print(NumbaWin64CondaBuilder().yaml_generate())
print(80 * "-")
print("fstring_generate")
print(80 * "-")
print(NumbaWin64CondaBuilder().fstring_generate())
print(80 * "-")