How to factor `paths:` in common for push: and pull_request: in github actions?

Viewed 1794

I’d like to factor the common paths in this:

on:
  push:
    # Run only on changes on these files
    paths:
      - 'lib/**.nim'
      - 'doc/**.rst'
      - 'doc/nimdoc.css'
      - '.github/workflows/ci_docs.yml'

  pull_request:
    # Run only on changes on these files
    paths:
      - 'lib/**.nim'
      - 'doc/**.rst'
      - '.github/workflows/ci_docs.yml'

documentation on github mentions [push, pull_request] but it doesn’t work if we have paths node. What is the syntax to avoid code duplication?

(apologies in advance for cross posting with https://github.community/t/how-to-factor-paths-in-common-for-push-and-pull-request/115967, if I get any answer I'll update on the other end)

2 Answers

If I'm understanding your question correctly you're asking how to list common paths for multiple events, as in on both push and pull_request run for file paths lib/**.nim', 'doc/**.rst', '.github/workflows/ci_docs.yml' that's not currently possible.

Respectfully, it's not a lot of duplication to have the lists in both places, and it's likely that way for some implementation detail reason on GitHub's side of things.

Official docs if you want more reading: https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#onpushpull_requestpaths

here is an example that you might want to try. A similar approach is outlined in the documentation linked by @xandermonkey too.

on:
  push:
  pull_request:
    # Run only on changes on these files
    paths:
      - 'lib/**.nim'
      - 'doc/**.rst'
      - '.github/workflows/ci_docs.yml'
Related