Add CI workflow to build RPMs #10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build RPM | |
on: push | |
env: | |
NIGHTLY_BRANCH: develop | |
jobs: | |
build-rpm: | |
if: github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name != github.event.pull_request.base.repo.full_name | |
strategy: | |
fail-fast: false | |
matrix: | |
os: [almalinux] | |
version: [8, 9] | |
runs-on: ubuntu-latest | |
container: '${{ matrix.os }}:${{ matrix.version }}' | |
steps: | |
- name: Install dependencies | |
run: | | |
dnf upgrade -y | |
[[ "${{ matrix.version }}" = 8 ]] && dnf module enable -y maven:3.8/common | |
dnf install -y git rpmdevtools rpmlint maven-openjdk11 | |
- name: Setup build tree | |
run: | | |
mkdir -p rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS} | |
- name: Check out repository code | |
uses: actions/checkout@v4 | |
with: | |
path: 'rpmbuild/BUILD' | |
fetch-depth: 0 | |
- name: Calculate version and repo | |
run: | | |
cd rpmbuild/BUILD | |
VERSION_POM=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout) | |
if [[ ${{ github.ref_type }} = 'tag' ]]; then | |
# In case is a tag, get the tag value | |
GITHUB_REF=${{ github.ref }} | |
TAG_NAME=${GITHUB_REF#refs/tags/} | |
# Check if the tag matches v<x>.<y>.<z>(@...)?(-<n>)? | |
if [[ ${TAG_NAME} =~ ^v([0-9]+\.[0-9]+\.[0-9]+)(@[[:alnum:]]+)?(-[0-9]+)?$ ]]; then | |
# If the release was not specified set to 1 | |
VERSION=${BASH_REMATCH[1]} | |
if [[ -z ${BASH_REMATCH[3]} ]]; then | |
RELEASE=1 | |
else | |
RELEASE=${BASH_REMATCH[3]:1} | |
fi | |
if [[ -z ${BASH_REMATCH[2]} ]]; then | |
REPO='stable' | |
if [[ ${VERSION} != ${VERSION_POM} ]]; then | |
echo "Version mismatch between tag (${VERSION}) and POM file (${VERSION_POM})" | |
exit 1 | |
fi | |
else | |
# If the tag include something after the @ is a beta, substitute @ with ~ in the RPM version (~ is not supported in Git tags) | |
REPO='beta' | |
VERSION="${BASH_REMATCH[1]}~${BASH_REMATCH[2]:1}" | |
fi | |
fi | |
else | |
VERSION=$VERSION_POM | |
RELEASE=0 | |
if [[ ${GITHUB_REF} = 'refs/heads/'+$NIGHTLY_BRANCH ]]; then | |
REPO='nightly' | |
fi | |
fi | |
echo "REPO=$REPO" >> "$GITHUB_ENV" | |
echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
echo "RELEASE=$RELEASE" >> "$GITHUB_ENV" | |
echo "Version: $VERSION-$RELEASE" | |
echo "Repo: ${REPO:-none}" | |
- name: Create .rpm | |
run: | | |
echo "Building $VERSION-$RELEASE" | |
cp rpmbuild/BUILD/storm-webdav.spec rpmbuild/SPECS/storm-webdav.spec | |
rpmlint rpmbuild/SPECS/storm-webdav.spec | |
rpmbuild --define "_topdir `pwd`/rpmbuild" --define "base_version ${VERSION}" --define "release_version ${RELEASE}" -ba rpmbuild/SPECS/storm-webdav.spec | |
- name: Upload release | |
if: env.REPO != '' | |
run: | | |
curl --user "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file rpmbuild/RPMS/noarch/*.rpm https://repo.cloud.cnaf.infn.it/repository/storm-rpm-$REPO/redhat${{ matrix.version }}/ | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-rpm-${{ matrix.os }}-${{ matrix.version }} | |
path: | | |
rpmbuild/RPMS/noarch/*.rpm |