Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
fregante opened this issue Nov 8, 2020 · 2 comments
Open

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

fregante opened this issue Nov 8, 2020 · 2 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fregante
Copy link
Owner

fregante commented Nov 8, 2020

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:

  • because env doesn't support arrays for example, and can't be used in strategy.matrix
  • some conditions could be pre-evaluated, so that whole steps/jobs could be dropped/added at merge time instead of just being silenced at run time.

Initially defined in sindresorhus/project-ideas#128

@fregante fregante added the enhancement New feature or request label Nov 8, 2020
@fregante fregante added the help wanted Extra attention is needed label Nov 8, 2020
@fregante
Copy link
Owner Author

fregante commented Nov 8, 2020

The user would:

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

This is essentially the same as #9, except that #9 refers to just loading the .github/workflows files.

@fregante
Copy link
Owner Author

fregante commented Nov 12, 2020

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

  • No limits

Cons

  • Verbose/complex
  • Who really needs this? 🤔

@fregante fregante unpinned this issue Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant