pathpull-requestgithub-actions

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


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)


Solution

  • 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.

    We currently have to live with the duplication of having the lists in both places -- it's likely this 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