Skip to content

Commit

Permalink
Add RPM build
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Perina <mperina@redhat.com>
  • Loading branch information
mwperina committed Mar 22, 2022
1 parent 1f9cc74 commit ea67ad6
Show file tree
Hide file tree
Showing 9 changed files with 462 additions and 182 deletions.
16 changes: 16 additions & 0 deletions .automation/build-rpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/bin/bash -xe

source $(dirname "$(readlink -f "$0")")/build-srpm.sh

# Install build dependencies
dnf builddep -y rpmbuild/SRPMS/*src.rpm

# Build binary package
rpmbuild \
--define "_topmdir rpmbuild" \
--define "_rpmdir rpmbuild" \
--rebuild rpmbuild/SRPMS/*src.rpm

# Move RPMs to exported artifacts
[[ -d $ARTIFACTS_DIR ]] || mkdir -p $ARTIFACTS_DIR
find rpmbuild -iname \*rpm | xargs mv -t $ARTIFACTS_DIR
41 changes: 41 additions & 0 deletions .automation/build-srpm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash -xe

# When building on GitHub we should use GITHUB_SHA environment variable, otherwise parse has from git
if [ "${GITHUB_SHA}" == "" ]; then
GIT_HASH=$(git rev-list HEAD | wc -l)
else
GIT_HASH=$(git rev-parse --short $GITHUB_SHA)
fi

# Directory, where build artifacts will be stored, should be passed as the 1st parameter
ARTIFACTS_DIR=${1:-exported-artifacts}

# Disabling tests can be passed as the 2nd parameter
SKIP_TESTS=${2:-0}

# Prepare the version string (with support for SNAPSHOT versioning)
VERSION=$(mvn help:evaluate -q -DforceStdout -Dexpression=project.version)
VERSION=${VERSION/-SNAPSHOT/-0.${GIT_HASH}.$(date +%04Y%02m%02d%02H%02M)}
IFS='-' read -ra VERSION <<< "$VERSION"
RELEASE=${VERSION[1]-1}

# Prepare source archive
[[ -d rpmbuild/SOURCES ]] || mkdir -p rpmbuild/SOURCES
git archive --format=tar HEAD | gzip -9 > rpmbuild/SOURCES/ovirt-engine-api-model-$VERSION.tar.gz

# Generate AsciiDoc and HTML documentation
mvn package -Pgenerate-doc
cp target/doc.jar rpmbuild/SOURCES/ovirt-engine-api-model-doc-$VERSION.jar

# Set version and release
sed \
-e "s|@VERSION@|${VERSION}|g" \
-e "s|@RELEASE@|${RELEASE}|g" \
-e "s|@SKIP_TESTS@|${SKIP_TESTS}|g" \
< ovirt-engine-api-model.spec.in \
> ovirt-engine-api-model.spec

# Build source package
rpmbuild \
-D "_topdir rpmbuild" \
-bs ovirt-engine-api-model.spec
22 changes: 2 additions & 20 deletions .automation/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,8 @@ fi
ARTIFACTS_DIR=${1:-exported-artifacts}
[[ -d ${ARTIFACTS_DIR} ]] || mkdir -p ${ARTIFACTS_DIR}

# Prepare the version string (with support for SNAPSHOT versioning)
VERSION=$(mvn help:evaluate -q -DforceStdout -Dexpression=project.version)
VERSION=${VERSION/-SNAPSHOT/-0.${GIT_HASH}.$(date +%04Y%02m%02d%02H%02M)}
IFS='-' read -ra VERSION <<< "$VERSION"
RELEASE=${VERSION[1]-1}


# We will need the name of the package in several places:
name="ovirt-engine-api-model"


# Generate the tarball:
git archive \
--prefix="${name}-${version}/" \
--output="${ARTIFACTS_DIR}/ovirt-engine-api-model-${VERSION}-${RELEASE}.tar.gz" \
HEAD


# Build the artifacts:
# Build the project along with the documentation
mvn package -DskipTests -Dadoc.linkcss=true

# Deploy the artifacts to the artifacts directory:
# Deploy the artifacts to the artifacts directory
mvn deploy -DaltDeploymentRepository="local::default::file://${ARTIFACTS_DIR}"
8 changes: 8 additions & 0 deletions .copr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.PHONY: installdeps srpm

installdeps:
dnf -y install git gzip java-11-openjdk-devel make maven ovirt-engine-api-metamodel rpm-build sed unzip

srpm: installdeps
./.automation/build-srpm.sh exported-artifacts 1
cp rpmbuild/SRPMS/*.src.rpm $(outdir)
69 changes: 16 additions & 53 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ on:
pull_request:
branches: [master]
workflow_dispatch:
branches: [master]

jobs:
build:
Expand All @@ -16,77 +15,41 @@ jobs:
include:
- name: centos-stream-8
shortcut: cs8
container-name: stream8
- name: centos-stream-9
shortcut: cs9
container-name: stream9
container-name: el8stream
# Uncomment CS9 builds once all deps on CS9 are provided
#- name: centos-stream-9
# shortcut: cs9
# container-name: el9stream

name: ${{ matrix.name }}

env:
ARTIFACTS_DIR: exported-artifacts

container:
image: quay.io/centos/centos:${{ matrix.container-name }}
image: quay.io/ovirt/buildcontainer:${{ matrix.container-name }}

steps:
- name: Prepare CentOS Stream 8 environment
if: ${{ matrix.shortcut == 'cs8' }}
run: |
# Install oVirt repositories
dnf copr enable -y ovirt/ovirt-master-snapshot centos-stream-8
dnf install -y ovirt-release-master
# Configure CS8 repositories
dnf config-manager --enable powertools
dnf module enable -y pki-deps javapackages-tools
- name: Checkout sources
uses: actions/checkout@v2

- name: Prepare CentOS Stream 9 environment
if: ${{ matrix.shortcut == 'cs9' }}
- name: Install additional build dependencies
run: |
# DNF core plugins are installed in the official CS9 container image
dnf install -y dnf-plugins-core
# Install oVirt repositories
dnf copr enable -y ovirt/ovirt-master-snapshot
dnf install -y ovirt-release-master
dnf install -y ovirt-engine-api-metamodel unzip
# Configure CS9 repositories
dnf config-manager --enable crb
- name: Install required packages
- name: Perform build
run: |
dnf install -y \
dnf-utils \
git \
gzip \
java-11-openjdk-devel \
maven \
rpm-build \
sed \
tar
- name: Checkout sources
uses: actions/checkout@v2
.automation/build-rpm.sh $ARTIFACTS_DIR
- name: Use cache for maven
uses: actions/cache@v2
- name: Upload artifacts
uses: ovirt/upload-rpms-action@v2
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
directory: ${{ env.ARTIFACTS_DIR }}

- name: Perform build
- name: Generate documentation
run: |
.automation/build.sh $ARTIFACTS_DIR
- name: Upload RPM artifacts
uses: actions/upload-artifact@v2
with:
name: rpm-${{ matrix.shortcut }}
path: ${{ env.ARTIFACTS_DIR}}

- name: Upload generated documentation artifacts
uses: actions/upload-artifact@v2
with:
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*.iml
.idea/
.bash_history
.vscode/
exported-artifacts/
logs*
mocker*
Expand Down
Loading

0 comments on commit ea67ad6

Please sign in to comment.