add make-tar.sh

This commit is contained in:
Michael Davidsaver
2017-11-14 13:15:25 -06:00
parent 75cdab3c17
commit a1f633fe27
3 changed files with 84 additions and 0 deletions

77
.ci/make-tar.sh Executable file
View File

@@ -0,0 +1,77 @@
#!/bin/sh
#
# Make tar for git repo w/ one level of sub modules.
#
set -e
TOPREV="$1"
FINALTAR="$2"
PREFIX="$3"
if ! [ "$TOPREV" ]
then
cat <<EOF >&2
usage: $0 [rev] [outfile.tar.gz] [prefix/]
"<rev>" may be any git revision spec. (tag, branch, or commit id).
Output file may be .tar.gz, .tar.bz2, or any extension supported by "tar -a".
If output file name is omitted, then "<rev>.tar.gz" is the default.
If prefix is omitted, then the default is "<rev>/".
EOF
exit 1
fi
[ "$FINALTAR" ] || FINALTAR="$TOPREV.tar.gz"
[ "PREFIX" ] || PREFIX="$TOPREV/"
# temporary directory w/ automatic cleanup
TDIR=`mktemp -d`
trap 'rm -rf "$TDIR"' EXIT INT QUIT TERM
mkdir "$TDIR"/tar
echo "Export revision $TOPREV as $FINALTAR with prefix $PREFIX"
# Use git-archive to copy files at the given revision into our temp. dir.
# Respects 'export-exclude' in .gitattributes files.
git archive --prefix=$PREFIX $TOPREV | tar -C "$TDIR"/tar -x
# use ls-tree instead of submodule-foreach to capture submodule revision associated with supermodule rev.
#
# sub-modules appear in tree as eg.:
# 160000 commit c3a6cfcf0dad4a4eeecf59b474710d06ff3eb68a modules/ca
git ls-tree -r $TOPREV | awk '/^[0-9]+ commit / {print $3, $4}' | \
while read HASH MODDIR
do
echo "visit $HASH $MODDIR"
(cd $MODDIR && git archive --prefix=${PREFIX}${MODDIR}/ $HASH) | tar -C "$TDIR"/tar -x
done
# make a list of files copied and filter out undesirables
(cd "$TDIR"/tar && find .) > "$TDIR"/list.1
sed \
-e '/.*ci$/d' \
-e '/.*ci\//d' \
-e '/.*jenkins$/d' \
-e '/.*jenkins\//d' \
-e '/\.git/d' \
-e '/\.project/d' \
-e '/.*\.travis\.yml$/d' \
-e '/.*\.appveyor\.yml$/d' \
"$TDIR"/list.1 > "$TDIR"/list.2
if ! diff -u "$TDIR"/list.1 "$TDIR"/list.2
then
echo "Warning: prohibited files being ignored"
fi
# Use the filtered list to build the final tar
# The -a option chooses compression automatically based on output file name.
tar -C "$TDIR"/tar --files-from="$TDIR"/list.2 -caf "$FINALTAR"
echo "Wrote $FINALTAR"

4
.gitattributes vendored Normal file
View File

@@ -0,0 +1,4 @@
.ci/ export-ignore
.appveyor.yml export-ignore
.travis.yml export-ignore
README export-subst

3
README
View File

@@ -22,3 +22,6 @@ training materials, additional components, links to other
websites etc. is available on the EPICS home page at
http://www.aps.anl.gov/epics/
$Format:%cD$
$Format:%H$
https://code.launchpad.net/epics-base