fregante / ghat

šŸ›• Reuse GitHub Actions workflows across repositories
https://npm.im/ghat
MIT License
264 stars 9 forks source link

Allow definition/setup via local template instead of cli #4

Open fregante opened 3 years ago

fregante commented 3 years ago

Currently the only customization possible is via the global env property, but unfortunately this isn't available everywhere in the workflow and can't be used to customize a workflow template.

I foresee a few ways to reuse existing templates:

Plain merging of a local template (e.g. .github/workflows-ghat/ci.yml) with the remote template

# Fetch template
apply: fregante/ghat/templates/node

# Overwrite existing `on` property with
on:
  - push

Importing single jobs

on:
  - push
jobs:
  test:
    name: Let's test stuff
    apply: fregante/ghat/templates/node#jobs.test # It would only merge the specific jobs.test section
  build:
    needs: test
    steps:
      - run: echo My other steps

An advanced way to customize the templates

For example it could apply some ENVs at merge time like GitHub does with the $default-branch variable:


Initially defined in https://github.com/sindresorhus/project-ideas/issues/128

fregante commented 3 years ago

The user would:

  1. Create the files in .github/workflows-ghat
  2. Run $ ghat without any input

This is essentially the same as https://github.com/fregante/ghat/issues/9, except that https://github.com/fregante/ghat/issues/9 refers to just loading the .github/workflows files.

fregante commented 3 years ago

Alternative idea: The "local template" could just be a .js module that can do anything:

// In ghat
require('./.github/workflows/ghat.js'); // if it exists
// In local .github/workflows/ghat.js
const ghat = require('ghat');
(async () => {
    const myWorkflow = await ghat.get('fregante/ghatemplates/file.yml');
    myWorkflow.name = 'Coolio';
    await ghat.save('ci.yml', myWorkflow);
})();

Pros

Cons