Skip to content

Commit fa770ea

Browse files
committed
Enable Packit integration in pull requests
This feature adds support for Packit and the Packit bot. It adds two files: - .packit.yaml: Defines the tasks. It can be expanded later in case other features are attractive. - scripts/packit.sh: Variables can't be passed due to YAML limitations, and some commands with complex structures fail. Hence the script. The features inside the script are complex to use outside the Packit system; instead of having two scripts, two different functionalities are inside this file. How it works: When a PR is open or has changed, the bot packit-as-a-service will detect them. Then, three stages are run: - create-archive: this stage will run scripts/packit.sh using a create-archive argument that triggers git archive. Packit default functionality in this stage fails. By default, it thinks we are trying to substitute the Go upstream tarball. - post-upstream-clone: this stage will clone the ELN branch inside a new folder named .packit_rpm. - fix-spec-file: Several actions performed by scripts/packit.sh are executed here. It detects the version targeted in the PR, fakes the spec file previously downloaded in the second stage, and removes the patches that Fedora carries because those changes will likely conflict with the changes in the pull request.
1 parent ce5cefc commit fa770ea

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed

.packit.yaml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# This file is used by the Packit service.
2+
# Currently it is used for the gating of pull requests.
3+
#
4+
# See the documentation for more information:
5+
# https://packit.dev/docs/configuration/
6+
7+
# We need a specfile to build the RPM package.
8+
# But instead of storing it in this repository,
9+
# we use the one that exists already in src.fedoraproject.org/rpms/golang.
10+
# In particular, we use the specfile from the branch `eln`.
11+
# We'll create the temporary folder .packit_rpm to store the content of the
12+
# Fedora repository.
13+
specfile_path: .packit_rpm/golang.spec
14+
15+
# We need to tell Packit which files to sync from the upstream repository.
16+
files_to_sync:
17+
- .packit.yaml
18+
- ./scripts/packit.sh
19+
- src: .packit_rpm/golang.spec
20+
dest: golang.spec
21+
22+
srpm_build_deps:
23+
- golang
24+
- net-tools
25+
- openssl-devel
26+
- glibc-static
27+
- perl-interpreter
28+
- procps-ng
29+
30+
# The name of the package in the upstream repository.
31+
upstream_package_name: golang
32+
# The name of the package in Fedora.
33+
downstream_package_name: golang
34+
# Use a different tag template for the upstream repository.
35+
#upstream_tag_template: "v{version}"
36+
37+
actions:
38+
create-archive:
39+
- "bash ./scripts/packit.sh create-archive"
40+
post-upstream-clone:
41+
# Use the Fedora ELN package.
42+
- "git clone https://src.fedoraproject.org/rpms/golang.git .packit_rpm --branch eln"
43+
fix-spec-file:
44+
# Fix the specfile by running the ./scripts/packit.sh script
45+
# We cannot put the content of the script inside the yaml due to limitations of the format
46+
- "bash ./scripts/packit.sh"
47+
48+
jobs:
49+
# Build the package in Fedora ELN when a pull request is opened.
50+
# It can be requested by adding a comment with the text: /packit copr-build
51+
# This will run the job in the Copr project `alexsaezm/golang-fips`.
52+
- job: copr_build
53+
trigger: pull_request
54+
owner: alexsaezm
55+
project: go-fips
56+
targets:
57+
- fedora-eln-aarch64
58+
- fedora-eln-ppc64le
59+
- fedora-eln-s390x
60+
- fedora-eln-x86_64
61+

scripts/packit.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/usr/bin/env bash
2+
# This script execute a set of steps needed by the .packit.yaml file
3+
4+
# Detect the Go version targeted in the PR
5+
version=$(awk '/github.com\/golang\/go/ {gsub(/[: "go]/, "", $2); print $2}' config/versions.json)
6+
# Split the version using '.' as the delimiter
7+
IFS='.' read -ra parts <<< "$version"
8+
# Extract the first two parts and store in go_api
9+
go_api="${parts[0]}.${parts[1]}"
10+
# Extract the third part and store in go_patch
11+
go_patch="${parts[2]}"
12+
# Create a high package release number. This is a dirty hack.
13+
pkg_release="99"
14+
15+
package="go$version-$pkg_release-openssl-fips"
16+
17+
if [ "$1" = "create-archive" ]; then
18+
git archive --verbose --output $package.tar.gz --prefix go-$package/ HEAD
19+
ls -1t ./go*-openssl-fips.tar.gz | head -n 1
20+
else
21+
# Drop fedora.go file
22+
rm -fv .packit_rpm/fedora.go
23+
sed -i '/SOURCE2/d' .packit_rpm/golang.spec
24+
sed -i '/fedora.go/d' .packit_rpm/golang.spec
25+
# Drop all the patches, we don't know if they can be apply to the new code
26+
rm -fv .packit_rpm/*.patch
27+
sed -ri '/^Patch[0-9]*:.+$/d' .packit_rpm/golang.spec
28+
29+
# Update the Go version in golang.spec with the value of $go_api and $go_patch
30+
sed -i "s/%global go_api .*/%global go_api $go_api/" .packit_rpm/golang.spec
31+
sed -i "s/%global go_patch .*/%global go_patch $go_patch/" .packit_rpm/golang.spec
32+
sed -i "s/%global pkg_release .*/%global pkg_release $pkg_release/" .packit_rpm/golang.spec
33+
fi

0 commit comments

Comments
 (0)