--- /dev/null
+# -*- 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'
--- /dev/null
+#!/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>
+
+Options:
+-P <OBS project>
+-p <OBS package>
+-c <command> 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 "$@"