# Usage in Jenkins:
# make -f Makefile.ci osc_build
-.PHONY: package osc_build
-
-package:
- ./obs-package-from-git \
+.PHONY: package
+package: obs-package-from-git
+ ./$^ \
-P YaST:Head -p snapper \
-o .obsdir \
-c 'make -f Makefile.repo && make package'
+.PHONY: osc_build
osc_build: package
cd .obsdir; osc build
+
+# A script that is shared with other projects and should be always refreshed
+URL=https://raw.githubusercontent.com/openSUSE/obs-package-from-git/master/obs-package-from-git
+.PHONY: always_out_of_date
+obs-package-from-git: always_out_of_date
+ wget -O $@ $(URL) && chmod +x $@
+++ /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 (not used here; our caller, typically Jenkins, will have used it)
-# - osc
-# - build
-
-main() {
- local USAGE_TEXT='
-Usage: main <options>
-
-Options:
--P <OBS project>
--p <OBS package>
--o <OBS target directory> (will be removed first)
--c <command> Shell command to make a package
-'
- local COMMAND OBSDIR PROJECT PACKAGE
- local USAGE=false RC=0
- while getopts c:ho:P:p: FLAG; do
- case $FLAG in
- c) COMMAND="$OPTARG";;
- h) USAGE=true;;
- o) OBSDIR="$OPTARG";;
- 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`
- 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
-# out:
-# package in $OSC_BUILD_ROOT/$TMPGIT/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 "$@"