Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Packit integration in pull requests #143

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions .packit.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# This file is used by the Packit service.
# Currently it is used for the gating of pull requests.
#
# See the documentation for more information:
# https://packit.dev/docs/configuration/

# We need a specfile to build the RPM package.
# But instead of storing it in this repository,
# we use the one that exists already in src.fedoraproject.org/rpms/golang.
# In particular, we use the specfile from the branch `eln`.
# We'll create the temporary folder .packit_rpm to store the content of the
# Fedora repository.
specfile_path: .packit_rpm/golang.spec

# We need to tell Packit which files to sync from the upstream repository.
files_to_sync:
- .packit.yaml
- ./scripts/packit.sh
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need the changes from this script reflected in the final downstream rpm as well?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean if they will be included in the CentOS Stream packages? They are only for this GitHub project, I don't think we need them anywhere else.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case, line 18 can be removed too.


srpm_build_deps:
- golang
- net-tools
- openssl-devel
- glibc-static
- perl-interpreter
- procps-ng

# The name of the package in the upstream repository.
upstream_package_name: golang
# The name of the package in Fedora.
downstream_package_name: golang
# Use a different tag template for the upstream repository.
#upstream_tag_template: "v{version}"

actions:
create-archive:
- "bash ./scripts/packit.sh create-archive"
post-upstream-clone:
# Use the Fedora ELN package.
- "git clone https://src.fedoraproject.org/rpms/golang.git .packit_rpm --branch eln"
fix-spec-file:
# Fix the specfile by running the ./scripts/packit.sh script
# We cannot put the content of the script inside the yaml due to limitations of the format
- "bash ./scripts/packit.sh"

jobs:
# Build the package in Fedora ELN when a pull request is opened.
# It can be requested by adding a comment with the text: /packit copr-build
- job: copr_build
trigger: pull_request
targets:
- fedora-eln-aarch64
- fedora-eln-ppc64le
- fedora-eln-s390x
- fedora-eln-x86_64
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend adding centos-stream-$releasever-$arch and epel-$releasever-$arch targets as well as we'll also be shipping over there.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick note, currently we don't have epel-10 targets on copr, so it'll only be epel-9. But centos stream can have both 9 and 10.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concern that will increase the complexity as CentOS Stream and ELN spec files might be potentially different at some times, but we should try on CentOS Stream too for sure.

Not sure about EPEL, why is necessary? There is no golang spec file for EPEL 8/9.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am concern that will increase the complexity as CentOS Stream and ELN spec files might be potentially different at some times, but we should try on CentOS Stream too for sure.

There are maybe two approaches you can try:

  1. Make both ELN and CentOS Stream 9/10 buildable using a single spec file.
  2. Include separate spec files for both ELN and CentOS Stream and mention them like this . You can replace you existing specfile_path line with that and use the separate paths for each of fedora and centos-stream.

I guess we could leave that for a followup PR.

Not sure about EPEL, why is necessary? There is no golang spec file for EPEL 8/9.

This could instead be a rhel-9-$arch copr target as well.

BTW, a quirk about copr is that on a rhel / centos-stream env if you run dnf copr enable foo/bar it will by default enable the epel target if it exists. And the epel copr targets are rhel + epel envs. So, if you wanna check buildability on proper rhel, you could use either of rhel- or epel- and get the same results. Just that the copr quirk might make using epel a little more convenient for testing etc.

This could also be left for a followup.


33 changes: 33 additions & 0 deletions scripts/packit.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# This script execute a set of steps needed by the .packit.yaml file

# Detect the Go version targeted in the PR
version=$(awk '/github.com\/golang\/go/ {gsub(/[: "go]/, "", $2); print $2}' config/versions.json)
# Split the version using '.' as the delimiter
IFS='.' read -ra parts <<< "$version"
# Extract the first two parts and store in go_api
go_api="${parts[0]}.${parts[1]}"
# Extract the third part and store in go_patch
go_patch="${parts[2]}"
# Create a high package release number. This is a dirty hack.
pkg_release="99"

package="go$version-$pkg_release-openssl-fips"

if [ "$1" = "create-archive" ]; then
git archive --verbose --output $package.tar.gz --prefix go-$package/ HEAD
ls -1t ./go*-openssl-fips.tar.gz | head -n 1
else
# Drop fedora.go file
rm -fv .packit_rpm/fedora.go
sed -i '/SOURCE2/d' .packit_rpm/golang.spec
sed -i '/fedora.go/d' .packit_rpm/golang.spec
# Drop all the patches, we don't know if they can be apply to the new code
rm -fv .packit_rpm/*.patch
sed -ri '/^Patch[0-9]*:.+$/d' .packit_rpm/golang.spec

# Update the Go version in golang.spec with the value of $go_api and $go_patch
sed -i "s/%global go_api .*/%global go_api $go_api/" .packit_rpm/golang.spec
sed -i "s/%global go_patch .*/%global go_patch $go_patch/" .packit_rpm/golang.spec
sed -i "s/%global pkg_release .*/%global pkg_release $pkg_release/" .packit_rpm/golang.spec
fi
Loading