Skip to content

Commit c06b42f

Browse files
committed
ci-build.sh: validate deploy credentials better
We don't need CENTRAL env vars when deploying to maven.scijava.org. We don't need MAVEN env vars when deploying to Central.
1 parent 1e1b1eb commit c06b42f

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

ci-build.sh

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ EOL
165165
scmURL=${scmURL%/}
166166
if [ "$NO_DEPLOY" ]; then
167167
echo "No deploy -- the NO_DEPLOY flag is set"
168-
elif [ ! "$SIGNING_ASC" -o ! "$GPG_KEY_NAME" -o ! "$GPG_PASSPHRASE" -o ! "$MAVEN_PASS" -o ! "$CENTRAL_PASS" ]; then
169-
echo "No deploy -- secure environment variables not available"
170168
elif [ "$BUILD_REPOSITORY" -a "$BUILD_REPOSITORY" != "$scmURL" ]; then
171169
echo "No deploy -- repository fork: $BUILD_REPOSITORY != $scmURL"
170+
elif [ "$BUILD_BASE_REF" -o "$BUILD_HEAD_REF" ]; then
171+
echo "No deploy -- proposed change: $BUILD_HEAD_REF -> $BUILD_BASE_REF"
172172
else
173173
# Are we building a snapshot version, or a release version?
174174
version=$(mavenEvaluate '${project.version}')
@@ -187,6 +187,13 @@ EOL
187187
echo "Remove the file from version control and try again."
188188
exit 1
189189
fi
190+
191+
# Check for SciJava Maven repository credentials.
192+
if [ "$MAVEN_USER" -a "$MAVEN_PASS" ]; then
193+
deployOK=1
194+
else
195+
echo "No deploy -- MAVEN environment variables not available"
196+
fi
190197
;;
191198
*)
192199
# Release version -- ensure release.properties is present.
@@ -195,14 +202,43 @@ EOL
195202
echo "You must use release-version.sh to release -- see https://imagej.net/develop/releasing"
196203
exit 1
197204
fi
205+
206+
# To which repository are we releasing?
207+
releaseProfiles=$(mavenEvaluate '${releaseProfiles}')
208+
result=$?
209+
checkSuccess $result
210+
if [ $result -ne 0 ]; then
211+
echo "No deploy -- could not extract releaseProfiles string"
212+
echo "Output of failed attempt follows:"
213+
echo "$releaseProfiles"
214+
fi
215+
case "$releaseProfiles" in
216+
*deploy-to-scijava*)
217+
# Check for SciJava Maven repository credentials.
218+
if [ "$MAVEN_USER" -a "$MAVEN_PASS" ]; then
219+
deployOK=1
220+
else
221+
echo "[ERROR] Cannot deploy: MAVEN environment variables not available"
222+
exit 1
223+
fi
224+
;;
225+
*sonatype-oss-release*)
226+
# Check for Central Portal deployment credentials.
227+
# Deploy to Central requires GPG-signed artifacts.
228+
if [ "$CENTRAL_USER" -a "$CENTRAL_PASS" -a "$SIGNING_ASC" -a "$GPG_KEY_NAME" -a "$GPG_PASSPHRASE" ]; then
229+
deployOK=1
230+
else
231+
echo "[ERROR] Cannot deploy: CENTRAL environment variables not available"
232+
exit 1
233+
fi
234+
;;
235+
*)
236+
echo "Unknown deploy target -- attempting to deploy anyway"
237+
deployOK=1
238+
;;
239+
esac
198240
;;
199241
esac
200-
if [ "$BUILD_BASE_REF" -o "$BUILD_HEAD_REF" ]
201-
then
202-
echo "No deploy -- proposed change: $BUILD_HEAD_REF -> $BUILD_BASE_REF"
203-
else
204-
deployOK=1
205-
fi
206242
fi
207243
fi
208244
fi

0 commit comments

Comments
 (0)