Skip to content

Commit 00a3690

Browse files
committed
Reinstate 'pubishArtifacts' Gradle task
This commit adds back in the Gradle `PublishArtifactsPlugin` and updates the CI to use it. The reason is that the spring-pulsar-docs module never goes to Maven Central but it does need to always go to Artifactory. Signed-off-by: Chris Bono <[email protected]> (cherry picked from commit 5647e96)
1 parent 41a7e95 commit 00a3690

File tree

5 files changed

+90
-9
lines changed

5 files changed

+90
-9
lines changed

.github/workflows/ci.yml

Lines changed: 55 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,61 @@ jobs:
115115
deploy_artifacts:
116116
name: Deploy Artifacts
117117
needs: [prerequisites, build_jdk_17, check_samples, scan]
118-
uses: spring-io/spring-security-release-tools/.github/workflows/deploy-artifacts.yml@v1
119-
with:
120-
should-deploy-artifacts: ${{ needs.prerequisites.outputs.should_deploy_artifacts }}
121-
default-publish-milestones-central: true
122-
secrets: inherit
123-
118+
runs-on: ubuntu-latest
119+
if: ${{ needs.prerequisites.outputs.should_deploy_artifacts }}
120+
steps:
121+
- uses: actions/checkout@v4
122+
- uses: spring-io/spring-gradle-build-action@v2
123+
- id: branch-name
124+
name: Extract Branch Name
125+
env:
126+
BRANCH: ${{ github.ref_name }}
127+
VERSION: ${{ needs.prerequisites.outputs.project_version }}
128+
run: |
129+
branch=$BRANCH
130+
if [[ "$branch" = "main" ]] ; then
131+
branch="${VERSION%.*}.x"
132+
fi
133+
echo "branch=$branch" >> $GITHUB_OUTPUT
134+
- id: deploy-location
135+
name: Default the Deploy Location
136+
env:
137+
VERSION: ${{ needs.prerequisites.outputs.project_version }}
138+
run: |
139+
if [[ "$VERSION" =~ "-SNAPSHOT" ]] ; then
140+
deploy_location=artifactory
141+
else
142+
deploy_location=central
143+
fi
144+
echo "deploy_location=$deploy_location" >> $GITHUB_OUTPUT
145+
- name: Publish artifacts (Artifactory or staged for Central)
146+
env:
147+
ORG_GRADLE_PROJECT_signingKey: ${{ secrets.GPG_PRIVATE_KEY }}
148+
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSPHRASE }}
149+
ARTIFACTORY_BUILD_NAME: ${{ github.event.repository.name }}-${{ steps.branch-name.outputs.branch }}
150+
ARTIFACTORY_BUILD_NUMBER: ${{ github.run_id }}
151+
ARTIFACTORY_BUILD_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
152+
ARTIFACTORY_USER_AGENT_NAME: GitHub Actions
153+
ARTIFACTORY_USER_AGENT_VERSION: Unknown
154+
ARTIFACTORY_VCS_REVISION: ${{ github.sha }
155+
run: |
156+
./gradlew publishArtifacts \
157+
--stacktrace \
158+
-PartifactoryUsername="$ARTIFACTORY_USERNAME" -PartifactoryPassword="$ARTIFACTORY_PASSWORD"
159+
- name: Publish staged artifacts to Central
160+
if: ${{ steps.deploy-location.outputs.deploy_location == 'central' }}
161+
steps:
162+
- name: Deploy
163+
uses: spring-io/central-publish-action@0cdd90d12e6876341e82860d951e1bcddc1e51b6 # v0.2.0
164+
with:
165+
token-name: ${{ secrets.SONATYPE_TOKEN_NAME }}
166+
token: ${{ secrets.SONATYPE_TOKEN }}
167+
uses: spring-io/[email protected]
168+
with:
169+
token-name: ${{ secrets.CENTRAL_TOKEN_USERNAME }}
170+
token: ${{ secrets.CENTRAL_TOKEN_PASSWORD }}
171+
dir: build/publications/repos
172+
fail-on-existing-checksums: false
124173
deploy_docs_antora:
125174
name: Deploy Antora Docs
126175
needs: [build_jdk_17, check_samples, scan]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.springframework.pulsar.gradle.publish;
2+
3+
import org.gradle.api.Plugin;
4+
import org.gradle.api.Project;
5+
6+
import org.springframework.pulsar.gradle.ProjectUtils;
7+
8+
public class PublishArtifactsPlugin implements Plugin<Project> {
9+
10+
@Override
11+
public void apply(Project project) {
12+
project.getTasks().register("stageForCentralPublish", centralPublish -> {
13+
centralPublish.setGroup("Publishing");
14+
centralPublish.setDescription("Stage the artifacts for Maven Central");
15+
centralPublish.dependsOn("publishAllPublicationsToLocalRepository");
16+
});
17+
project.getTasks().register("publishArtifacts", publishArtifacts -> {
18+
publishArtifacts.setGroup("Publishing");
19+
publishArtifacts.setDescription("Publish the artifacts to either Artifactory or Maven Central based on the version");
20+
if (ProjectUtils.isSnapshot(project) || project.getName().equals("spring-pulsar-docs")) {
21+
publishArtifacts.dependsOn("artifactoryPublish");
22+
}
23+
else {
24+
publishArtifacts.dependsOn("stageForCentralPublish");
25+
}
26+
});
27+
}
28+
29+
}

buildSrc/src/main/java/org/springframework/pulsar/gradle/publish/SpringMavenPlugin.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public void apply(Project project) {
1515
pluginManager.apply(SpringSigningPlugin.class);
1616
pluginManager.apply(MavenPublishingConventionsPlugin.class);
1717
pluginManager.apply(PublishLocalPlugin.class);
18+
pluginManager.apply(PublishArtifactsPlugin.class);
1819
pluginManager.apply(ArtifactoryPlugin.class);
1920
}
2021
}

buildSrc/src/main/java/org/springframework/pulsar/gradle/publish/SpringSigningPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void apply(Project project) {
4040

4141
private void sign(Project project) {
4242
SigningExtension signing = project.getExtensions().findByType(SigningExtension.class);
43-
signing.setRequired((Callable<Boolean>) () -> project.getGradle().getTaskGraph().hasTask("artifactoryPublish"));
43+
signing.setRequired((Callable<Boolean>) () -> project.getGradle().getTaskGraph().hasTask("publishArtifacts"));
4444
String signingKeyId = (String) project.findProperty("signingKeyId");
4545
String signingKey = (String) project.findProperty("signingKey");
4646
String signingPassword = (String) project.findProperty("signingPassword");

spring-pulsar-docs/spring-pulsar-docs.gradle

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import org.springframework.pulsar.gradle.ProjectUtils
2+
13
plugins {
24
id 'org.springframework.pulsar.spring-docs-module'
35
alias(libs.plugins.antora)
@@ -106,9 +108,9 @@ artifactoryPublish {
106108
}
107109

108110
tasks.withType(PublishToMavenRepository).configureEach {
109-
enabled = false
111+
enabled = ProjectUtils.isSnapshot(project)
110112
}
111113

112114
tasks.withType(PublishToMavenLocal).configureEach {
113-
enabled = false
115+
enabled = ProjectUtils.isSnapshot(project)
114116
}

0 commit comments

Comments
 (0)