Skip to content

Conversation

@esc
Copy link
Member

@esc esc commented Apr 11, 2025

This is an initial prototype (or illustration) of what a meta-programming style generator for GitHub actions could look like. Basically the idea is to supply a static, declarative config of what the final workflow should look like and the meta-programming system then generates the appropriate yaml config. This allows very easy re-configuration, global updates across all workflows, isolated workflows for easy debugging and sharing of workflows generation across repositories.

I have supplied two approaches here that will allow us to evaluate the merits of each approach. First a dictionary/yaml style generator where the final config is specified in dictionary form and the final workflow string is generated using yaml.dump. The second is a f-string based approach that uses an f-string style template and then injects the correct variables into it. Both approaches have advantages and disadvantages. The dictionary style approach is more verbose and less readable, but you have more control about how and what is generated. For example, you could splice a dictionary together from sub-dictionaries, you can for-loop over stuff to generate dictionaries dynamically. The f-string approach is more readable initially as it is closer to the final config. But, it's less flexible: we can't for-loop inside the f-string template (unless we use fancy templating engines such as jinja) and we need escape any f-string syntax such as { and } -- which is prone to duplication errors.

Here is an example of running the provided script and the resulting output:

 💣 zsh» python numba_gha.py                                                                                                                                                                             
--------------------------------------------------------------------------------
yaml_generate
--------------------------------------------------------------------------------
name: numba_win-64_conda_builder
'on':
  pull-request:
    paths:
    - .github/workflows/numba_win-64_conda_builder.yml
  workflow_dispatch:
    inputs:
      artifact_run_id:
        description: artifact workflow run ID (optional)
        required: 'false'
        type: string
concurrency:
  group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.sha }}
  cancel-in-progress: true

--------------------------------------------------------------------------------
fstring_generate
--------------------------------------------------------------------------------

name: numba_win-64_conda_builder

on:
  pull_request:
    paths:
      - .github/workflows/numba_win-64_conda_builder.yml
  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

--------------------------------------------------------------------------------

Note that this is a proposal for discussion and not a final decision on anything. Let's circle back together and find a suitable solution that we feel confident about as a team before committing and implementing anything further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant