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