CI for mesa in Fedora Project

Today I played with jenkins for my primary work. I wanted to check sources periodically and if it has been changed – build new RPM package from new git version. I have started playing with mesa, because I maintain it in Fedora and has git version in Rawhide which I’m building from time to time from git.

Q: What it’s doing right now?
A: Checking if there new upstream commits, updating .spec file, commiting to fedorapeople git repository, copying .src.rpm to fedorapeople http site and submitting to build in COPR repo.

Q: How I can use this CI and what version of Fedora I need?
A: You can use this CI only on Fedora Rawhide. You can enable repo via # dnf copr enable ignatenkobrain/mesa and update packages.

How I built this in jenkins?

First, I installed jenkins via # dnf install jenkins, started it via # systemctl start jenkins and opened browser at http://localhost:8080/.
Installed some plugins: Git Plugin and Multiple SCMs Plugin.
Uploaded my .fedora.cert and .fedora-server-ca.cert to /var/lib/jenkins/ directory.
Created COPR config in /var/lib/jenkins/.config/copr as described in API page.
Added credential in jenkins with private ssh key which can push to fedorapeople git repository (the same as in FAS).
Created job in jenkins with name mesa and configured it:

  1. Source Code Management -> Multiple SCMs
  2. Add SCM -> Git
    1. Repository URL -> ssh://ignatenkobrain@fedorapeople.org/home/fedora/ignatenkobrain/public_git/mesa.git
    2. Credentials -> ignatenkobrain (Fedora Project)
    3. Advanced
    4. Name -> fedora
    5. Add -> Check out to a sub-directory
    6. Local subdirectory for repo -> fedora
    7. Add -> Custom user name/email address
    8. user.name -> Igor Gnatenko
    9. user.email -> ignatenkobrain@fedoraproject.org
    10. Add -> Wipe out repository & force clone
  3. Add SCM -> Git
    1. Repository URL -> git://anongit.freedesktop.org/mesa/mesa
    2. Advanced
    3. Name -> upstream
    4. Add -> Check out to a sub-directory
    5. Local subdirectory for repo -> upstream
  4. Poll SCM -> H * * * *
  5. Add build step -> Exexute shell
    1. Command ->
      get_evr()
      {
          python - << EOF
      import rpm
      import re
      sp = rpm.spec("mesa.spec")
      print(re.sub(r"\.fc.*$", "", sp.sourceHeader.EVR))
      EOF
      }
      
      cd fedora/
      git checkout master
      
      REV=`GIT_DIR=../upstream/.git git rev-parse --short HEAD`
      sed -i \
          -e "s/^\(%define githash \).*/\1${REV}/g" \
          mesa.spec
      
      ret=$(EVR=`get_evr` python - << EOF
      import requests
      import os
      r = requests.get("https://copr.fedoraproject.org/api/coprs/ignatenkobrain/mesa/monitor/").json()
      for x in r["builds"]:
          if os.environ["EVR"] in x['src_pkg'] and x['state'] != "failed":
              print("Already built")
      EOF
      )
      [[ "${ret}" == *"Already built"* ]] && exit 0
      
      DIRNAME=mesa-${REV}
      rm -f ${DIRNAME}.tar.xz
      GIT_DIR=../upstream/.git git archive --format=tar --prefix=${DIRNAME}/ HEAD | xz > ${DIRNAME}.tar.xz
      rm -rf ${DIRNAME}
      ./sanitize-tarball.sh ${DIRNAME}.tar.xz
      rm -rf ${DIRNAME}
      sed -i \
          -e "s/^\(Release:\).*/\1 0.devel.${BUILD_NUMBER}.%{git}%{?dist}/g" \
          mesa.spec
      EVR=`get_evr`
      CHLOG=`date "+%a %b %d %Y Igor Gnatenko <ignatenkobrain@fedoraproject.org> - ${EVR}"`
      sed -i \
          -e "s/^\(%changelog\)/\1\n* ${CHLOG}\n- ${REV}\n/g" \
          mesa.spec
      fedpkg new-sources ${DIRNAME}.tar.xz
      git commit -a -s -m "${REV}"
      git push fedora master
      mkdir -p SRPMS/
      SRPM=`rpmbuild -bs -D "_sourcedir ${WORKSPACE}/fedora" -D "_srcrpmdir ${WORKSPACE}/fedora/SRPMS/" mesa.spec`
      SRPM=`basename $(echo ${SRPM##Wrote: })`
      scp ${WORKSPACE}/fedora/SRPMS/${SRPM} ignatenkobrain@fedorapeople.org:~/public_html/mesa-staging/
      copr-cli build mesa https://ignatenkobrain.fedorapeople.org/mesa-staging/${SRPM}
      

Probably I could do this more easy. If so – let me know ;)

Leave a Reply

Your email address will not be published. Required fields are marked *

css.php