diff mbox series

[PULL,32/33] gitlab: don't run CI jobs in forks by default

Message ID 20220601180537.2329566-33-alex.bennee@linaro.org
State New
Headers show
Series [PULL,01/33] .gitlab-ci.d/container-cross: Fix RISC-V container dependencies / stages | expand

Commit Message

Alex Bennée June 1, 2022, 6:05 p.m. UTC
From: Daniel P. Berrangé <berrange@redhat.com>

To preserve CI shared runner credits we don't want to run
pipelines on every push.

This sets up the config so that pipelines are never created
for contributors by default. To override this the QEMU_CI
variable can be set to a non-zero value. If set to 1, the
pipeline will be created but all jobs will remain manually
started. The contributor can selectively run jobs that they
care about. If set to 2, the pipeline will be created and
all jobs will immediately start.

This behavior can be controlled using push variables

  git push -o ci.variable=QEMU_CI=1

To make this more convenient define an alias

   git config --local alias.push-ci "push -o ci.variable=QEMU_CI=1"
   git config --local alias.push-ci-now "push -o ci.variable=QEMU_CI=2"

Which lets you run

  git push-ci

to create the pipeline, or

  git push-ci-now

to create and run the pipeline

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Message-Id: <20220526110705.59952-6-berrange@redhat.com>
[AJB: fix typo, replicate alias tips in ci.rst]
Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20220527153603.887929-33-alex.bennee@linaro.org>

Comments

Philippe Mathieu-Daudé June 2, 2022, 10:50 a.m. UTC | #1
Cc'ing qemu-stable@

Thank you Daniel / Thomas / Alex!

On 1/6/22 20:05, Alex Bennée wrote:
> From: Daniel P. Berrangé <berrange@redhat.com>
> 
> To preserve CI shared runner credits we don't want to run
> pipelines on every push.
> 
> This sets up the config so that pipelines are never created
> for contributors by default. To override this the QEMU_CI
> variable can be set to a non-zero value. If set to 1, the
> pipeline will be created but all jobs will remain manually
> started. The contributor can selectively run jobs that they
> care about. If set to 2, the pipeline will be created and
> all jobs will immediately start.
> 
> This behavior can be controlled using push variables
> 
>    git push -o ci.variable=QEMU_CI=1
> 
> To make this more convenient define an alias
> 
>     git config --local alias.push-ci "push -o ci.variable=QEMU_CI=1"
>     git config --local alias.push-ci-now "push -o ci.variable=QEMU_CI=2"
> 
> Which lets you run
> 
>    git push-ci
> 
> to create the pipeline, or
> 
>    git push-ci-now
> 
> to create and run the pipeline
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> Message-Id: <20220526110705.59952-6-berrange@redhat.com>
> [AJB: fix typo, replicate alias tips in ci.rst]
> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> Reviewed-by: Thomas Huth <thuth@redhat.com>
> Message-Id: <20220527153603.887929-33-alex.bennee@linaro.org>
> 
> diff --git a/docs/devel/ci-jobs.rst.inc b/docs/devel/ci-jobs.rst.inc
> index 0b4926e537..9118a61a17 100644
> --- a/docs/devel/ci-jobs.rst.inc
> +++ b/docs/devel/ci-jobs.rst.inc
> @@ -28,6 +28,32 @@ For further information about how to set these variables, please refer to::
>   
>     https://docs.gitlab.com/ee/user/project/push_options.html#push-options-for-gitlab-cicd
>   
> +Setting aliases in your git config
> +----------------------------------
> +
> +You can use aliases to make it easier to push branches with different
> +CI configurations. For example define an alias for triggering CI:
> +
> +.. code::
> +
> +   git config --local alias.push-ci "push -o ci.variable=QEMU_CI=1"
> +   git config --local alias.push-ci-now "push -o ci.variable=QEMU_CI=2"
> +
> +Which lets you run:
> +
> +.. code::
> +
> +   git push-ci
> +
> +to create the pipeline, or:
> +
> +.. code::
> +
> +   git push-ci-now
> +
> +to create and run the pipeline
> +
> +
>   Variable naming and grouping
>   ----------------------------
>   
> @@ -98,6 +124,18 @@ Contributor controlled runtime variables
>   The following variables may be set by contributors to control
>   job execution
>   
> +QEMU_CI
> +~~~~~~~
> +
> +By default, no pipelines will be created on contributor forks
> +in order to preserve CI credits
> +
> +Set this variable to 1 to create the pipelines, but leave all
> +the jobs to be manually started from the UI
> +
> +Set this variable to 2 to create the pipelines and run all
> +the jobs immediately, as was historicaly behaviour
> +
>   QEMU_CI_AVOCADO_TESTING
>   ~~~~~~~~~~~~~~~~~~~~~~~
>   By default, tests using the Avocado framework are not run automatically in
> diff --git a/.gitlab-ci.d/base.yml b/.gitlab-ci.d/base.yml
> index 4f091d5aad..f334f3ded7 100644
> --- a/.gitlab-ci.d/base.yml
> +++ b/.gitlab-ci.d/base.yml
> @@ -28,6 +28,10 @@
>       - if: '$QEMU_JOB_ONLY_FORKS == "1" && $CI_PROJECT_NAMESPACE == "qemu-project"'
>         when: never
>   
> +    # Forks don't get pipelines unless QEMU_CI=1 or QEMU_CI=2 is set
> +    - if: '$QEMU_CI != "1" && $QEMU_CI != "2" && $CI_PROJECT_NAMESPACE != "qemu-project"'
> +      when: never
> +
>       # Avocado jobs don't run in forks unless $QEMU_CI_AVOCADO_TESTING is set
>       - if: '$QEMU_JOB_AVOCADO && $QEMU_CI_AVOCADO_TESTING != "1" && $CI_PROJECT_NAMESPACE != "qemu-project"'
>         when: never
> @@ -59,5 +63,10 @@
>       # an earlier criteria
>       #############################################################
>   
> +    # Forks pipeline jobs don't start automatically unless
> +    # QEMU_CI=2 is set
> +    - if: '$QEMU_CI != "2" && $CI_PROJECT_NAMESPACE != "qemu-project"'
> +      when: manual
> +
>       # Jobs can run if any jobs they depend on were successfull
>       - when: on_success
Daniel P. Berrangé June 6, 2022, 11:01 a.m. UTC | #2
On Thu, Jun 02, 2022 at 12:50:21PM +0200, Philippe Mathieu-Daudé wrote:
> Cc'ing qemu-stable@

If you want this in stable, you'll need the 5 preceeding patches
too. I wouldn't be surprised if there are conflicts too. So it
might well need a custom set of patches spinning just for stable.

> 
> Thank you Daniel / Thomas / Alex!
> 
> On 1/6/22 20:05, Alex Bennée wrote:
> > From: Daniel P. Berrangé <berrange@redhat.com>
> > 
> > To preserve CI shared runner credits we don't want to run
> > pipelines on every push.
> > 
> > This sets up the config so that pipelines are never created
> > for contributors by default. To override this the QEMU_CI
> > variable can be set to a non-zero value. If set to 1, the
> > pipeline will be created but all jobs will remain manually
> > started. The contributor can selectively run jobs that they
> > care about. If set to 2, the pipeline will be created and
> > all jobs will immediately start.
> > 
> > This behavior can be controlled using push variables
> > 
> >    git push -o ci.variable=QEMU_CI=1
> > 
> > To make this more convenient define an alias
> > 
> >     git config --local alias.push-ci "push -o ci.variable=QEMU_CI=1"
> >     git config --local alias.push-ci-now "push -o ci.variable=QEMU_CI=2"
> > 
> > Which lets you run
> > 
> >    git push-ci
> > 
> > to create the pipeline, or
> > 
> >    git push-ci-now
> > 
> > to create and run the pipeline
> > 
> > Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> > Message-Id: <20220526110705.59952-6-berrange@redhat.com>
> > [AJB: fix typo, replicate alias tips in ci.rst]
> > Signed-off-by: Alex Bennée <alex.bennee@linaro.org>
> > Reviewed-by: Thomas Huth <thuth@redhat.com>
> > Message-Id: <20220527153603.887929-33-alex.bennee@linaro.org>
> > 
> > diff --git a/docs/devel/ci-jobs.rst.inc b/docs/devel/ci-jobs.rst.inc
> > index 0b4926e537..9118a61a17 100644
> > --- a/docs/devel/ci-jobs.rst.inc
> > +++ b/docs/devel/ci-jobs.rst.inc
> > @@ -28,6 +28,32 @@ For further information about how to set these variables, please refer to::
> >     https://docs.gitlab.com/ee/user/project/push_options.html#push-options-for-gitlab-cicd
> > +Setting aliases in your git config
> > +----------------------------------
> > +
> > +You can use aliases to make it easier to push branches with different
> > +CI configurations. For example define an alias for triggering CI:
> > +
> > +.. code::
> > +
> > +   git config --local alias.push-ci "push -o ci.variable=QEMU_CI=1"
> > +   git config --local alias.push-ci-now "push -o ci.variable=QEMU_CI=2"
> > +
> > +Which lets you run:
> > +
> > +.. code::
> > +
> > +   git push-ci
> > +
> > +to create the pipeline, or:
> > +
> > +.. code::
> > +
> > +   git push-ci-now
> > +
> > +to create and run the pipeline
> > +
> > +
> >   Variable naming and grouping
> >   ----------------------------
> > @@ -98,6 +124,18 @@ Contributor controlled runtime variables
> >   The following variables may be set by contributors to control
> >   job execution
> > +QEMU_CI
> > +~~~~~~~
> > +
> > +By default, no pipelines will be created on contributor forks
> > +in order to preserve CI credits
> > +
> > +Set this variable to 1 to create the pipelines, but leave all
> > +the jobs to be manually started from the UI
> > +
> > +Set this variable to 2 to create the pipelines and run all
> > +the jobs immediately, as was historicaly behaviour
> > +
> >   QEMU_CI_AVOCADO_TESTING
> >   ~~~~~~~~~~~~~~~~~~~~~~~
> >   By default, tests using the Avocado framework are not run automatically in
> > diff --git a/.gitlab-ci.d/base.yml b/.gitlab-ci.d/base.yml
> > index 4f091d5aad..f334f3ded7 100644
> > --- a/.gitlab-ci.d/base.yml
> > +++ b/.gitlab-ci.d/base.yml
> > @@ -28,6 +28,10 @@
> >       - if: '$QEMU_JOB_ONLY_FORKS == "1" && $CI_PROJECT_NAMESPACE == "qemu-project"'
> >         when: never
> > +    # Forks don't get pipelines unless QEMU_CI=1 or QEMU_CI=2 is set
> > +    - if: '$QEMU_CI != "1" && $QEMU_CI != "2" && $CI_PROJECT_NAMESPACE != "qemu-project"'
> > +      when: never
> > +
> >       # Avocado jobs don't run in forks unless $QEMU_CI_AVOCADO_TESTING is set
> >       - if: '$QEMU_JOB_AVOCADO && $QEMU_CI_AVOCADO_TESTING != "1" && $CI_PROJECT_NAMESPACE != "qemu-project"'
> >         when: never
> > @@ -59,5 +63,10 @@
> >       # an earlier criteria
> >       #############################################################
> > +    # Forks pipeline jobs don't start automatically unless
> > +    # QEMU_CI=2 is set
> > +    - if: '$QEMU_CI != "2" && $CI_PROJECT_NAMESPACE != "qemu-project"'
> > +      when: manual
> > +
> >       # Jobs can run if any jobs they depend on were successfull
> >       - when: on_success
> 

With regards,
Daniel
diff mbox series

Patch

diff --git a/docs/devel/ci-jobs.rst.inc b/docs/devel/ci-jobs.rst.inc
index 0b4926e537..9118a61a17 100644
--- a/docs/devel/ci-jobs.rst.inc
+++ b/docs/devel/ci-jobs.rst.inc
@@ -28,6 +28,32 @@  For further information about how to set these variables, please refer to::
 
   https://docs.gitlab.com/ee/user/project/push_options.html#push-options-for-gitlab-cicd
 
+Setting aliases in your git config
+----------------------------------
+
+You can use aliases to make it easier to push branches with different
+CI configurations. For example define an alias for triggering CI:
+
+.. code::
+
+   git config --local alias.push-ci "push -o ci.variable=QEMU_CI=1"
+   git config --local alias.push-ci-now "push -o ci.variable=QEMU_CI=2"
+
+Which lets you run:
+
+.. code::
+
+   git push-ci
+
+to create the pipeline, or:
+
+.. code::
+
+   git push-ci-now
+
+to create and run the pipeline
+
+
 Variable naming and grouping
 ----------------------------
 
@@ -98,6 +124,18 @@  Contributor controlled runtime variables
 The following variables may be set by contributors to control
 job execution
 
+QEMU_CI
+~~~~~~~
+
+By default, no pipelines will be created on contributor forks
+in order to preserve CI credits
+
+Set this variable to 1 to create the pipelines, but leave all
+the jobs to be manually started from the UI
+
+Set this variable to 2 to create the pipelines and run all
+the jobs immediately, as was historicaly behaviour
+
 QEMU_CI_AVOCADO_TESTING
 ~~~~~~~~~~~~~~~~~~~~~~~
 By default, tests using the Avocado framework are not run automatically in
diff --git a/.gitlab-ci.d/base.yml b/.gitlab-ci.d/base.yml
index 4f091d5aad..f334f3ded7 100644
--- a/.gitlab-ci.d/base.yml
+++ b/.gitlab-ci.d/base.yml
@@ -28,6 +28,10 @@ 
     - if: '$QEMU_JOB_ONLY_FORKS == "1" && $CI_PROJECT_NAMESPACE == "qemu-project"'
       when: never
 
+    # Forks don't get pipelines unless QEMU_CI=1 or QEMU_CI=2 is set
+    - if: '$QEMU_CI != "1" && $QEMU_CI != "2" && $CI_PROJECT_NAMESPACE != "qemu-project"'
+      when: never
+
     # Avocado jobs don't run in forks unless $QEMU_CI_AVOCADO_TESTING is set
     - if: '$QEMU_JOB_AVOCADO && $QEMU_CI_AVOCADO_TESTING != "1" && $CI_PROJECT_NAMESPACE != "qemu-project"'
       when: never
@@ -59,5 +63,10 @@ 
     # an earlier criteria
     #############################################################
 
+    # Forks pipeline jobs don't start automatically unless
+    # QEMU_CI=2 is set
+    - if: '$QEMU_CI != "2" && $CI_PROJECT_NAMESPACE != "qemu-project"'
+      when: manual
+
     # Jobs can run if any jobs they depend on were successfull
     - when: on_success