From: Martin Vidner Date: Tue, 24 Nov 2015 09:40:36 +0000 (+0100) Subject: From Git to OBS with fewer dependencies. X-Git-Tag: v0.3.3~21^2~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5c8c5d868f0b43c95ad4c20214a8982c5259659a;p=thirdparty%2Fsnapper.git From Git to OBS with fewer dependencies. --- diff --git a/Makefile.ci b/Makefile.ci new file mode 100644 index 00000000..60cc4ab3 --- /dev/null +++ b/Makefile.ci @@ -0,0 +1,19 @@ +# -*- Makefile -*- +# if "rake" is undesirable, reimplement it in make? +# Not everything, just the bare minimum that makes sense +# And let Rakefile be a redirector to this Makefile.ci + +# Simplicity is complicated? + +# Usage in Jenkins: +# make -f Makefile.ci osc:sr +# make -f Makefile.ci osc:ci +# make -f Makefile.ci osc:build +# make -f Makefile.ci package + +.PHONY: package + +package: + ./git-to-obs-package \ + -P YaST:Head -p snapper \ + -c 'make -f Makefile.repo && make package' diff --git a/git-to-obs-package b/git-to-obs-package new file mode 100755 index 00000000..26dfe740 --- /dev/null +++ b/git-to-obs-package @@ -0,0 +1,109 @@ +#!/bin/bash +set -eu + +# Given a Git repo of a package in the Open Build Service, +# make a source package from that repo, +# using `osc` to bring the dependencies to a chroot. + +# Minimal dependencies: +# - git-core +# - osc +# - build + +main() { + local USAGE_TEXT=' +Usage: main + +Options: +-P +-p +-c Shell command to make a package +' + local COMMAND PROJECT PACKAGE + local USAGE=false RC=0 + while getopts c:hP:p: FLAG; do + case $FLAG in + c) COMMAND="$OPTARG";; + h) USAGE=true;; + P) PROJECT="$OPTARG";; + p) PACKAGE="$OPTARG";; + + *) USAGE=true; RC=1;; + esac + done + shift $((OPTIND-1)) + + if $USAGE; then + echo "$USAGE_TEXT" + return $RC + fi + + local GITDIR=`pwd` + OBSDIR=`pwd`/.obsdir + rm -rf $OBSDIR + osc checkout --output-dir=$OBSDIR $PROJECT $PACKAGE + cd $OBSDIR + + export OSC_BUILD_ROOT=/var/tmp/build-root-git-to-obs + init_build_root + + copy_git_to_chroot $GITDIR + + make_package "$COMMAND" + + fetch_package + + # CLEANUP + cleanup_git_in_chroot +} + +# short circuit the first build +# in: +# cwd: obs +# $OSC_BUILD_ROOT +# out: +# chroot at $OSC_BUILD_ROOT is initialized +init_build_root() { + local SUCCESS_FILE=/tmp/build-root-ready + + rm -f $OSC_BUILD_ROOT/$SUCCESS_FILE + sed -i -e "/^%build/atouch $SUCCESS_FILE; : intentional fail; exit 1" *.spec + osc build --build-uid=caller || : + rm $OSC_BUILD_ROOT/$SUCCESS_FILE # fails if not present + +} + +TMPGIT=/tmp/gitdir + +# in: +# $1 git dir +# $OSC_BUILD_ROOT +copy_git_to_chroot() { + cleanup_git_in_chroot + mkdir -p $OSC_BUILD_ROOT/$TMPGIT + rmdir $OSC_BUILD_ROOT/$TMPGIT + cp -a $1 $OSC_BUILD_ROOT/$TMPGIT +} + +# in: +# $OSC_BUILD_ROOT +cleanup_git_in_chroot() { + rm -rf $OSC_BUILD_ROOT/$TMPGIT +} + +# in: +# $1 command to make package +make_package() { + sudo chroot --userspec=$USER $OSC_BUILD_ROOT \ + sh -c "cd ${TMPGIT#$OSC_BUILD_ROOT}; $1" +} + +# in: +# pwd: obs dir + +fetch_package() { + rm -v *.tar.* + cp -av $OSC_BUILD_ROOT/$TMPGIT/package/* . +} + +main "$@"