Add CI workflow to build RPMs #13
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} | |
- uses: actions/checkout@v4 | |
with: | |
path: 'rpmbuild/BUILD' | |
fetch-depth: 0 | |
- name: Calculate version and repo | |
run: | | |
cd rpmbuild/BUILD | |
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>(-[0-9A-Za-z-]+)? | |
if [[ ${TAG_NAME} =~ ^v([0-9]+\.[0-9]+\.[0-9]+)(-[[:alnum:]-]+)?$ ]]; then | |
if [[ -z ${BASH_REMATCH[2]} ]]; then | |
REPO='stable' | |
VERSION="${BASH_REMATCH[1]}" | |
VERSION_POM=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout) | |
if [[ ${VERSION} != ${VERSION_POM} ]]; then | |
echo "Version mismatch between tag (${VERSION}) and POM file (${VERSION_POM})" | |
exit 1 | |
fi | |
else | |
# If the tag includes a "-" is a beta, substitute the first "-" with "~" and any other ones with "_" | |
REPO='beta' | |
PRERELEASE=$(echo ${BASH_REMATCH[2]:1} | sed 's/-/_/g') | |
VERSION="${BASH_REMATCH[1]}~$PRERELEASE" | |
fi | |
fi | |
else | |
# Use the output of "git describe" to create version dropping the leading "v" and substituting: | |
# - the last "-" with "." | |
# - the now last "-" with "^" | |
# - the first remaining "-" (if any) with "~" | |
# - all possible remaining "-" with "_" | |
VERSION=$(git describe --tags --long | sed 's/^v//' | sed -r 's/(.*)-/\1./' | sed -r 's/(.*)-/\1^/' | sed 's/-/~/' | sed 's/-/_/g') | |
if [[ ${GITHUB_REF} = 'refs/heads/'+$NIGHTLY_BRANCH ]]; then | |
REPO='nightly' | |
fi | |
fi | |
echo "REPO=$REPO" >> "$GITHUB_ENV" | |
echo "VERSION=$VERSION" >> "$GITHUB_ENV" | |
echo "Version: $VERSION" | |
echo "Repo: ${REPO:-none}" | |
- name: Build RPM | |
run: | | |
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}" -ba rpmbuild/SPECS/storm-webdav.spec | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: build-rpm-${{ matrix.os }}-${{ matrix.version }} | |
path: | | |
rpmbuild/RPMS/noarch/*.rpm | |
- name: Upload release to repo | |
if: env.REPO != '' | |
run: | | |
curl --fail --user "$NEXUS_USER:$NEXUS_PASSWORD" --upload-file rpmbuild/RPMS/noarch/*.rpm https://repo.cloud.cnaf.infn.it/repository/storm-rpm-$REPO/redhat${{ matrix.version }}/ |