.. _tutorial-set-up-workflow-templates:

=========================
Set up workflow templates
=========================

The best way to ask Debusine to do some work for you is to create
:ref:`explanation-workflows`.  In this tutorial, you will discover how to
set up workflow templates on your own instance.

Prerequisites
=============

This tutorial assumes that you installed :ref:`your own instance
<tutorial-install-debusine>` and that you have administrative access it via
:ref:`debusine-admin <debusine-admin-cli>`.  You can skip this tutorial if
you're using a managed instance such as debusine.debian.net, since in those
cases suitable workflow templates have already been created for you.

If you haven't done so already, you'll need to make yourself an owner of the
default workspace in order to be allowed to create workflow templates in it.

.. code-block:: console

    $ sudo debusine-admin group create debusine/Admins
    $ sudo debusine-admin workspace grant_role debusine/System owner Admins
    $ sudo debusine-admin group members debusine/Admins --add YOUR-USER-NAME

You will also need to :ref:`set up the Debusine client
<set-up-debusine-client>`.

Create a build environment
==========================

Various :ref:`worker tasks <explanation-tasks>` require build environments,
which are created using the :workflow:`update_environments` workflow.

Start by creating a :collection:`debian:environments` collection on your
server:

.. code-block:: console

    $ sudo debusine-admin create_collection debian debian:environments </dev/null

Then, on your client, create a suitable workflow template and start it
running:

.. code-block:: console

    $ debusine workflow-template create \
        update_environments update-debian-environments <<END
    static_parameters:
      vendor: "debian"
      targets:
      - codenames: ["trixie"]
        architectures: ["amd64"]
        backends: ["unshare"]
        mmdebstrap_template:
          bootstrap_options:
            variant: "minbase"
          bootstrap_repositories:
          - mirror: "http://deb.debian.org/debian"
            components: ["main"]
      - codenames: ["trixie"]
        architectures: ["amd64"]
        variants: ["sbuild"]
        backends: ["unshare"]
        mmdebstrap_template:
          bootstrap_options:
            variant: "buildd"
          bootstrap_repositories:
          - mirror: "http://deb.debian.org/debian"
            components: ["main"]
    END

    $ debusine workflow start update-debian-environments <<END
    {}
    END

Once this workflow finishes (which will take a few minutes), you should have
a :collection:`debian:environments` collection populated with some useful
base tarballs for ``trixie/amd64`` that can be used with the ``unshare``
backend: a default variant containing only essential and required packages,
and an ``sbuild`` variant that also contains build-essential packages.
These can be :ref:`looked up by name <lookup-syntax>`.  If you wish, you can
vary the ``targets`` dictionary to build different environments, or automate
this workflow to run regularly.

Set up the Debian pipeline
==========================

The :workflow:`debian_pipeline` workflow is a powerful tool that coordinates
all the steps typically involved in building and testing an upload to
Debian; it also has options to run tests on other packages that depend on
your package, and perform the upload for you at the end.

On your client, create a suitable workflow template:

.. code-block:: console

    $ debusine workflow-template create \
        debian_pipeline debian-qa-unshare <<END
    static_parameters:
      autopkgtest_backend: unshare
      lintian_backend: unshare
      piuparts_backend: unshare
      sbuild_backend: unshare
      upload_include_binaries: false
      upload_merge_uploads: false
      vendor: debian
      codename: sid
    runtime_parameters:
      source_artifact: 'any'
      codename: ['sid', 'forky']
      autopkgtest_backend: ['unshare', 'incus-lxc', 'incus-vm']
      lintian_backend: ['unshare', 'incus-lxc', 'incus-vm']
      piuparts_backend: ['unshare', 'incus-lxc', 'incus-vm']
      sbuild_backend: ['unshare', 'incus-lxc', 'incus-vm']
    END

Any workflow parameters specified in ``runtime_parameters`` may be set
to any of the specified values when you create a workflow from the
template.
The special value ``'any'`` allows any value to be provided.
A global ``runtime_parameters: any`` allows all workflow parameters to
be specified at workflow creation time.

You will then be able to run this workflow for a given source artifact, as
shown in :ref:`tutorial-getting-started`.
