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

Enable reuse of GitHub Actions workflows somehow (completed 💚) #128

Closed
fregante opened this issue Oct 24, 2020 · 2 comments
Closed

Enable reuse of GitHub Actions workflows somehow (completed 💚) #128

fregante opened this issue Oct 24, 2020 · 2 comments

Comments

@fregante
Copy link

fregante commented Oct 24, 2020

Code reuse across workflows is impossible, we're copy-pasting across repositories and this isn't ok. I don't know when/if GitHub will allow workflow reuse like with GitHub Actions: actions/runner#748

Is this something that can be done in userland? For example:

# .github/workflows-template/test.yml
apply:
  name: fregante/gh-workflow-npm-test@hash124
  with: # If `gh-workflow-npm-test` has any custom/conditional features, `with` acts as parameters
    node-version: [8.x, 10.x, 12.x]
jobs:
  test:
    env:
      MY-COOL-ENV: an amazing project

or

jobs:
  test:
    name: Let's test stuff
    apply: fregante/gh-workflow-npm-test@hash124#jobs.test # It would only merge the specific jobs.test section
  build:
    needs: test
    steps:
      - run: echo My other steps

Then, on npm install or some other event, this module will:

  1. look files under .github/workflows-template/*.yml
  2. download the specified workflows from GitHub
  3. merge the user's template with the specified workflow(s), applying any special variables it expects like node-version
  4. save the merged workflow as .github/workflows/$1.yml

This is pretty simple, but I need your suggestions on when/how to ensure that .github/workflows/$1.yml is up to date:

  • via postinstall only?
  • git hooks?
@fregante
Copy link
Author

To appease the all-in-one package.json gods, this could also just be a property:

{
  "name": "is-odd",
  ...,
  "dependencies": {
    "gh-workflows": "^1.2.3"
  },
  "gh-workflows": {
    "test": "sindresorhus/workflows@v1/test.yml"
  }
}

@fregante
Copy link
Author

fregante commented Nov 8, 2020

ghat is here (GitHub Action Templates) 🎉

I imagined it first of all configuration-free so, given a repo with a source template, you'll be able to pull it in with no further local configuration. You can just run this in your repository now:

npx ghat fregante/ghat/templates/node

It would copy the workflow(s) from the fregante/ghat repo in the templates/node folder and apply a header with instructions.

To update it in the future, you just re-run the same command and commit the changes, if you like them.

This does away with any versioning/installation needs, because workflows can't change automatically.

@fregante fregante changed the title Enable reuse of GitHub Actions workflows somehow Enable reuse of GitHub Actions workflows somehow (completed 💚) Nov 10, 2020
@fregante fregante closed this as completed Nov 3, 2023
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

No branches or pull requests

1 participant