#
# Verify on CI/GHA that package building works.
#
name: RPM Packaging

on:
  push:
    branches: [main, master, 'release/**']
  pull_request:
    branches: [main, master]
  workflow_dispatch:

jobs:

  build:
    name: Build RPMs
    runs-on: ubuntu-latest

    container:
      image: ghcr.io/caronc/apprise-rpmbuild:el9
      options: --user root

    steps:
      - name: Checkout source
        uses: actions/checkout@v4

      - name: Build RPMs
        run: ./bin/build-rpm.sh
        env:
          APPRISE_DIR: ${{ github.workspace }}

      - name: Show RPMs found for upload
        run: |
          echo "Listing dist/**/*.rpm:"
          find dist -type f -name '*.rpm'

      - name: Upload RPM Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: built-rpms
          path: |
            dist/rpm/*/*.rpm
          if-no-files-found: error
          retention-days: 5

  verify:
    name: Verify RPMs
    needs: build
    runs-on: ubuntu-latest

    container:
      image: ghcr.io/caronc/apprise-rpmbuild:el9
      options: --user root

    steps:
      - name: Download built RPMs
        uses: actions/download-artifact@v4
        with:
          name: built-rpms
          path: ./dist

      - name: Lint RPMs
        run: rpmlint ./dist/**/*.rpm
      
      - name: Install and verify RPMs
        run: |
          echo "Installing RPMs from: ./dist/"
          find ./dist -name '*.rpm'
          dnf install -y ./dist/**/*.rpm
          apprise --version
      
      - name: Check Installed Files
        run: rpm -qlp ./dist/**/*.rpm
