Skip to content

Commit 92565b7

Browse files
committed
travisify.sh: make it work for both .org and .com
We scan the pom.xml to find out which ciManagement URL is appropriate, then invoke the "travis encrypt" and "travis encrypt-file" commands with either "--org" or "--pro" as appropriate.
1 parent 0901e13 commit 92565b7

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

travisify.sh

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ process() {
9292
die "Not pom-scijava parent: $parent. Run with -p flag to skip this check."
9393
fi
9494

95+
domain=$(grep "travis-ci\.[a-z]*/$repoSlug" pom.xml 2>/dev/null | sed 's/.*\(travis-ci\.[a-z]*\).*/\1/')
96+
test "$domain" &&
97+
info "Detected domain from pom.xml: $domain" ||
98+
die "No valid ciManagement section in pom.xml. Please add one, then try again."
99+
100+
case $domain in
101+
travis-ci.com) mode=pro;;
102+
travis-ci.org) mode=org;;
103+
*) die "Unsupported domain: $domain";;
104+
esac
105+
95106
# -- Travis sanity checks --
96107

97108
test -e "$travisDir" -a ! -d "$travisDir" && die "$travisDir is not a directory"
@@ -168,12 +179,14 @@ EOL
168179
fi
169180

170181
# update the README
171-
if ! grep -q "travis-ci.\(com\|org\)/$repoSlug" README.md >/dev/null 2>&1
182+
if grep -q "travis-ci\.[a-zA-Z0-9/_-]*\.svg" README.md >/dev/null 2>&1
172183
then
184+
info "Updating README.md Travis badge"
185+
sed "s|travis-ci\.[a-zA-Z0-9/_-]*|$domain/$repoSlug|g" README.md >"$tmpFile"
186+
update README.md 'Travis: fix README.md badge link'
187+
else
173188
info "Adding Travis badge to README.md"
174-
travisURL=$(grep travis-ci pom.xml | sed 's_.*<url>\(.*\)</url>.*_\1_')
175-
test "$travisURL" || travisURL="https://travis-ci.com/$repoSlug"
176-
echo "[![]($travisURL.svg?branch=master)]($travisURL)" >"$tmpFile"
189+
echo "[![](https://$domain/$repoSlug.svg?branch=master)]($travisURL)" >"$tmpFile"
177190
echo >>"$tmpFile"
178191
test -f README.md && cat README.md >>"$tmpFile"
179192
update README.md 'Travis: add badge to README.md'
@@ -188,7 +201,7 @@ EOL
188201
'#'*) continue;;
189202
esac
190203
info "Encrypting ${p%%=*}"
191-
$EXEC travis encrypt "$p" --add env.global --repo "$repoSlug"
204+
$EXEC travis encrypt --$mode "$p" --add env.global --repo "$repoSlug"
192205
test $? -eq 0 || die "Failed to encrypt variable '$p'"
193206
done <"$varsFile"
194207
$EXEC git commit "$travisConfig" -m "Travis: add encrypted environment variables"
@@ -203,7 +216,7 @@ EOL
203216
if [ -z "$EXEC" ]
204217
then
205218
rm -f "$signingKeyDestFile.enc"
206-
encryptOutput=$(travis encrypt-file "$signingKeySourceFile" "$signingKeyDestFile.enc" --repo "$repoSlug")
219+
encryptOutput=$(travis encrypt-file --$mode "$signingKeySourceFile" "$signingKeyDestFile.enc" --repo "$repoSlug")
207220
test $? -eq 0 || die "Failed to encrypt signing key."
208221
encryptResult=$(echo "$encryptOutput" | grep openssl)
209222
test "$encryptResult" || die "No openssl variables emitted."

0 commit comments

Comments
 (0)