Is it possible to generate the yaml metadata file dynamically?

As titled, I’d like to take advantage of (Kotlin) DSL to automatically generate the yaml metadata file to run on Github Action.

I can do this offline and then push, but I was wondering if it’s possible to automatize somehow the process, like having a dedicated Github Action which run the script, which generate the metadata that will be parsed next

1 Like

I have done it like this with nodejs:

I write my temporary action.yml to a fixed location, then I run the generated yaml file via uses (local action).
As far I know you can override this temporary action.yml after it’s last run without causing errors.

It would be better if this feature would be implemented (Local composite actions always relative to top level repository · Issue #1348 · actions/runner · GitHub), because this might allow to avoid writing to your workspace or choose a temporary path at runtime.

Hello Christopher,

sorry but I didn’t get it completely.

So, that yaml will execute the script, which in turns creates a directory under ./.github/conditional/tmp and then write to action.yaml the corresponding content.

The new action.yaml will be later on run with
- uses: ./.github/conditional/tmp

My questions are:

  • do I need the input and run?
  • can I run this with on: [ push]?


do I need the input and run ?

No. This is a composite action, which writes a different action.yaml depending on the input you don’t need to do that.

can I run this with on: [ push] ?

Yes, just move the steps into your job, like this

on: [push]
    runs-on: ubuntu-latest
    - uses: actions/github-script@v4
        github-token: none
        script: |
          var fs = require('fs');
          try {
            fs.mkdirSync('./.github/conditional/tmp', {recursive: true});
          } catch {
          fs.writeFileSync('./.github/conditional/tmp/action.yml', 'runs: {using: composite, steps: []}');
    - uses: ./.github/conditional/tmp

I get:

Error: Top level ‘runs:’ section is required for /home/runner/work/kotlin-unsigned/kotlin-unsigned/./.github/conditional/tmp/action.yml

I guess a composite is mandatory…

Edit: I think it’s possible to compose only actions and not workflows, which is what I need instead…

I’ve done it but with manual steps. Here’s a sample of what it kind of looks like: GitHub - dorner/gha-config

With this flow you have to remember to run the command before you commit (you can add a pre-commit hook for example).