blob: deb812654b912629d7e30cd92cd856c4405f07e8 [file] [log] [blame]
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +00001#!/bin/bash
2
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00003# Copyright 2015 The Bazel Authors. All rights reserved.
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +00004#
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)
18set -eu
19
20SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
21source ${SCRIPT_DIR}/testenv.sh || { echo "testenv.sh not found!" >&2; exit 1; }
22
23source ${SCRIPT_DIR}/common.sh || { echo "common.sh not found!" >&2; exit 1; }
24
25RELEASE_SCRIPT=${SCRIPT_DIR}/release.sh
26
27GERRIT_ROOT=${TEST_TMPDIR}/git/gerrit
28GITHUB_ROOT=${TEST_TMPDIR}/git/github
29WORKSPACE=${TEST_TMPDIR}/git/workspace
30export RELEASE_REPOSITORIES="${GITHUB_ROOT}"
31export MASTER_REPOSITORIES="${GITHUB_ROOT} ${GERRIT_ROOT}"
32
33setup_git_repository
34
35function 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
49EOF
50}
51
52function 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
60function 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
71function 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
106function 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
140function 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
159Important 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
174EOF
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
182if [ "\$(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
188fi
189
190# 2. write the replacement in the input file
191cat ${TEST_TMPDIR}/replacement.log >\$1
192EOF
193 chmod +x ${EDITOR}
194 create v1 1170dc6 0540fde
195 local header='Release v1 ('$(date +%Y-%m-%d)')
196
197Baseline: 1170dc6
Damien Martin-Guillerez8dc5fb22015-08-26 12:42:54 +0000198 + 0540fde: Extract version numbers that look like "..._1.2.3_..."
199 from BUILD_EMBED_LABEL into Info.plist.
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +0000200
201'
202 assert_equals "${header}Test replacement" "$(cat ${TEST_log})"
203 push
204
205 # Test creating a second candidate
Damien Martin-Guillerez6ac7bd52015-07-30 09:32:19 +0000206 echo "#!$(which true)" >${EDITOR}
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +0000207 create v1 1170dc6 0540fde cef25c4
208 header='Release v1 ('$(date +%Y-%m-%d)')
209
210Baseline: 1170dc6
Damien Martin-Guillerez8dc5fb22015-08-26 12:42:54 +0000211 + 0540fde: Extract version numbers that look like "..._1.2.3_..."
212 from BUILD_EMBED_LABEL into Info.plist.
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +0000213 + 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.
231echo 'Dummy release' >\$1
232EOF
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-Guillerez4def9d02015-10-06 15:04:53 +0000239 # Add a commit hook to test if it is ignored
240 cat <<'EOF' >.git/hooks/commit-msg
241echo HOOK-SHOULD-BE-IGNORED >>$1
242EOF
243 chmod +x .git/hooks/commit-msg
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +0000244 # Re-create release
245 create v2 2464526
246 expect_log "Release v2"
247 expect_log "Baseline: 2464526"
Damien Martin-Guillerez4def9d02015-10-06 15:04:53 +0000248 expect_not_log "HOOK-SHOULD-BE-IGNORED"
Damien Martin-Guillerezfa15d392015-07-28 15:54:40 +0000249 # Push
250 push
251 # Abandon it
252 abandon v2
253}
254
255run_suite "Release tests"