duncanmmacleod/requests-ecp

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
      - release/**
  pull_request:
    branches:
      - main
      - release/**

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}
  cancel-in-progress: true

jobs:
  tarball:
    name: Tarball

    runs-on: ubuntu-latest

    steps:
      - name: Get source code
        uses: actions/checkout@v4

      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v4
        with:
          python-version: '3.x'

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

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

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

      - uses: actions/upload-artifact@v3
        with:
          name: wheel
          path: requests_ecp*.whl
          if-no-files-found: error

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

  debian-source:
    name: Debian ${{ matrix.debian }} source package
    needs:
      - tarball
    strategy:
      fail-fast: false
      matrix:
        debian:
          - oldstable-backports
          - stable
          - testing
    runs-on: ubuntu-latest
    container: debian:${{ matrix.debian }}
    env:
      TARBALL: "*.tar.*"
    steps:
      - name: Download tarball
        uses: actions/download-artifact@v3
        with:
          name: tarball

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

      - name: Create source package
        run: |
          mkdir src
          tar -xf ${TARBALL} -C src --strip-components=1
          SOURCE_NAME=$(dpkg-parsechangelog -l src/debian/changelog -SSource || echo "\1")
          # rename tarball for debian orig
          _orig=$(basename ${TARBALL} | sed "s|\(.*\)-\(.*\).\(tar\..*\)|${SOURCE_NAME}_\2.orig.\3|")
          cp -r ${TARBALL} "${_orig}"
          # create debian source package files
          dpkg-source --build src

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

  debian-binary:
    name: Debian ${{ matrix.debian }} binary package
    needs:
      - debian-source
    strategy:
      fail-fast: false
      matrix:
        debian:
          - oldstable-backports
          - stable
          - testing
    runs-on: ubuntu-latest
    container: debian:${{ matrix.debian }}
    env:
      DSC: "requests-ecp_*.dsc"
    steps:
      - name: Download source package
        uses: actions/download-artifact@v3
        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
          if [[ "${{ matrix.debian }}" == *backports ]]; then
              . /etc/os-release
              BACKPORTS="-t ${VERSION_CODENAME}-backports";
          fi
          mk-build-deps \
              --tool "apt-get -y -q ${BACKPORTS:-} -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@v3
        with:
          name: deb-${{ matrix.debian }}
          path: |
            *.buildinfo
            *.changes
            *.deb
          if-no-files-found: error

  debian-install:
    name: Debian ${{ matrix.debian }} install test
    needs:
      - debian-binary
    strategy:
      fail-fast: false
      matrix:
        debian:
          - oldstable-backports
          - stable
          - testing
    runs-on: ubuntu-latest
    container: debian:${{ matrix.debian }}
    steps:
      - name: Download binary packages
        uses: actions/download-artifact@v3
        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@v3
        with:
          name: deb-stable

      - 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 *.changes

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

  rhel-source:
    name: ${{ matrix.name }} ${{ matrix.version }} source package
    needs:
      - tarball
    strategy:
      fail-fast: false
      matrix:
        include:
          - dist: lscsoft
            name: LSCSoft
            version: EL7
            container: igwn/base:el7-testing
          - dist: rockylinux
            name: Rocky Linux
            version: 8
            container: rockylinux:8
          - dist: rockylinux
            name: Rocky Linux
            version: 9
            container: rockylinux:9
          - dist: fedora
            name: Fedora
            version: latest
            container: fedora:latest
    runs-on: ubuntu-latest
    container: ${{ matrix.container }}
    env:
      TARBALL: "*.tar.*"
    steps:
      - name: Download tarball
        uses: actions/download-artifact@v3
        with:
          name: tarball

      - name: Configure DNF
        if: matrix.dist == 'lscsoft'
        run: ln -s /usr/bin/yum /usr/bin/dnf

      - name: Configure EPEL
        if: matrix.dist != 'fedora'
        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@v3
        with:
          name: srpm-${{ matrix.dist }}-${{ matrix.version }}
          path: "*.src.rpm"
          if-no-files-found: error

  rhel-binary:
    name: ${{ matrix.name }} ${{ matrix.version }} binary package
    needs:
      - rhel-source
    strategy:
      fail-fast: false
      matrix:
        include:
          - dist: lscsoft
            name: LSCSoft
            version: EL7
            container: igwn/base:el7-testing
          - dist: rockylinux
            name: Rocky Linux
            version: 8
            container: rockylinux:8
          - dist: rockylinux
            name: Rocky Linux
            version: 9
            container: rockylinux:9
          - dist: fedora
            name: Fedora
            version: latest
            container: fedora:latest
    runs-on: ubuntu-latest
    container: ${{ matrix.container }}
    env:
      SRPM: "*.src.rpm"
    steps:
      - name: Download SRPM
        uses: actions/download-artifact@v3
        with:
          name: srpm-${{ matrix.dist }}-${{ matrix.version }}

      - name: Configure DNF
        if: matrix.dist == 'lscsoft'
        run: ln -s /usr/bin/yum /usr/bin/dnf

      - name: Enable CRB (Rocky Linux >=9)
        if: matrix.dist == 'rockylinux' && matrix.version >= 9
        run: |
          dnf -y -q install "dnf-command(config-manager)"
          dnf config-manager --set-enabled crb

      - name: Configure EPEL
        if: matrix.dist != 'fedora'
        run: |
          dnf -y install epel-release
          dnf -y install epel-rpm-macros

      - name: Install build tools
        if: matrix.dist != 'lscsoft'
        run: |
          dnf -y -q install \
              rpm-build \
              "dnf-command(builddep)" \
          ;

      - name: Install build dependencies
        if: matrix.dist != 'lscsoft'
        run: dnf builddep -y ${SRPM}

      - name: Install build tools (LSCSoft)
        if: matrix.dist == 'lscsoft'
        run: |
          dnf -y -q install \
              rpm-build \
              yum-utils \
          ;

      - name: Install build dependencies (LSCSoft)
        if: matrix.dist == 'lscsoft'
        run: yum-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 -qp --info "${rpmf}"
              echo "Files:"
              rpm -qp --list "${rpmf}"
              echo "Provides:"
              rpm -qp --provides "${rpmf}"
              echo "Requires:"
              rpm -qp --requires "${rpmf}"
          done

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

  rhel-install:
    name: ${{ matrix.name }} ${{ matrix.version }} install test
    needs:
      - rhel-binary
    strategy:
      fail-fast: false
      matrix:
        include:
          - dist: lscsoft
            name: LSCSoft
            version: EL7
            container: igwn/base:el7-testing
          - dist: rockylinux
            name: Rocky Linux
            version: 8
            container: rockylinux:8
          - dist: rockylinux
            name: Rocky Linux
            version: 9
            container: rockylinux:9
          - dist: fedora
            name: Fedora
            version: latest
            container: fedora:latest
    runs-on: ubuntu-latest
    container: ${{ matrix.container }}
    steps:
      - name: Download RPMs
        uses: actions/download-artifact@v3
        with:
          name: rpm-${{ matrix.dist }}-${{ matrix.version }}

      - name: Configure DNF
        if: matrix.dist == 'lscsoft'
        run: ln -s /usr/bin/yum /usr/bin/dnf

      - name: Configure EPEL
        if: matrix.dist != 'fedora'
        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: rockylinux:9
    needs:
      - rhel-binary
    steps:
      - name: Download RPM
        uses: actions/download-artifact@v3
        with:
          name: rpm-rockylinux-9

      - name: Configure EPEL
        if: matrix.dist != 'fedora'
        run: dnf -y install epel-release

      - name: Install rpmlint
        run: |
          dnf -y -q install \
              rpmlint \
              *.rpm \
          ;

      - name: Lint
        run: rpmlint --info python3-requests-ecp *.rpm