Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 3 | # Copyright 2015 The Bazel Authors. All rights reserved. |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # 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 | # Tests release notes generation (relnotes.sh) |
| 18 | set -eu |
| 19 | |
| 20 | SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 21 | source ${SCRIPT_DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; } |
| 22 | |
| 23 | source ${SCRIPT_DIR}/common.sh || { echo "common.sh not found!" >&2; exit 1; } |
| 24 | |
| 25 | RELEASE_SCRIPT=${SCRIPT_DIR}/release.sh |
| 26 | |
| 27 | GERRIT_ROOT=${TEST_TMPDIR}/git/gerrit |
| 28 | GITHUB_ROOT=${TEST_TMPDIR}/git/github |
| 29 | WORKSPACE=${TEST_TMPDIR}/git/workspace |
| 30 | export RELEASE_REPOSITORIES="${GITHUB_ROOT}" |
| 31 | export MASTER_REPOSITORIES="${GITHUB_ROOT} ${GERRIT_ROOT}" |
| 32 | |
| 33 | setup_git_repository |
| 34 | |
| 35 | function set_up() { |
| 36 | # Clean previous clones |
| 37 | rm -fr ${GERRIT_ROOT} ${GITHUB_ROOT} ${WORKSPACE} |
| 38 | # Now creates the clones |
| 39 | git clone -l --bare -q ${MASTER_ROOT} ${GERRIT_ROOT} |
| 40 | git clone -l --bare -q ${MASTER_ROOT} ${GITHUB_ROOT} |
| 41 | # And the working copy |
| 42 | git clone -l -q ${GERRIT_ROOT} ${WORKSPACE} |
| 43 | cd ${WORKSPACE} |
| 44 | # Avoid committer message |
| 45 | cat >>.git/config <<EOF |
| 46 | [user] |
| 47 | name = Bazel tests |
| 48 | email = noreply@google.com |
| 49 | EOF |
| 50 | } |
| 51 | |
| 52 | function create() { |
| 53 | ${RELEASE_SCRIPT} create $@ \ |
| 54 | || fail "Failed to cut release $1 at commit $2" |
| 55 | local branch=$(git_get_branch) |
| 56 | assert_equals "release-$1" "$branch" |
| 57 | git show -s --pretty=format:%B >$TEST_log |
| 58 | } |
| 59 | |
| 60 | function push() { |
| 61 | local branch=$(git_get_branch) |
| 62 | ${RELEASE_SCRIPT} push || fail "Failed to push release branch $branch" |
| 63 | git --git-dir=${GITHUB_ROOT} branch >$TEST_log |
| 64 | expect_log "$branch" |
| 65 | git --git-dir=${GERRIT_ROOT} branch >$TEST_log |
| 66 | expect_not_log "$branch" |
| 67 | assert_equals "$(git show -s --pretty=format:%B $branch)" \ |
| 68 | "$(git --git-dir=${GITHUB_ROOT} show -s --pretty=format:%B $branch)" |
| 69 | } |
| 70 | |
| 71 | function release() { |
| 72 | local tag=$1 |
| 73 | local branch=$(git_get_branch) |
| 74 | local changelog=$(cat CHANGELOG.md) |
| 75 | local commit=$(git show -s --pretty=format:%B $branch) |
| 76 | echo y | ${RELEASE_SCRIPT} release || fail "Failed to release ${branch}" |
| 77 | assert_equals master "$(git_get_branch)" |
| 78 | git tag >$TEST_log |
| 79 | expect_log $tag |
| 80 | git --git-dir=${GITHUB_ROOT} tag >$TEST_log |
| 81 | expect_log $tag |
| 82 | git --git-dir=${GERRIT_ROOT} tag >$TEST_log |
| 83 | expect_not_log $tag |
| 84 | # Test commit is everywhere |
| 85 | assert_equals "$commit" "$(git show -s --pretty=format:%B $tag)" |
| 86 | assert_equals "$commit" "$(git show -s --pretty=format:%B master)" |
| 87 | assert_equals "$commit" \ |
| 88 | "$(git --git-dir=${GITHUB_ROOT} show -s --pretty=format:%B $tag)" |
| 89 | assert_equals "$commit" \ |
| 90 | "$(git --git-dir=${GITHUB_ROOT} show -s --pretty=format:%B master)" |
| 91 | assert_equals "$commit" \ |
| 92 | "$(git --git-dir=${GERRIT_ROOT} show -s --pretty=format:%B master)" |
| 93 | |
| 94 | # Now test for CHANGELOG.md file in master branch |
| 95 | assert_equals "$changelog" "$(git show $tag:CHANGELOG.md)" |
| 96 | assert_equals "$changelog" "$(git show master:CHANGELOG.md)" |
| 97 | assert_equals "$changelog" \ |
| 98 | "$(git --git-dir=${GITHUB_ROOT} show $tag:CHANGELOG.md)" |
| 99 | assert_equals "$changelog" \ |
| 100 | "$(git --git-dir=${GITHUB_ROOT} show master:CHANGELOG.md)" |
| 101 | assert_equals "$changelog" \ |
| 102 | "$(git --git-dir=${GERRIT_ROOT} show master:CHANGELOG.md)" |
| 103 | |
| 104 | } |
| 105 | |
| 106 | function abandon() { |
| 107 | local tag="$1" |
| 108 | local branch=$(git_get_branch) |
| 109 | local changelog="$(git show master:CHANGELOG.md)" |
| 110 | local master_sha1=$(git rev-parse master) |
| 111 | echo y | ${RELEASE_SCRIPT} abandon || fail "Failed to abandon release ${branch}" |
| 112 | assert_equals master "$(git_get_branch)" |
| 113 | |
| 114 | # test release was not tagged |
| 115 | git tag >$TEST_log |
| 116 | expect_not_log $tag |
| 117 | git --git-dir=${GITHUB_ROOT} tag >$TEST_log |
| 118 | expect_not_log $tag |
| 119 | git --git-dir=${GERRIT_ROOT} tag >$TEST_log |
| 120 | expect_not_log $tag |
| 121 | |
| 122 | # Test branch was deleted |
| 123 | git branch >$TEST_log |
| 124 | expect_not_log $branch |
| 125 | git --git-dir=${GITHUB_ROOT} branch >$TEST_log |
| 126 | expect_not_log $branch |
| 127 | |
| 128 | # Test the master branch commit hasn't changed |
| 129 | assert_equals "$(git rev-parse master)" "${master_sha1}" |
| 130 | |
| 131 | # Now test for CHANGELOG.md file in master branch hasn't changed |
| 132 | assert_equals "$changelog" "$(git show master:CHANGELOG.md)" |
| 133 | assert_equals "$changelog" \ |
| 134 | "$(git --git-dir=${GITHUB_ROOT} show master:CHANGELOG.md)" |
| 135 | assert_equals "$changelog" \ |
| 136 | "$(git --git-dir=${GERRIT_ROOT} show master:CHANGELOG.md)" |
| 137 | |
| 138 | } |
| 139 | |
| 140 | function test_release_workflow() { |
| 141 | export EDITOR=true |
| 142 | # Initial release |
| 143 | create v0 965c392 |
| 144 | expect_log "Release v0" |
| 145 | expect_log "Initial release" |
| 146 | # Push the release branch |
| 147 | push |
| 148 | # Do the initial release |
| 149 | release v0 |
| 150 | |
| 151 | # Second release. |
| 152 | |
| 153 | # First we need to edit the logs |
| 154 | export EDITOR=${TEST_TMPDIR}/editor.sh |
| 155 | local RELNOTES='Incompatible changes: |
| 156 | |
| 157 | - Remove deprecated "make var" INCDIR |
| 158 | |
| 159 | Important changes: |
| 160 | |
| 161 | - Use a default implementation of a progress message, rather than |
| 162 | defaulting to null for all SpawnActions.' |
| 163 | |
| 164 | cat >${TEST_TMPDIR}/expected.log <<EOF |
| 165 | # Editing release notes |
| 166 | # Modify the release notes to make them suitable for the release. |
| 167 | # Every line starting with a # will be removed as well as every |
| 168 | # empty line at the start and at the end. |
| 169 | |
| 170 | # Release v1 ($(date +%Y-%m-%d)) |
| 171 | |
| 172 | ${RELNOTES} |
| 173 | |
| 174 | EOF |
| 175 | |
| 176 | echo "Test replacement" >${TEST_TMPDIR}/replacement.log |
| 177 | |
| 178 | cat >${EDITOR} <<EOF |
| 179 | #!/bin/bash |
| 180 | |
| 181 | # 1. Assert the file is correct |
| 182 | if [ "\$(cat \$1)" != "\$(cat ${TEST_TMPDIR}/expected.log)" ]; then |
| 183 | echo "Expected:" >&2 |
| 184 | cat ${TEST_TMPDIR}/expected.log >&2 |
| 185 | echo "Got:" >&2 |
| 186 | cat \$1 >&2 |
| 187 | exit 1 |
| 188 | fi |
| 189 | |
| 190 | # 2. write the replacement in the input file |
| 191 | cat ${TEST_TMPDIR}/replacement.log >\$1 |
| 192 | EOF |
| 193 | chmod +x ${EDITOR} |
| 194 | create v1 1170dc6 0540fde |
| 195 | local header='Release v1 ('$(date +%Y-%m-%d)') |
| 196 | |
| 197 | Baseline: 1170dc6 |
Damien Martin-Guillerez | 8dc5fb2 | 2015-08-26 12:42:54 +0000 | [diff] [blame] | 198 | + 0540fde: Extract version numbers that look like "..._1.2.3_..." |
| 199 | from BUILD_EMBED_LABEL into Info.plist. |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 200 | |
| 201 | ' |
| 202 | assert_equals "${header}Test replacement" "$(cat ${TEST_log})" |
| 203 | push |
| 204 | |
| 205 | # Test creating a second candidate |
Damien Martin-Guillerez | 6ac7bd5 | 2015-07-30 09:32:19 +0000 | [diff] [blame] | 206 | echo "#!$(which true)" >${EDITOR} |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 207 | create v1 1170dc6 0540fde cef25c4 |
| 208 | header='Release v1 ('$(date +%Y-%m-%d)') |
| 209 | |
| 210 | Baseline: 1170dc6 |
Damien Martin-Guillerez | 8dc5fb2 | 2015-08-26 12:42:54 +0000 | [diff] [blame] | 211 | + 0540fde: Extract version numbers that look like "..._1.2.3_..." |
| 212 | from BUILD_EMBED_LABEL into Info.plist. |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 213 | + cef25c4: RELNOTES: Attribute error messages related to Android |
| 214 | resources are easier to understand now. |
| 215 | |
| 216 | ' |
| 217 | RELNOTES="${RELNOTES}"' |
| 218 | - Attribute error messages related to Android resources are easier |
| 219 | to understand now.' |
| 220 | assert_equals "${header}${RELNOTES}" "$(cat ${TEST_log})" |
| 221 | assert_equals 2 "$(get_release_candidate)" |
| 222 | |
| 223 | # Push the release |
| 224 | push |
| 225 | release v1 |
| 226 | |
| 227 | # Third release to test abandon |
| 228 | cat >${EDITOR} <<EOF |
| 229 | #!/bin/bash |
| 230 | # Make sure we have release notes or the release will be cancelled. |
| 231 | echo 'Dummy release' >\$1 |
| 232 | EOF |
| 233 | # Create release |
| 234 | create v2 2464526 |
| 235 | expect_log "Release v2" |
| 236 | expect_log "Baseline: 2464526" |
| 237 | # Abandon it |
| 238 | abandon v2 |
Damien Martin-Guillerez | 4def9d0 | 2015-10-06 15:04:53 +0000 | [diff] [blame] | 239 | # Add a commit hook to test if it is ignored |
| 240 | cat <<'EOF' >.git/hooks/commit-msg |
| 241 | echo HOOK-SHOULD-BE-IGNORED >>$1 |
| 242 | EOF |
| 243 | chmod +x .git/hooks/commit-msg |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 244 | # Re-create release |
| 245 | create v2 2464526 |
| 246 | expect_log "Release v2" |
| 247 | expect_log "Baseline: 2464526" |
Damien Martin-Guillerez | 4def9d0 | 2015-10-06 15:04:53 +0000 | [diff] [blame] | 248 | expect_not_log "HOOK-SHOULD-BE-IGNORED" |
Damien Martin-Guillerez | fa15d39 | 2015-07-28 15:54:40 +0000 | [diff] [blame] | 249 | # Push |
| 250 | push |
| 251 | # Abandon it |
| 252 | abandon v2 |
| 253 | } |
| 254 | |
| 255 | run_suite "Release tests" |