summaryrefslogtreecommitdiffstats
path: root/azure/aria/aria-extension-cloudify/src/aria/release/asf-release.sh
blob: 18f5b3835610ef77eaf3e5b65aa615c613b0df8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


# This script is meant to help with the creation of Apache-compliant
# release candidates, as well as finalizing releases by using said candidates.
#
# Creation of a release candidate includes:
# 1) Creating a source package (a snapshot of the repository)
# 2) Creating a Pythonic sdist (generated docs, examples, etc., but no tests etc.)
# 3) Creating a Pythonic bdist (Wheel; binary distribution)
# 4) Publishing these packages on to https://dist.apache.org/repos/dist/dev/incubator/ariatosca/
# 5) Publishing the sdist and bdist packages on test-PyPI (https://test.pypi.org/)
#
# Finalization of a release includes:
# 1) Copying of the source, sdist and bdist packages from /dist/dev to /dist/release
#    (i.e. from https://dist.apache.org/repos/dist/dev/incubator/ariatosca/
#     to https://dist.apache.org/repos/dist/release/incubator/ariatosca/)
# 2) Publishing the sdist and bdist packages on PyPI (https://pypi.org)
# 3) Tagging the git repository for the release version
#
# Read more about Apache release rules and regulations at:
# 1) https://www.apache.org/dev/#releases
# 2) https://www.apache.org/legal/release-policy.html
# 3) https://www.apache.org/dev/release-distribution.html
# 4) https://www.apache.org/dev/release-publishing.html
# 5) https://www.apache.org/dev/release-signing.html
# 6) http://incubator.apache.org/incubation/Incubation_Policy.html#Releases
# 7) http://incubator.apache.org/guides/releasemanagement.html


set -e


function create_apache_release_candidate {
    if [ "$#" -lt 1 ]; then
        echo "Must provide git branch for release candidate" >&2
        return 1
    fi

    local GIT_BRANCH=$1
    local OPTIONAL_ARIATOSCA_DIST_DEV_PATH=$2

    ARIA_DIR=$(_get_aria_dir)
    pushd ${ARIA_DIR}

    git checkout ${GIT_BRANCH}
    local VERSION=$(cat VERSION)

    echo "Creating Apache release candidate for version ${VERSION}..."

    make clean
    _create_source_package ${GIT_BRANCH} ${VERSION}
    _create_sdist_and_bdist_packages
    _publish_to_apache_dev ${VERSION} ${OPTIONAL_ARIATOSCA_DIST_DEV_PATH}
    _publish_to_test_pypi
    git checkout -
    popd
}


function finalize_apache_release {
    if [ "$#" -ne 1 ]; then
        echo "Must provide git branch for release tagging" >&2
        return 1
    fi

    local GIT_BRANCH=$1

    ARIA_DIR=$(_get_aria_dir)
    pushd ${ARIA_DIR}

    git checkout ${GIT_BRANCH}
    local VERSION=$(cat VERSION)

    read -p "Enter 'Yes' to confirm release finalization for version ${VERSION}: " yn
    case $yn in
        Yes ) echo "Finalizing Apache release...";;
        * ) git checkout -; return;;
    esac

    _publish_to_apache_release ${VERSION}
    _publish_to_real_pypi
    _create_git_tag ${VERSION}
    git checkout -
    popd
}


function _get_aria_dir {
    SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
    ARIA_DIR="$(dirname "${SCRIPT_DIR}")"
    echo ${ARIA_DIR}
}


function _create_source_package {
    local GIT_BRANCH=$1
    local VERSION=$2
    local INCUBATING_ARCHIVE_CONTENT_DIR=apache-ariatosca-${VERSION}-incubating  # e.g. apache-ariatosca-0.1.0-incubating
    local INCUBATING_ARCHIVE=${INCUBATING_ARCHIVE_CONTENT_DIR}.tar.gz  # e.g. apache-ariatosca-0.1.0-incubating.tar.gz
    local SOURCE_PACKAGE_DIR="source"

    echo "Creating source package..."
    mkdir -p dist/${SOURCE_PACKAGE_DIR}
    pushd dist/${SOURCE_PACKAGE_DIR}
    # re-cloning repository, to ensure repo snapshot is clean and not environment-dependent
    wget https://github.com/apache/incubator-ariatosca/archive/${GIT_BRANCH}.zip
    unzip ${GIT_BRANCH}.zip > /dev/null
    mv incubator-ariatosca-${GIT_BRANCH} ${INCUBATING_ARCHIVE_CONTENT_DIR}
    tar -czvf ${INCUBATING_ARCHIVE} ${INCUBATING_ARCHIVE_CONTENT_DIR} > /dev/null
    rm -rf ${INCUBATING_ARCHIVE_CONTENT_DIR}
    rm ${GIT_BRANCH}.zip

    _sign_package ${INCUBATING_ARCHIVE}
    popd
}

function _sign_package {
    local ARCHIVE_NAME=$1

    echo "Signing archive ${ARCHIVE_NAME}..."
    gpg --armor --output ${ARCHIVE_NAME}.asc --detach-sig ${ARCHIVE_NAME}
    gpg --print-md MD5 ${ARCHIVE_NAME} > ${ARCHIVE_NAME}.md5
    gpg --print-md SHA512 ${ARCHIVE_NAME} > ${ARCHIVE_NAME}.sha
}


function _create_sdist_and_bdist_packages {
    local SDIST_PACKAGE_DIR="sdist"
    local BDIST_PACKAGE_DIR="bdist"

    echo "Creating sdist and bdist packages..."
    make docs
    python setup.py sdist -d dist/${SDIST_PACKAGE_DIR} bdist_wheel -d dist/${BDIST_PACKAGE_DIR}

    # pushing LICENSE and additional files into the binary distribution archive
    find dist/${BDIST_PACKAGE_DIR} -type f -name '*.whl' -exec zip -u {} LICENSE NOTICE DISCLAIMER \;

    pushd dist/${SDIST_PACKAGE_DIR}
    local SDIST_ARCHIVE=$(find . -type f -name "*.tar.gz" -printf '%P\n')
    _sign_package ${SDIST_ARCHIVE}
    popd

    pushd dist/${BDIST_PACKAGE_DIR}
    local BDIST_ARCHIVE=$(find . -type f -name "*.whl" -printf '%P\n')
    _sign_package ${BDIST_ARCHIVE}
    popd
}


function _publish_to_test_pypi {
    echo "Publishing to test PyPI..."
    _publish_to_pypi https://test.pypi.org/legacy/
}


function _publish_to_apache_dev {
    local VERSION=$1
    local ARIATOSCA_DIST_DEV_PATH=$2

    local DIST_DIR=$(pwd)/dist
    local RELEASE_DIR=${VERSION}-incubating  # e.g. 0.1.0-incubating

    echo "Publishing to Apache dist dev..."
    if [ -z "${ARIATOSCA_DIST_DEV_PATH}" ]; then
        local TMP_DIR=$(mktemp -d)
        echo "Checking out ARIA dist dev to ${TMP_DIR}"
        pushd ${TMP_DIR}
        svn co https://dist.apache.org/repos/dist/dev/incubator/ariatosca/
        popd
        pushd ${TMP_DIR}/ariatosca
    else
        pushd ${ARIATOSCA_DIST_DEV_PATH}
    fi

    svn up
    cp -r ${DIST_DIR} .
    mv dist/ ${RELEASE_DIR}/
    svn add ${RELEASE_DIR}
    svn commit -m "ARIA ${VERSION} release candidate"
    popd
}


function _publish_to_real_pypi {
    echo "Publishing to PyPI..."
    _publish_to_pypi https://upload.pypi.org/legacy/
}


function _publish_to_pypi {
    local REPOSITORY_URL=$1

    pushd dist

    pushd sdist
    local SDIST_ARCHIVE=$(find . -type f -name "*.tar.gz" -printf '%P\n')
    twine upload --repository-url ${REPOSITORY_URL} ${SDIST_ARCHIVE} ${SDIST_ARCHIVE}.asc
    popd

    pushd bdist
    local BDIST_ARCHIVE=$(find . -type f -name "*.whl" -printf '%P\n')
    twine upload --repository-url ${REPOSITORY_URL} ${BDIST_ARCHIVE} ${BDIST_ARCHIVE}.asc
    popd

    popd
}


function _publish_to_apache_release {
    local VERSION=$1
    local RELEASE_DIR=${VERSION}-incubating  # e.g. 0.1.0-incubating

    echo "Publishing to Apache dist..."

    local TMP_DIR=$(mktemp -d)
    echo "Checking out ARIA dist dev to ${TMP_DIR}"
    pushd ${TMP_DIR}

    svn co https://dist.apache.org/repos/dist/dev/incubator/ariatosca/ ariatosca-dev
    svn co https://dist.apache.org/repos/dist/release/incubator/ariatosca/ ariatosca-release
    cp -r ariatosca-dev/${RELEASE_DIR} ariatosca-release

    pushd ariatosca-release
    svn add ${RELEASE_DIR}
    # TODO: remove older releases?
    svn commit -m "ARIA ${VERSION} release"
    popd
    popd
}


function _create_git_tag {
    local VERSION=$1

    echo "Creating git tag ${VERSION}"
    git tag -a ${VERSION} -m "ARIA ${VERSION}"
    git push --tags origin
}


function pushd {
    command pushd "$@" > /dev/null
}



function popd {
    command popd "$@" > /dev/null
}



if [ "$#" -ne 2 ]; then
    echo "Usage: $0 {candidate,package} <git-branch>" >&2
    exit 1
fi

OPERATION=$1
GIT_BRANCH=$2

if [ "${OPERATION}" == "candidate" ]; then
    create_apache_release_candidate ${GIT_BRANCH}
elif [ "${OPERATION}" == "package" ]; then
    finalize_apache_release ${GIT_BRANCH}
else
    echo "First parameter must be either 'candidate' or 'package'" >&2
    exit 1
fi