Bug #318241 - Include LICENSE file in release tarballs.
[portage.git] / mkrelease.sh
1 #!/bin/bash
2
3 RELEASE_BUILDDIR=${RELEASE_BUILDDIR:-/var/tmp/portage-release}
4 SOURCE_DIR=${RELEASE_BUILDDIR}/checkout
5 BRANCH=${BRANCH:-master}
6 USE_TAG=false
7 CHANGELOG_REVISION=
8 UPLOAD_LOCATION=
9
10 die() {
11         echo $@
12         echo "Usage: ${0##*/} [--changelog-rev <tree-ish>] [-t|--tag] [-u|--upload <location>] <version>"
13         exit 1
14 }
15
16 ARGS=$(getopt -o tu: --long changelog-rev:,tag,upload: \
17         -n ${0##*/} -- "$@")
18 [ $? != 0 ] && die "initialization error"
19
20 eval set -- "${ARGS}"
21
22 while true; do
23         case "$1" in
24                 --changelog-rev)
25                         CHANGELOG_REVISION=$2
26                         shift 2
27                         ;;
28                 -t|--tag)
29                         USE_TAG=true
30                         shift
31                         ;;
32                 -u|--upload)
33                         UPLOAD_LOCATION=${2}
34                         shift 2
35                         ;;
36                 --)
37                         shift
38                         break
39                         ;;
40                 *)
41                         die "unknown option: $1"
42                         ;;
43         esac
44 done
45
46 [ -z "$1" ] && die "Need version argument"
47 [ -n "${1/[0-9]*}" ] && die "Invalid version argument"
48
49 VERSION=${1}
50 RELEASE=portage-${VERSION}
51 RELEASE_DIR=${RELEASE_BUILDDIR}/${RELEASE}
52 RELEASE_TARBALL="${RELEASE_BUILDDIR}/${RELEASE}.tar.bz2"
53 TREE_ISH=$BRANCH
54 if [[ $USE_TAG = true ]] ; then
55         TREE_ISH=v$VERSION
56 fi
57
58 echo ">>> Cleaning working directories ${RELEASE_DIR} ${SOURCE_DIR}"
59 rm -rf "${RELEASE_DIR}" "${SOURCE_DIR}" || die "directory cleanup failed"
60 mkdir -p "${RELEASE_DIR}" || die "directory creation failed"
61 mkdir -p "$SOURCE_DIR" || die "mkdir failed"
62
63 echo ">>> Starting GIT archive"
64 git archive --format=tar $TREE_ISH | \
65         tar -xf - -C "$SOURCE_DIR" || die "git archive failed"
66
67 echo ">>> Building release tree"
68 cp -a "${SOURCE_DIR}/"{bin,cnf,doc,man,pym} "${RELEASE_DIR}/" || die "directory copy failed"
69 cp "${SOURCE_DIR}/"{DEVELOPING,LICENSE,NEWS,RELEASE-NOTES,TEST-NOTES} \
70         "${RELEASE_DIR}/" || die "file copy failed"
71
72 echo ">>> Creating Changelog"
73 git_log_opts=""
74 [ -n "$CHANGELOG_REVISION" ] && git_log_opts+=" $CHANGELOG_REVISION^.."
75 skip_next=false
76 git log $git_log_opts | fmt -w 80 -p "    " | while read ; do
77         if [[ $skip_next = true ]] ; then
78                 skip_next=false
79         elif [[ $REPLY = "    svn path="* ]] ; then
80                 skip_next=true
81         else
82                 echo "$REPLY"
83         fi
84 done > "$RELEASE_DIR/ChangeLog" || die "ChangeLog creation failed"
85
86 cd "${RELEASE_BUILDDIR}"
87
88 echo ">>> Creating release tarball ${RELEASE_TARBALL}"
89 tar --owner portage --group portage -cjf "${RELEASE_TARBALL}" "${RELEASE}" || \
90         die "tarball creation failed"
91
92 DISTDIR=$(portageq distdir)
93 if [ -n "${DISTDIR}" -a -d "${DISTDIR}" -a -w "${DISTDIR}" ]; then
94         echo ">>> Copying release tarball into ${DISTDIR}"
95         cp "${RELEASE_TARBALL}" "${DISTDIR}"/ || echo "!!! tarball copy failed"
96 fi
97
98 if [ -n "${UPLOAD_LOCATION}" ]; then
99         echo ">>> Uploading ${RELEASE_TARBALL} to ${UPLOAD_LOCATION}"
100         scp "${RELEASE_TARBALL}" "dev.gentoo.org:${UPLOAD_LOCATION}" || die "upload failed"
101 else
102         echo "${RELEASE_TARBALL} created"
103 fi
104
105 exit 0