From 1369feba724177d0404f96e526d6403f9e8b5295 Mon Sep 17 00:00:00 2001 From: esc Date: Fri, 11 Apr 2025 11:34:08 +0200 Subject: [PATCH 1/2] adding README As title --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..fc30834 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# numba-gha + +Common code and utilities for using GitHub Actions (GHA) in Numba and related +projects. From 69957c2925dc2d79a9ba84cfacd03cb5cbf744e4 Mon Sep 17 00:00:00 2001 From: esc Date: Fri, 11 Apr 2025 12:32:27 +0200 Subject: [PATCH 2/2] add initial illustration of what a workflow generator could look like As title --- numba_gha.py | 105 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 numba_gha.py diff --git a/numba_gha.py b/numba_gha.py new file mode 100644 index 0000000..9917cc0 --- /dev/null +++ b/numba_gha.py @@ -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 * "-")