Skip to content
This repository was archived by the owner on Jan 31, 2022. It is now read-only.

Commit d62247b

Browse files
author
Clément Le Provost
committed
Fix Maven publication (again)
It’s becoming kind of a recurring joke… :/ A single Maven upload task can only upload to a single repository. So I created another task (`testUploadArchives`) to test the upload locally. Also, I decide to disable automatic Sonatype release and Git push. The reasons are: - We cannot know what was the previous state of the staging repository on Sonatype. => Better check manually before releasing! - We don’t want to push before the release is actually available for download, which can take time.
1 parent 9a11683 commit d62247b

File tree

2 files changed

+86
-42
lines changed

2 files changed

+86
-42
lines changed

algoliasearch/common.gradle

+59-34
Original file line numberDiff line numberDiff line change
@@ -121,47 +121,72 @@ uploadArchives {
121121
beforeDeployment {
122122
MavenDeployment deployment -> signing.signPom(deployment)
123123
}
124+
editPom(pom)
124125

125-
// POM metadata.
126-
pom.groupId = PUBLISH_GROUP_ID
127-
pom.artifactId = PUBLISH_ARTIFACT_ID
128-
pom.version = PUBLISH_VERSION
129-
pom.project {
130-
name PUBLISH_NAME
131-
packaging 'aar'
132-
description PUBLISH_DESCRIPTION
133-
url 'https://github.com/algolia/algoliasearch-client-android'
126+
// Maven Central repository.
127+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
128+
authentication(
129+
userName: project.hasProperty('nexusUsername') ? project['nexusUsername'] : 'FIXME',
130+
password: project.hasProperty('nexusPassword') ? project['nexusPassword'] : 'FIXME'
131+
)
132+
}
133+
// Maven Central snapshot repository.
134+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
135+
authentication(
136+
userName: project.hasProperty('nexusUsername') ? project['nexusUsername'] : 'FIXME',
137+
password: project.hasProperty('nexusPassword') ? project['nexusPassword'] : 'FIXME'
138+
)
139+
}
140+
}
141+
}
134142

135-
scm {
136-
url 'https://github.com/algolia/algoliasearch-client-android'
137-
connection 'scm:git:https://github.com/algolia/algoliasearch-client-android.git'
138-
}
143+
// Test uploading of the archives to a local directory.
144+
task testUploadArchives(type: Upload) {
145+
configuration = configurations.archives
146+
uploadDescriptor = true
147+
repositories.mavenDeployer {
148+
beforeDeployment {
149+
MavenDeployment deployment -> signing.signPom(deployment)
150+
}
151+
editPom(pom)
152+
repository(url: "file://$buildDir/mvnrep")
153+
}
154+
}
139155

140-
licenses {
141-
license {
142-
name 'MIT'
143-
url 'http://opensource.org/licenses/MIT'
144-
}
145-
}
156+
// Edit the Maven POM.
157+
//
158+
// NOTE: This function is meant to factorize POM generation between the built-in `uploadArchives` and the custom
159+
// `testUploadArchives` tasks.
160+
//
161+
def editPom(pom) {
162+
// POM metadata.
163+
pom.groupId = PUBLISH_GROUP_ID
164+
pom.artifactId = PUBLISH_ARTIFACT_ID
165+
pom.version = PUBLISH_VERSION
166+
pom.project {
167+
name PUBLISH_NAME
168+
packaging 'aar'
169+
description PUBLISH_DESCRIPTION
170+
url 'https://github.com/algolia/algoliasearch-client-android'
171+
172+
scm {
173+
url 'https://github.com/algolia/algoliasearch-client-android'
174+
connection 'scm:git:https://github.com/algolia/algoliasearch-client-android.git'
175+
}
146176

147-
developers {
148-
developer {
149-
id 'algolia'
150-
name 'The Algolia Team'
151-
152-
}
177+
licenses {
178+
license {
179+
name 'MIT'
180+
url 'http://opensource.org/licenses/MIT'
153181
}
154182
}
155183

156-
// Local repository, to test publication contents.
157-
repository(url: "file://$buildDir/mvnrep")
158-
159-
// Maven Central repository.
160-
repository(url: PUBLISH_VERSION.endsWith("-SNAPSHOT") ? "https://oss.sonatype.org/content/repositories/snapshots/" : "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
161-
authentication(
162-
userName: project.hasProperty('nexusUsername') ? project['nexusUsername'] : 'FIXME',
163-
password: project.hasProperty('nexusPassword') ? project['nexusPassword'] : 'FIXME'
164-
)
184+
developers {
185+
developer {
186+
id 'algolia'
187+
name 'The Algolia Team'
188+
189+
}
165190
}
166191
}
167192
}

release.sh

+27-8
Original file line numberDiff line numberDiff line change
@@ -38,29 +38,48 @@ $SELF_ROOT/tools/update-version.sh $VERSION_CODE
3838

3939
for flavor in online offline
4040
do
41-
echo "========== Processing flavor '$flavor' =========="
41+
echo "==================== Processing flavor '$flavor' ===================="
4242
$SELF_ROOT/select-flavor.sh $flavor
4343
$SELF_ROOT/gradlew clean
44-
$SELF_ROOT/gradlew uploadArchives
44+
45+
# Test publication locally.
46+
echo "-------------------- Publishing locally --------------------"
47+
$SELF_ROOT/gradlew testUploadArchives
4548
if [[ $flavor = "online" ]]; then
4649
module_name="algoliasearch-android"
4750
elif [[ $flavor = "offline" ]]; then
4851
module_name="algoliasearch-offline-android"
4952
fi
5053
# Dump the contents that has been published, just for the sake of manual checking.
5154
$SELF_ROOT/tools/dump-local-mvnrep.sh $module_name
52-
echo "---------- Testing publication ----------"
55+
echo "-------------------- Testing publication --------------------"
5356
$SELF_ROOT/tools/test-publication.sh $module_name $VERSION_CODE
54-
done
5557

56-
echo "SUCCESS: closing and releasing new version..."
57-
$SELF_ROOT/gradlew closeAndPromoteRepository 1>/dev/null
58+
# Perform the actual publication.
59+
echo "-------------------- Publishing remotely --------------------"
60+
$SELF_ROOT/gradlew uploadArchives
61+
done
5862

5963
# Revert flavor to original.
6064
git checkout $SELF_ROOT/algoliasearch/build.gradle
6165

62-
# Commit to Git.
66+
# Commit to Git... but do *not* push (see below).
6367
git add .
6468
git commit -m "Version $VERSION_CODE"
6569
git tag $VERSION_CODE
66-
git push --tags origin master
70+
71+
echo "SUCCESS!"
72+
73+
# NOTE: We don't automatically publish nor Git push. Why?
74+
# - We cannot be sure what the state of the staging repository was at the beginning of the script. So publishing
75+
# without controlling it manually is risky.
76+
# - We don't want to push to Git before the release is actually available on Maven Central, which can take a few hours
77+
# after the staging repository has been promoted.
78+
#
79+
cat <<EOF
80+
Next steps:
81+
- Check the staging repository on Sonatype.
82+
- If everything is OK: close, release and drop the staging repository.
83+
- Git commit and tag.
84+
- When the release is available on Maven Central: Git push.
85+
EOF

0 commit comments

Comments
 (0)