packit / packit.dev

packit.dev website content
https://packit.dev/
MIT License
9 stars 50 forks source link

A way to set specific branches triggered on push (commit). #664

Open junaruga opened 1 year ago

junaruga commented 1 year ago

Description

I want to run Packit as a service on push for the specific branches. I want to trigger any branches except master branch. Below is my current .packit.yml configuration. Is there a way to do it? I check the https://dashboard.packit.dev/pipelines page. But it seems nothing triggers in the push for a branch with the following configuration. Does the current branch: syntax support the regular expression?

jobs:
  - &copr
    job: copr_build
    trigger: pull_request
    enable_net: true
    targets:
      # https://packit.dev/docs/configuration/#available-copr-build-targets
      - fedora-rawhide-x86_64
      - fedora-rawhide-i386
      - fedora-rawhide-aarch64
      - fedora-rawhide-ppc64le
      - fedora-rawhide-s390x

  - <<: *copr
    # Run on push to any branch.
    trigger: commit

Benefit

Users can test their commit by running on CI before sending the PR to the target repository.

Importance

GitHub Actions have the feature to set the triggered branches using the wildcard by branches and branches-ignore syntax. https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#using-filters https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#example-excluding-branches

Workaround

Participation

mfocko commented 1 year ago

I have implemented a way to process regex for the branch option on trigger: commit. It was part of experiments with the merge queues on GitHub, so it is not yet documented and well tested.

I would suggest trying:

  - <<: *copr
    # Run on push to any branch.
    trigger: commit
    branch: '^(?!.*master)'
junaruga commented 1 year ago

Thanks for the suggestion. Why is it the branch: '^(?!.*master)' rather than branch: '^(?!master)'?

junaruga commented 1 year ago

Checking the Python regular expression syntax (?!...) at https://docs.python.org/3/library/re.html. If you trim the heading and tailing spaces of the value of the branch. I think we can omit the ^ in the '^(?!master)' too.

junaruga commented 1 year ago

I experimented.

$ python3 --version
Python 3.11.3

$ python3
...
>>> import re
>>> p = re.compile('^(?!master)')
>>> print(p.match('master'))
None
>>> print(p.match(' master'))
<re.Match object; span=(0, 0), match=''>
>>> print(p.match('amaster'))
<re.Match object; span=(0, 0), match=''>
>>> print(p.match('mastera'))
None
>>> import re
>>> p = re.compile('(?!master)')
>>> print(p.match('master'))
None
>>> print(p.match('amaster'))
<re.Match object; span=(0, 0), match=''>
>>> print(p.match(' master'))
<re.Match object; span=(0, 0), match=''>
>>> print(p.match('mastera'))
None
>>> print(p.match('master '))
None
junaruga commented 1 year ago

It seems I was able to run the CI on the push on a branch (wip/packit-copr-push). https://dashboard.packit.dev/results/copr-builds/810710

+    branch: '(?!master)'
mfocko commented 1 year ago

Thanks for letting me know, I'll transfer it to the repo with docs, so it can be properly documented.

ad the suggested regex, it was just a guess :)

junaruga commented 1 year ago

Okay. Thanks for implementing this!