Skip to main content

Configuration examples

Examples for actions

You can find detailed documentation for actions here.

Getting version

Getting version from specfile
get-current-version:
- grep -oP '^Version:\s+\K\S+' my-package.spec

or with a command from rpm-build package that will honor the macros:

get-current-version:
- rpmspec -q --queryformat "%{VERSION}\n" *spec |head -n1
Getting version for Python packages with setup.py
get-current-version:
- python3 setup.py --version
Getting version for Ruby packages from the gemspec
get-current-version:
- ruby -rrubygems -e 'puts Gem::Specification::load(Dir.glob("*.gemspec").first).version'

Manipulating spec file

Downloading specfile from the dist-git repo
post-upstream-clone:
- "wget https://src.fedoraproject.org/rpms/my-package/raw/main/f/my-package.spec -O my-package.spec"
Setting the Sources correctly in case of multiple Sources
fix-spec-file:
# define one of the Source variables correctly
- sed -i my_specfile_path -e "s/https.*only-vendor.tar.xz/my_correct_tarball_path/"
# fill in %release as if packit would have done it
- bash -c "sed -i my_specfile_path -r \"s/Release:(\s*)\S+/Release:\1${PACKIT_RPMSPEC_RELEASE}%{?dist}/\""

Custom archive creation for SRPM

Creating archive with custom make target
create-archive:
- make release
- bash -c "ls -1t ./my-package-*.tar.gz | head -n 1"
Creating archive for Python packages with setup.py
create-archive:
- python3 setup.py sdist --dist-dir .
- bash -c "ls -1t ./my-package-*.tar.gz | head -n 1"
Creating archive with git submodules
create-archive:
- git submodule update --init
# Create an archive file with the ‹pkg› directory prefix
- bash -c 'git ls-files --recurse-submodules | tar --transform "s|^|pkg/|" -caf .packit/pkg.tar.gz -T-'
- echo '.packit/pkg.tar.gz'

Custom archive creation for release syncing

If you need to generate local archive(s) during release syncing, you can utilise e.g. pre-sync action to place the commands necessary for the creation. You also have to include the archive(s) in the list of files to be moved to the dist-git repo so that it is then handled by Packit from there. Note: Beware of how Packit uploads files to lookaside cache or adds them to dist-git (see this note for more details).

Creating an archive using tito and syncing it to dist-git repo
actions:
pre-sync:
- tito build -o . --tgz

files_to_sync:
- src:
- "<my-package>-*.tar.gz"
dest: .

Custom changelog generation

Using file content as a changelog entry
changelog-entry:
- cat .changelog_entry
Using `git log` output as a changelog entry
changelog-entry:
- bash -c 'git log --no-merges --pretty="format:- %s (%an)" $(git describe --tags --abbrev=0 ${PACKIT_PROJECT_UPSTREAM_TAG}^)..${PACKIT_PROJECT_UPSTREAM_TAG} --'

Examples for jobs

You can find detailed documentation for jobs here.

Builds

Running builds in Copr for all pull requests
- job: copr_build
trigger: pull_request
targets:
- fedora-all
Running builds in Copr for pull requests with 'main' target branch
- job: copr_build
trigger: pull_request
branch: main
targets:
- fedora-all
Running builds in custom Copr project for pushes to 'main'

Configuring building in Copr project @oamg/convert2rhel:

- job: copr_build
trigger: commit
branch: main
owner: "@oamg"
project: convert2rhel
targets:
- epel-6-x86_64
- epel-7-x86_64
- epel-8-x86_64
Running more types of builds in Copr
jobs:
- job: copr_build
trigger: pull_request
identifier: fedora
targets:
- fedora-all

- job: copr_build
trigger: pull_request
specfile_path: epel8/python-specfile.spec
identifier: epel8
actions:
create-archive:
- python3 setup.py sdist --dist-dir ./epel8/
- bash -c "ls -1t ./epel8/*.tar.gz | head -n 1"
targets:
- epel-8
Running builds in Koji for all pull requests
- job: upstream_koji_build
trigger: pull_request
targets:
- fedora-all
Running builds in Koji for pull requests with 'main' target branch
- job: upstream_koji_build
trigger: pull_request
branch: main
targets:
- fedora-all
Utilising custom failure message
- job: copr_build
trigger: pull_request
targets:
- fedora-all
notifications:
failure_comment:
message: >
Some builds failed for commit {commit_sha}.
@admin, please check."

Tests

Running tests in Testing Farm for all pull requests
- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
trigger: pull_request
targets:
- fedora-all
Running tests in Testing Farm for pull requests with 'main' target branch
- job: copr_build
trigger: pull_request
branch: main
targets:
- fedora-all

- job: tests
trigger: pull_request
branch: main
targets:
- fedora-all
Running tests in internal Testing Farm instance

Please, let us know if you want to use the internal Testing Farm; we have to enable it for you.

- job: copr_build
trigger: pull_request
targets:
- epel-8-x86_64

- job: tests
trigger: pull_request
targets:
epel-8-x86_64:
distros: [RHEL-8.8.0-Nightly]
use_internal_tf: True
Running only tests (without builds)
- job: tests
trigger: pull_request
targets:
- fedora-all
skip_build: True
Defining mapping between build and test targets
- job: copr_build
trigger: pull_request
targets:
- epel-7-x86_64
- epel-8-x86_64

- job: tests
trigger: pull_request
targets:
epel-7-x86_64:
distros: [centos-7, oraclelinux-7]
epel-8-x86_64:
distros: [centos-8, oraclelinux-8]
Specifying where the FMF metadata are placed in the current repository
- job: tests
trigger: pull_request
targets:
- fedora-all
fmf_path: .distro/tmt
Specifying where the FMF metadata are placed outside the current repository
- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
trigger: pull_request
targets:
- fedora-all
fmf_url: "https://gitlab.cee.redhat.com/baseos-qe/tmt.git"
fmf_ref: main
Running more types of tests with different settings
jobs:
- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
trigger: pull_request
identifier: "postgres-12-pgoutput"
targets:
- fedora-all
tf_extra_params:
test:
tmt:
name: postgres
environments:
- variables:
POSTGRESQL_VERSION: 12
DECODER_PLUGIN: pgoutput


- job: tests
trigger: pull_request
identifier: "postgres-15-decoderbufs"
targets:
- fedora-all
tf_extra_params:
test:
tmt:
name: postgres
environments:
- variables:
POSTGRESQL_VERSION: 15
DECODER_PLUGIN: decoderbufs

Extending timeout of a test pipeline for 24 hours (default is 12 hours)
- job: tests
trigger: pull_request
identifier: "performance"
targets:
- centos-stream-9-x86_64
skip_build: true
manual_trigger: true
labels:
- performance
tf_extra_params:
settings:
pipeline:
timeout: 1440
test:
tmt:
name: performance
Providing custom tmt context
- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
trigger: pull_request
targets:
- fedora-all
tf_extra_params:
environments:
- tmt:
context:
how: "full"
Tag cloud resources in Testing Farm

Tag cloud resources in Testing Farm to a specific Red Hat team or a project. If you are not a Red Hat employee, this section is not relevant for you. Make sure to update sst_change_me to your RHEL SST name or name of the project. If not set, cloud costs are reported against Packit Service. The BusinessUnit key name is required, please do not change it.

- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
trigger: pull_request
targets:
- fedora-all
# Tag cloud resources for tmt
tf_extra_params:
environments:
- settings:
provisioning:
tags:
BusinessUnit: sst_change_me
Providing additional Testing Farm artifacts
- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
trigger: pull_request
targets:
- fedora-all
tf_extra_params:
environments:
- artifacts:
- type: repository
id: https://my.repo/repository
Utilising custom failure message
- job: copr_build
trigger: pull_request
targets:
- fedora-all

- job: tests
identifier: revdeps
trigger: pull_request
targets:
- fedora-all
notifications:
failure_comment:
message: >
Reverse dep tests failed for commit {commit_sha}.
@admin, please check."

Fedora release automation

Creating dist-git pull requests on upstream releases
- job: propose_downstream
trigger: release
dist_git_branches:
- fedora-all
Creating dist-git pull requests on upstream releases defined in the dist-git repository
upstream_project_url: https://github.com/packit/packit

jobs:
- job: pull_from_upstream
trigger: release
dist_git_branches:
- fedora-all
Creating dist-git pull requests on upstream releases matching specified tag pattern defined in the dist-git repository
upstream_project_url: https://github.com/packit/packit

jobs:
- job: pull_from_upstream
trigger: release
dist_git_branches:
- fedora-all
upstream_tag_include: "^2\\..+"
upstream_tag_exclude: "^.+\\.1\\..+"
Creating dist-git pull requests on upstream releases with different configs for branches defined in the dist-git repository
upstream_project_url: https://github.com/packit/packit

jobs:
- job: pull_from_upstream
trigger: release
dist_git_branches:
- fedora-38
upstream_tag_include: "^2\\..+"
upstream_tag_exclude: "^.+\\.1\\..+"

- job: pull_from_upstream
trigger: release
dist_git_branches:
- fedora-rawhide
Running Koji builds when the Packit pull requests in dist-git are merged
- job: koji_build
trigger: commit
dist_git_branches:
- fedora-all
Running Koji builds as a reaction to merging PRs or committing in dist-git by specified users
- job: koji_build
trigger: commit
dist_git_branches:
- fedora-all
allowed_pr_authors:
- packit
- the-fas-username-to-allow
allowed_committers:
- packit
- another-fas-username-to-allow
Creating Bodhi updates automatically for successful Koji builds
- job: bodhi_update
trigger: commit
dist_git_branches:
- fedora-branched # rawhide updates are created automatically

Get inspired

You can also look directly into configuration files of some other projects using Packit: