name: RPM Packages
permissions: read-all
on:
  workflow_dispatch:
  push:
    tags:
      - '[0-9]+.[0-9]+.[0-9]+'
  schedule:
    - cron: '0 0 * * 1,4' # Runs at 00:00 UTC on Monday and Thursday
  pull_request:
    branches: [ main ]
    paths:
      - 'packaging/rpm/**' # Only run on changes to the rpm packaging files
      - '.github/workflows/rpm_packages.yml'
jobs:
  test-package:
    if: (github.event_name == 'schedule' && github.repository_owner == 'miniflux')
      || github.event_name == 'pull_request'
    name: Test Packages
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
      with:
          fetch-depth: 0
    - name: Build RPM Package
      run: make rpm VERSION=2.2.x_dev
    - name: List generated files
      run: ls -l *.rpm
  build-package-manually:
    if: github.event_name == 'workflow_dispatch'
    name: Build Packages Manually
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
      with:
          fetch-depth: 0
    - name: Build RPM Package
      run: make rpm
    - name: Upload package
      uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
      with:
        name: packages
        path: "*.rpm"
        if-no-files-found: error
        retention-days: 3
  publish-package:
    if: github.event_name == 'push' && github.repository_owner == 'miniflux'
    name: Publish Packages
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
      with:
          fetch-depth: 0
    - name: Build RPM Package
      run: make rpm
    - name: List generated files
      run: ls -l *.rpm
    - name: Upload package to repository
      env:
        FURY_TOKEN: ${{ secrets.FURY_TOKEN }}
      run: for f in *.rpm; do curl -F package=@$f https://$FURY_TOKEN@push.fury.io/miniflux/; done
