Skip to content

Commit

Permalink
Add git user setup and fix publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
lukebemish committed Nov 27, 2023
1 parent b155fcd commit b9f4f2e
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = 'dev.lukebemish'
version = '1.2.0'
version = '1.2.1'

repositories {
mavenCentral()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.gradle.api.publish.Publication;
import org.gradle.api.publish.PublishingExtension;
import org.gradle.plugins.signing.SigningExtension;
import org.gradle.plugins.signing.SigningPlugin;

import javax.inject.Inject;
import java.net.URI;
Expand Down Expand Up @@ -39,70 +38,61 @@ public void mavenCentral() {
}
}

public void mavenSnapshot() {
public void mavenSnapshot(PublishingExtension publishing) {
if (System.getenv(Constants.SNAPSHOT_MAVEN_URL) != null) {
project.getExtensions().configure(PublishingExtension.class, publishing -> {
publishing.repositories(repositories -> {
repositories.maven(maven -> {
maven.setName("PersonalMaven");
try {
maven.setUrl(new URI(System.getenv(Constants.SNAPSHOT_MAVEN_URL)));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
maven.credentials(cred -> {
cred.setUsername(System.getenv(Constants.SNAPSHOT_MAVEN_USER));
cred.setPassword(System.getenv(Constants.SNAPSHOT_MAVEN_PASSWORD));
});
publishing.repositories(repositories -> {
repositories.maven(maven -> {
maven.setName("PersonalMaven");
try {
maven.setUrl(new URI(System.getenv(Constants.SNAPSHOT_MAVEN_URL)));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
maven.credentials(cred -> {
cred.setUsername(System.getenv(Constants.SNAPSHOT_MAVEN_USER));
cred.setPassword(System.getenv(Constants.SNAPSHOT_MAVEN_PASSWORD));
});
});
});
}
}

public void mavenRelease() {
public void mavenRelease(PublishingExtension publishing) {
if (System.getenv(Constants.RELEASE_MAVEN_URL) != null) {
project.getExtensions().configure(PublishingExtension.class, publishing -> {
publishing.repositories(repositories -> {
repositories.maven(maven -> {
maven.setName("PersonalMaven");
try {
maven.setUrl(new URI(System.getenv(Constants.RELEASE_MAVEN_URL)));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
maven.credentials(cred -> {
cred.setUsername(System.getenv(Constants.RELEASE_MAVEN_USER));
cred.setPassword(System.getenv(Constants.RELEASE_MAVEN_PASSWORD));
});
publishing.repositories(repositories -> {
repositories.maven(maven -> {
maven.setName("PersonalMaven");
try {
maven.setUrl(new URI(System.getenv(Constants.RELEASE_MAVEN_URL)));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
maven.credentials(cred -> {
cred.setUsername(System.getenv(Constants.RELEASE_MAVEN_USER));
cred.setPassword(System.getenv(Constants.RELEASE_MAVEN_PASSWORD));
});
});
});
}
}

public void mavenPulLRequest() {
public void mavenPulLRequest(PublishingExtension publishing) {
if (System.getenv(Constants.PR_NUMBER) != null) {
project.getExtensions().configure(PublishingExtension.class, publishing -> {
publishing.repositories(repositories -> {
repositories.maven(maven -> {
maven.setName("LocalMaven");
maven.setUrl(project.getRootProject().getLayout().getBuildDirectory().dir("repo"));
});
publishing.repositories(repositories -> {
repositories.maven(maven -> {
maven.setName("LocalMaven");
maven.setUrl(project.getRootProject().getLayout().getBuildDirectory().dir("repo"));
});
});
}
}

public void sign(Publication... publications) {
public void sign(SigningExtension signing, Publication... publications) {
if (System.getenv(Constants.GPG_KEY) != null) {
project.getPlugins().apply(SigningPlugin.class);
project.getExtensions().configure(SigningExtension.class, signing -> {
signing.useInMemoryPgpKeys(System.getenv(Constants.GPG_KEY), System.getenv(Constants.GPG_PASSWORD));
for (Publication publication : publications) {
signing.sign(publication);
}
});
signing.useInMemoryPgpKeys(System.getenv(Constants.GPG_KEY), System.getenv(Constants.GPG_PASSWORD));
for (Publication publication : publications) {
signing.sign(publication);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,11 @@ public void uploadArtifact(String name, String path) {
this.getWith().put("name", name);
this.getWith().put("path", path);
}

public void setupGitUser() {
if (getUses().isPresent() || getRun().isPresent()) {
throw new RuntimeException("Cannot setup git user when using 'uses' or 'run'");
}
this.getUses().set("fregante/setup-git-user@v2");
}
}

0 comments on commit b9f4f2e

Please sign in to comment.