Skip to content

Commit f245a5f

Browse files
committed
travis-build.sh: centralize deploy detection
We only want to attempt deployment if we are building the official repository, not a fork, with deployment credentials available to the environment. Rather than testing for the various TRAVIS_* variables in multiple places, we now check everything once and set a single variable.
1 parent 0fbeea8 commit f245a5f

1 file changed

Lines changed: 24 additions & 9 deletions

File tree

travis-build.sh

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,27 @@ EOL
8888
EOL
8989
fi
9090

91+
# Determine whether deploying will be possible.
92+
ciURL=$(mvn -q -Denforcer.skip=true -Dexec.executable=echo -Dexec.args='${project.ciManagement.url}' --non-recursive validate exec:exec 2>/dev/null)
93+
ciRepo=${ciURL##*/}
94+
ciPrefix=${ciURL%/*}
95+
ciOrg=${ciPrefix##*/}
96+
deployOK=
97+
if [ "$TRAVIS_SECURE_ENV_VARS" != true ]
98+
then
99+
echo "No deploy -- secure environment variables not available"
100+
elif [ "$TRAVIS_PULL_REQUEST" != false ]
101+
then
102+
echo "No deploy -- pull request detected"
103+
elif [ "$TRAVIS_REPO_SLUG" != "$ciOrg/$ciRepo" ]
104+
then
105+
echo "No deploy -- repository fork: $TRAVIS_REPO_SLUG != $ciOrg/$ciRepo"
106+
# TODO: Detect travis-ci.org versus travis-ci.com?
107+
else
108+
echo "All checks passed for artifact deployment"
109+
deployOK=1
110+
fi
111+
91112
# Install GPG on OSX/macOS
92113
if [ "$TRAVIS_OS_NAME" = osx ]
93114
then
@@ -106,9 +127,7 @@ EOL
106127
openssl aes-256-cbc -K "$key" -iv "$iv" -in "$keyFile.enc" -out "$keyFile" -d
107128
checkSuccess $?
108129
fi
109-
if [ "$TRAVIS_SECURE_ENV_VARS" = true \
110-
-a "$TRAVIS_PULL_REQUEST" = false \
111-
-a -f "$keyFile" ]
130+
if [ "$deployOK" -a -f "$keyFile" ]
112131
then
113132
echo
114133
echo "== Importing GPG keypair =="
@@ -117,17 +136,13 @@ EOL
117136
fi
118137

119138
# Run the build.
120-
if [ "$TRAVIS_SECURE_ENV_VARS" = true \
121-
-a "$TRAVIS_PULL_REQUEST" = false \
122-
-a "$TRAVIS_BRANCH" = master ]
139+
if [ "$deployOK" -a "$TRAVIS_BRANCH" = master ]
123140
then
124141
echo
125142
echo "== Building and deploying master SNAPSHOT =="
126143
mvn -B -Pdeploy-to-scijava deploy
127144
checkSuccess $?
128-
elif [ "$TRAVIS_SECURE_ENV_VARS" = true \
129-
-a "$TRAVIS_PULL_REQUEST" = false \
130-
-a -f release.properties ]
145+
elif [ "$deployOK" -a -f release.properties ]
131146
then
132147
echo
133148
echo "== Cutting and deploying release version =="

0 commit comments

Comments
 (0)