vFW and vDNS support added to azure-plugin
[multicloud/azure.git] / azure / aria / aria-extension-cloudify / src / aria / release / asf-release.sh
1 #!/bin/bash
2 # Licensed to the Apache Software Foundation (ASF) under one or more
3 # contributor license agreements.  See the NOTICE file distributed with
4 # this work for additional information regarding copyright ownership.
5 # The ASF licenses this file to You under the Apache License, Version 2.0
6 # (the "License"); you may not use this file except in compliance with
7 # the License.  You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17
18 # This script is meant to help with the creation of Apache-compliant
19 # release candidates, as well as finalizing releases by using said candidates.
20 #
21 # Creation of a release candidate includes:
22 # 1) Creating a source package (a snapshot of the repository)
23 # 2) Creating a Pythonic sdist (generated docs, examples, etc., but no tests etc.)
24 # 3) Creating a Pythonic bdist (Wheel; binary distribution)
25 # 4) Publishing these packages on to https://dist.apache.org/repos/dist/dev/incubator/ariatosca/
26 # 5) Publishing the sdist and bdist packages on test-PyPI (https://test.pypi.org/)
27 #
28 # Finalization of a release includes:
29 # 1) Copying of the source, sdist and bdist packages from /dist/dev to /dist/release
30 #    (i.e. from https://dist.apache.org/repos/dist/dev/incubator/ariatosca/
31 #     to https://dist.apache.org/repos/dist/release/incubator/ariatosca/)
32 # 2) Publishing the sdist and bdist packages on PyPI (https://pypi.org)
33 # 3) Tagging the git repository for the release version
34 #
35 # Read more about Apache release rules and regulations at:
36 # 1) https://www.apache.org/dev/#releases
37 # 2) https://www.apache.org/legal/release-policy.html
38 # 3) https://www.apache.org/dev/release-distribution.html
39 # 4) https://www.apache.org/dev/release-publishing.html
40 # 5) https://www.apache.org/dev/release-signing.html
41 # 6) http://incubator.apache.org/incubation/Incubation_Policy.html#Releases
42 # 7) http://incubator.apache.org/guides/releasemanagement.html
43
44
45 set -e
46
47
48 function create_apache_release_candidate {
49     if [ "$#" -lt 1 ]; then
50         echo "Must provide git branch for release candidate" >&2
51         return 1
52     fi
53
54     local GIT_BRANCH=$1
55     local OPTIONAL_ARIATOSCA_DIST_DEV_PATH=$2
56
57     ARIA_DIR=$(_get_aria_dir)
58     pushd ${ARIA_DIR}
59
60     git checkout ${GIT_BRANCH}
61     local VERSION=$(cat VERSION)
62
63     echo "Creating Apache release candidate for version ${VERSION}..."
64
65     make clean
66     _create_source_package ${GIT_BRANCH} ${VERSION}
67     _create_sdist_and_bdist_packages
68     _publish_to_apache_dev ${VERSION} ${OPTIONAL_ARIATOSCA_DIST_DEV_PATH}
69     _publish_to_test_pypi
70     git checkout -
71     popd
72 }
73
74
75 function finalize_apache_release {
76     if [ "$#" -ne 1 ]; then
77         echo "Must provide git branch for release tagging" >&2
78         return 1
79     fi
80
81     local GIT_BRANCH=$1
82
83     ARIA_DIR=$(_get_aria_dir)
84     pushd ${ARIA_DIR}
85
86     git checkout ${GIT_BRANCH}
87     local VERSION=$(cat VERSION)
88
89     read -p "Enter 'Yes' to confirm release finalization for version ${VERSION}: " yn
90     case $yn in
91         Yes ) echo "Finalizing Apache release...";;
92         * ) git checkout -; return;;
93     esac
94
95     _publish_to_apache_release ${VERSION}
96     _publish_to_real_pypi
97     _create_git_tag ${VERSION}
98     git checkout -
99     popd
100 }
101
102
103 function _get_aria_dir {
104     SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
105     ARIA_DIR="$(dirname "${SCRIPT_DIR}")"
106     echo ${ARIA_DIR}
107 }
108
109
110 function _create_source_package {
111     local GIT_BRANCH=$1
112     local VERSION=$2
113     local INCUBATING_ARCHIVE_CONTENT_DIR=apache-ariatosca-${VERSION}-incubating  # e.g. apache-ariatosca-0.1.0-incubating
114     local INCUBATING_ARCHIVE=${INCUBATING_ARCHIVE_CONTENT_DIR}.tar.gz  # e.g. apache-ariatosca-0.1.0-incubating.tar.gz
115     local SOURCE_PACKAGE_DIR="source"
116
117     echo "Creating source package..."
118     mkdir -p dist/${SOURCE_PACKAGE_DIR}
119     pushd dist/${SOURCE_PACKAGE_DIR}
120     # re-cloning repository, to ensure repo snapshot is clean and not environment-dependent
121     wget https://github.com/apache/incubator-ariatosca/archive/${GIT_BRANCH}.zip
122     unzip ${GIT_BRANCH}.zip > /dev/null
123     mv incubator-ariatosca-${GIT_BRANCH} ${INCUBATING_ARCHIVE_CONTENT_DIR}
124     tar -czvf ${INCUBATING_ARCHIVE} ${INCUBATING_ARCHIVE_CONTENT_DIR} > /dev/null
125     rm -rf ${INCUBATING_ARCHIVE_CONTENT_DIR}
126     rm ${GIT_BRANCH}.zip
127
128     _sign_package ${INCUBATING_ARCHIVE}
129     popd
130 }
131
132 function _sign_package {
133     local ARCHIVE_NAME=$1
134
135     echo "Signing archive ${ARCHIVE_NAME}..."
136     gpg --armor --output ${ARCHIVE_NAME}.asc --detach-sig ${ARCHIVE_NAME}
137     gpg --print-md MD5 ${ARCHIVE_NAME} > ${ARCHIVE_NAME}.md5
138     gpg --print-md SHA512 ${ARCHIVE_NAME} > ${ARCHIVE_NAME}.sha
139 }
140
141
142 function _create_sdist_and_bdist_packages {
143     local SDIST_PACKAGE_DIR="sdist"
144     local BDIST_PACKAGE_DIR="bdist"
145
146     echo "Creating sdist and bdist packages..."
147     make docs
148     python setup.py sdist -d dist/${SDIST_PACKAGE_DIR} bdist_wheel -d dist/${BDIST_PACKAGE_DIR}
149
150     # pushing LICENSE and additional files into the binary distribution archive
151     find dist/${BDIST_PACKAGE_DIR} -type f -name '*.whl' -exec zip -u {} LICENSE NOTICE DISCLAIMER \;
152
153     pushd dist/${SDIST_PACKAGE_DIR}
154     local SDIST_ARCHIVE=$(find . -type f -name "*.tar.gz" -printf '%P\n')
155     _sign_package ${SDIST_ARCHIVE}
156     popd
157
158     pushd dist/${BDIST_PACKAGE_DIR}
159     local BDIST_ARCHIVE=$(find . -type f -name "*.whl" -printf '%P\n')
160     _sign_package ${BDIST_ARCHIVE}
161     popd
162 }
163
164
165 function _publish_to_test_pypi {
166     echo "Publishing to test PyPI..."
167     _publish_to_pypi https://test.pypi.org/legacy/
168 }
169
170
171 function _publish_to_apache_dev {
172     local VERSION=$1
173     local ARIATOSCA_DIST_DEV_PATH=$2
174
175     local DIST_DIR=$(pwd)/dist
176     local RELEASE_DIR=${VERSION}-incubating  # e.g. 0.1.0-incubating
177
178     echo "Publishing to Apache dist dev..."
179     if [ -z "${ARIATOSCA_DIST_DEV_PATH}" ]; then
180         local TMP_DIR=$(mktemp -d)
181         echo "Checking out ARIA dist dev to ${TMP_DIR}"
182         pushd ${TMP_DIR}
183         svn co https://dist.apache.org/repos/dist/dev/incubator/ariatosca/
184         popd
185         pushd ${TMP_DIR}/ariatosca
186     else
187         pushd ${ARIATOSCA_DIST_DEV_PATH}
188     fi
189
190     svn up
191     cp -r ${DIST_DIR} .
192     mv dist/ ${RELEASE_DIR}/
193     svn add ${RELEASE_DIR}
194     svn commit -m "ARIA ${VERSION} release candidate"
195     popd
196 }
197
198
199 function _publish_to_real_pypi {
200     echo "Publishing to PyPI..."
201     _publish_to_pypi https://upload.pypi.org/legacy/
202 }
203
204
205 function _publish_to_pypi {
206     local REPOSITORY_URL=$1
207
208     pushd dist
209
210     pushd sdist
211     local SDIST_ARCHIVE=$(find . -type f -name "*.tar.gz" -printf '%P\n')
212     twine upload --repository-url ${REPOSITORY_URL} ${SDIST_ARCHIVE} ${SDIST_ARCHIVE}.asc
213     popd
214
215     pushd bdist
216     local BDIST_ARCHIVE=$(find . -type f -name "*.whl" -printf '%P\n')
217     twine upload --repository-url ${REPOSITORY_URL} ${BDIST_ARCHIVE} ${BDIST_ARCHIVE}.asc
218     popd
219
220     popd
221 }
222
223
224 function _publish_to_apache_release {
225     local VERSION=$1
226     local RELEASE_DIR=${VERSION}-incubating  # e.g. 0.1.0-incubating
227
228     echo "Publishing to Apache dist..."
229
230     local TMP_DIR=$(mktemp -d)
231     echo "Checking out ARIA dist dev to ${TMP_DIR}"
232     pushd ${TMP_DIR}
233
234     svn co https://dist.apache.org/repos/dist/dev/incubator/ariatosca/ ariatosca-dev
235     svn co https://dist.apache.org/repos/dist/release/incubator/ariatosca/ ariatosca-release
236     cp -r ariatosca-dev/${RELEASE_DIR} ariatosca-release
237
238     pushd ariatosca-release
239     svn add ${RELEASE_DIR}
240     # TODO: remove older releases?
241     svn commit -m "ARIA ${VERSION} release"
242     popd
243     popd
244 }
245
246
247 function _create_git_tag {
248     local VERSION=$1
249
250     echo "Creating git tag ${VERSION}"
251     git tag -a ${VERSION} -m "ARIA ${VERSION}"
252     git push --tags origin
253 }
254
255
256 function pushd {
257     command pushd "$@" > /dev/null
258 }
259
260
261
262 function popd {
263     command popd "$@" > /dev/null
264 }
265
266
267
268 if [ "$#" -ne 2 ]; then
269     echo "Usage: $0 {candidate,package} <git-branch>" >&2
270     exit 1
271 fi
272
273 OPERATION=$1
274 GIT_BRANCH=$2
275
276 if [ "${OPERATION}" == "candidate" ]; then
277     create_apache_release_candidate ${GIT_BRANCH}
278 elif [ "${OPERATION}" == "package" ]; then
279     finalize_apache_release ${GIT_BRANCH}
280 else
281     echo "First parameter must be either 'candidate' or 'package'" >&2
282     exit 1
283 fi