gwastro/sbank

View on GitHub
.github/workflows/packaging.yml

Summary

Maintainability
Test Coverage
# ---------------------------
#
# Prepare distributions of this project
# for various platforms
#
# ---------------------------

name: Packaging

on:
  push:
    branches:
      - main
      - master
  pull_request:
    branches:
      - main
      - master

jobs:
  tarball:
    name: Tarball

    runs-on: ubuntu-latest

    steps:
      - name: Get source code
        uses: actions/checkout@v2
        with:
          fetch-depth: 0

      - name: Set up Python
        uses: actions/setup-python@v2
        with:
          python-version: '3.x'

      - name: Install build requirements
        run: python -m pip install build

      - name: Create distributions
        run: python -m build --outdir . --sdist .

      - uses: actions/upload-artifact@v2
        with:
          name: tarball
          path: sbank-*.tar.*
          if-no-files-found: error

  # -- Debian ---------------

  debian-source:
    name: LSCSoft ${{ matrix.debian }} source package
    needs:
      - tarball
    strategy:
      fail-fast: false
      matrix:
        debian:
          - buster
    runs-on: ubuntu-latest
    container: igwn/base:${{ matrix.debian }}
    env:
      TARBALL: "sbank-*.tar.*"
    steps:
      - name: Download tarball
        uses: actions/download-artifact@v2
        with:
          name: tarball

      - name: Configure apt
        run: |
          apt-get autoclean
          apt-get -y -q -q update
          apt-get -y -q -q install \
              devscripts \
              dpkg-dev \
          ;

      - name: Create source package
        run: |
          mkdir src
          tar -xf ${TARBALL} -C src --strip-components=1
          PKG_VERSION=$(grep ^Version src/PKG-INFO | cut -d\  -f2)
          # add changelog entry for this version
          (cd src; dch --newversion ${PKG_VERSION}-9999 --controlmaint "ci build")
          # rename tarball for debian orig
          _orig=$(
              basename ${TARBALL} | \
              sed 's|\(.*\)-\(.*\).\(tar\..*\)|\1_'${PKG_VERSION}'.orig.tar.gz|'
          )
          mv -v ${TARBALL} "${_orig}"
          # create debian source package files
          dpkg-source --build src

      - uses: actions/upload-artifact@v2
        with:
          name: dsc-${{ matrix.debian }}
          path: |
            *.orig.tar.*
            *.debian.tar.*
            *.dsc
          if-no-files-found: error

  debian-binary:
    name: LSCSoft ${{ matrix.debian }} binary package
    needs:
      - debian-source
    strategy:
      fail-fast: false
      matrix:
        debian:
          - buster
    runs-on: ubuntu-latest
    container: igwn/base:${{ matrix.debian }}
    env:
      DSC: "sbank_*.dsc"
    steps:
      - name: Download source package
        uses: actions/download-artifact@v2
        with:
          name: dsc-${{ matrix.debian }}

      - name: Configure apt
        run: |
          apt-get -y -q -q update
          apt-get -y -q -q install \
              devscripts \
              dpkg-dev \
          ;

      - name: Unpack DSC
        run: |
          dpkg-source --extract ${DSC} src

      - name: Install build dependencies
        shell: bash -ex {0}
        run: |
          cd src
          mk-build-deps \
              --tool "apt-get -y -q -o Debug::pkgProblemResolver=yes --no-install-recommends" \
              --install \
              --remove \
          ;

      - name: Build binary packages
        run: |
          cd src
          # build debian packages
          dpkg-buildpackage -us -uc -b

      - name: Print package info
        run: |
          # print contents of packages
          for debf in *.deb; do
              echo "===== ${debf}"
              dpkg --info "${debf}"
              dpkg --contents "${debf}"
          done

      - uses: actions/upload-artifact@v2
        with:
          name: deb-${{ matrix.debian }}
          path: |
            *.buildinfo
            *.changes
            *.deb
          if-no-files-found: error

  debian-install:
    name: LSCSoft ${{ matrix.debian }} install test
    needs:
      - debian-binary
    strategy:
      fail-fast: false
      matrix:
        debian:
          - buster
    runs-on: ubuntu-latest
    container: igwn/base:${{ matrix.debian }}
    steps:
      - name: Download binary packages
        uses: actions/download-artifact@v2
        with:
          name: deb-${{ matrix.debian }}

      - name: Configure apt
        run: apt-get -y -q -q update

      - name: Install packages
        shell: bash -ex {0}
        run: |
          dpkg --install *.deb || { \
              apt-get -y -f install;
              dpkg --install *.deb;
          }

  lint-debian:
    name: Lint Debian packages
    runs-on: ubuntu-latest
    container: debian
    needs:
      - debian-binary
    steps:
      - name: Download debian package
        uses: actions/download-artifact@v2
        with:
          name: deb-buster

      - name: Install lintian
        run: |
          apt-get -y -q -q update
          apt-get -y -q -q install \
              lintian \
          ;

      - name: Lintian
        run: lintian --color=auto --fail-on warning --allow-root --pedantic --suppress-tags manpage-has-useless-whatis-entry,manpage-has-errors-from-man *.changes

  # -- RHEL -----------------

  rhel-source:
    name: LSCSoft ${{ matrix.el }} source package
    needs:
      - tarball
    strategy:
      fail-fast: false
      matrix:
        el:
          - el7-testing
    runs-on: ubuntu-latest
    container: igwn/base:${{ matrix.el }}
    env:
      TARBALL: "sbank-*.tar.*"
    steps:
      - name: Download tarball
        uses: actions/download-artifact@v2
        with:
          name: tarball

      - name: Configure DNF
        if: matrix.el == 'el7-testing'
        run: ln -s /usr/bin/yum /usr/bin/dnf

      - name: Configure EPEL
        run: |
          dnf -y install epel-release
          dnf -y install epel-rpm-macros

      - name: Configure rpmbuild
        run: |
          dnf -y install \
              python-srpm-macros \
              rpm-build \
          ;

      - name: Create source package
        run: rpmbuild -ts --define "_srcrpmdir $(pwd)" ${TARBALL}

      - uses: actions/upload-artifact@v2
        with:
          name: srpm-${{ matrix.el }}
          path: "*.src.rpm"
          if-no-files-found: error

  rhel-binary:
    name: LSCSoft ${{ matrix.el }} binary package
    needs:
      - rhel-source
    strategy:
      fail-fast: false
      matrix:
        el:
          - el7-testing
    runs-on: ubuntu-latest
    container: igwn/base:${{ matrix.el }}
    env:
      SRPM: "python-sbank-*.src.rpm"
    steps:
      - name: Download SRPM
        uses: actions/download-artifact@v2
        with:
          name: srpm-${{ matrix.el }}

      - name: Configure DNF
        if: matrix.el == 'el7-testing'
        run: ln -s /usr/bin/yum /usr/bin/dnf

      - name: Configure EPEL
        run: |
          dnf -y install epel-release
          dnf -y install epel-rpm-macros

      - name: Enable PowerTools (EL8+)
        if: matrix.el != 'el7-testing'
        run: |
          dnf -y -q install "dnf-command(config-manager)"
          dnf config-manager --set-enabled powertools

      - name: Install build tools (EL7)
        if: matrix.el == 'el7-testing'
        run: |
          dnf -y -q install \
              rpm-build \
              yum-utils \
          ;

      - name: Install build tools (EL8+)
        if: matrix.el != 'el7-testing'
        run: |
          dnf -y -q install \
              rpm-build \
              "dnf-command(builddep)" \
          ;

      - name: Install build dependencies (EL7)
        if: matrix.el == 'el7-testing'
        run: yum-builddep -y ${SRPM}

      - name: Install build dependencies (EL8+)
        if: matrix.el != 'el7-testing'
        run: dnf builddep -y ${SRPM}

      - name: Build binary packages
        run: |
          rpmbuild --rebuild --define "_rpmdir $(pwd)" ${SRPM}
          rm -f ${SRPM}
          mv */*.rpm .

      - name: Print package info
        run: |
          # print contents of packages
          for rpmf in *.rpm; do
              echo "===== ${rpmf}"
              rpm -qlp "${rpmf}"
              echo "Files:"
              rpm -qip "${rpmf}"
              echo "Provides:"
              rpm -qp --provides "${rpmf}"
              echo "Requires:"
              rpm -qp --requires "${rpmf}"
          done

      - uses: actions/upload-artifact@v2
        with:
          name: rpm-${{ matrix.el }}
          path: "*.rpm"
          if-no-files-found: error

  rhel-install:
    name: LSCSoft ${{ matrix.el }} install test
    needs:
      - rhel-binary
    strategy:
      fail-fast: false
      matrix:
        el:
          - el7-testing
    runs-on: ubuntu-latest
    container: igwn/base:${{ matrix.el }}
    steps:
      - name: Download RPMs
        uses: actions/download-artifact@v2
        with:
          name: rpm-${{ matrix.el }}

      - name: Configure DNF
        if: matrix.el == 'el7-testing'
        run: ln -s /usr/bin/yum /usr/bin/dnf

      - name: Configure EPEL
        run: |
          dnf -y install epel-release
          dnf -y install epel-rpm-macros

      - name: Install RPMs
        run: dnf -y install *.rpm

  lint-rhel:
    name: Lint RPMs
    runs-on: ubuntu-latest
    container: centos:7
    needs:
      - rhel-binary
    steps:
      - name: Download RPM
        uses: actions/download-artifact@v2
        with:
          name: rpm-el7-testing

      - name: Install rpmlint
        run: |
          yum -y -q install \
              rpmlint \
          ;

      - name: Prepare rpmlintrc
        run : |
          cat << EOF > rpmlintrc
          # don't validate Source0
          setOption("NetworkEnabled", False)
          # the regex rpmlint uses to identify 'lib' libraries is crap
          addFilter('explicit-lib-dependency (.*)?matplotlib')
          EOF

      - name: Lint
        run: rpmlint -f rpmlintrc --info *.rpm