Add a 'changed' job that determines which .spec files were modified using git diff between push before/after SHAs. The build job now uses a dynamic matrix (fromJSON) so only changed specs are built. For workflow_dispatch, all specs are still built.
118 lines
3.7 KiB
YAML
118 lines
3.7 KiB
YAML
name: Build RPMs
|
|
|
|
on:
|
|
push:
|
|
paths:
|
|
- "**.spec"
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
changed:
|
|
runs-on: almalinux-10
|
|
outputs:
|
|
matrix: ${{ steps.set.outputs.matrix }}
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Determine changed specs
|
|
id: set
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
|
|
python3 -c "import json; print(json.dumps({'spec': ['sonic-interface-libraries.spec','sonic-win.spec','sonic-workspace.spec']}))"
|
|
else
|
|
CHANGED=$(git diff --name-only ${{ github.event.before }} ${{ github.sha }} | grep '\.spec$' || true)
|
|
python3 -c "import json, sys; print(json.dumps({'spec': sys.argv[1].split()}))" "$CHANGED"
|
|
fi >> "$GITHUB_OUTPUT"
|
|
|
|
build:
|
|
needs: changed
|
|
runs-on: almalinux-10
|
|
strategy:
|
|
fail-fast: false
|
|
matrix: ${{ fromJSON(needs.changed.outputs.matrix) }}
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install build tools
|
|
run: |
|
|
dnf install -y \
|
|
rpm-build \
|
|
rpmdevtools \
|
|
mock \
|
|
curl
|
|
|
|
- name: Add runner user to mock group
|
|
run: usermod -aG mock $(whoami) || true
|
|
|
|
- name: Setup RPM build tree
|
|
run: rpmdev-setuptree
|
|
|
|
- name: Download sources for ${{ matrix.spec }}
|
|
run: |
|
|
spectool -g -C ~/rpmbuild/SOURCES/ ${{ matrix.spec }}
|
|
|
|
- name: Build SRPM from ${{ matrix.spec }}
|
|
run: |
|
|
rpmbuild -bs \
|
|
--define "_topdir ${HOME}/rpmbuild" \
|
|
--define "_disable_source_fetch 0" \
|
|
${{ matrix.spec }}
|
|
PKGNAME=$(rpmspec -q --srpm --queryformat "%{NAME}-%{VERSION}-%{RELEASE}.src.rpm" ${{ matrix.spec }})
|
|
echo "SRPM_PATH=${HOME}/rpmbuild/SRPMS/${PKGNAME}" >> "$GITHUB_ENV"
|
|
|
|
- name: Build RPM with mock
|
|
run: |
|
|
cat > /tmp/mock-custom.cfg <<'MOCKEOF'
|
|
include('/etc/mock/alma+epel-10-x86_64.cfg')
|
|
config_opts['root'] = 'custom'
|
|
config_opts['yum.conf'] += """
|
|
[sonicde-rpm]
|
|
name=SonicDE RPM
|
|
baseurl=https://pc-rytteren.dk/forge/api/packages/anders/rpm
|
|
enabled=1
|
|
gpgcheck=0
|
|
|
|
[xlibre-xserver]
|
|
name=Copr xlibre-xserver
|
|
baseurl=https://download.copr.fedorainfracloud.org/results/@xlibre/xlibre-xserver/rhel+epel-10-$basearch/
|
|
type=rpm-md
|
|
skip_if_unavailable=True
|
|
gpgcheck=1
|
|
gpgkey=https://download.copr.fedorainfracloud.org/results/@xlibre/xlibre-xserver/pubkey.gpg
|
|
repo_gpgcheck=0
|
|
enabled=1
|
|
"""
|
|
MOCKEOF
|
|
cp /tmp/mock-custom.cfg /etc/mock/custom.cfg
|
|
mock --root custom --scrub=chroot || true
|
|
mock \
|
|
--root custom \
|
|
--resultdir "${HOME}/mock-results" \
|
|
--clean \
|
|
--rebuild "${{ env.SRPM_PATH }}"
|
|
|
|
- name: Upload RPMs to Forgejo Package Registry
|
|
run: |
|
|
FORGEJO_URL="${{ github.server_url }}"
|
|
OWNER="${{ github.repository_owner }}"
|
|
TOKEN="${{ secrets.PACKAGE_TOKEN }}"
|
|
|
|
find "${HOME}/mock-results" -name "*.rpm" ! -name "*.src.rpm" | while read rpm; do
|
|
FILENAME=$(basename "$rpm")
|
|
echo "Uploading $FILENAME ..."
|
|
curl --fail-with-body \
|
|
--user "${OWNER}:${TOKEN}" \
|
|
--upload-file "$rpm" \
|
|
"${FORGEJO_URL}/api/packages/${OWNER}/rpm/upload"
|
|
done
|
|
|
|
- name: Clean up build artifacts
|
|
if: always()
|
|
run: |
|
|
rm -rf "${HOME}/mock-results"
|
|
rm -rf "${HOME}/rpmbuild/SRPMS"
|