Skip to content

Commit

Permalink
fix: move registry config to .releaserc file
Browse files Browse the repository at this point in the history
  • Loading branch information
error418 authored Sep 24, 2019
1 parent 4855be5 commit b6718c1
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 28 deletions.
6 changes: 4 additions & 2 deletions .releaserc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ ci: false
gradle:
node:
version: 10.16.3
detect: true # try to detect system node, if found skip download evaluation.
detect: false # try to detect system node, if found skip download evaluation.
download: true # download a node dist and use it, if it was not detected
distUrl: https://nodejs.org/dist # dist download root url (default)
packages: # extra packages needed in semantic-release plugins
- '@semantic-release/commit-analyzer'
- '@semantic-release/release-notes-generator'
- '@semantic-release/github'
- '@semantic-release/github'
config:
registry: https://registry.npmjs.orgs/
14 changes: 0 additions & 14 deletions src/main/groovy/de/illjut/gradle/semrel/NodeSetup.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ class NodeSetup {
return MessageFormat.format(this.distHrefTemplate, this.distBase, version, platform, PlatformHelper.getArch(), archiveType);
}

void copyNpmRc(File dest) {
def npmrc = new File(project.rootProject.projectDir, ".npmrc")
def target = new File(dest, ".npmrc");
if (npmrc.exists()) {
Files.copy(
npmrc.toPath(),
target.toPath(),
StandardCopyOption.REPLACE_EXISTING
);
} else if (target.exists()) {
Files.delete(target.toPath());
}
}

void setupNode(String version, File dest) {
def completeMarker = new File(dest, this.completeMarkerName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class SemanticReleaseConfig {
private final boolean autoDetectNode
private final List<String> packages
private final distUrl
private final npmConfig

SemanticReleaseConfig(File configFile = new File(".releaserc.yml")) {
Yaml yaml = new Yaml();
Expand All @@ -28,6 +29,7 @@ class SemanticReleaseConfig {
this.downloadNode = config.gradle?.node?.download == true
this.autoDetectNode = config.gradle?.node?.detect ?: false
this.nodeVersion = config.gradle?.node?.version ?: '10.16.3'
this.npmConfig = config.gradle?.config;

if (config.gradle?.node?.packages != null) {
this.packages = config.gradle.node.packages
Expand Down
24 changes: 15 additions & 9 deletions src/main/groovy/de/illjut/gradle/semrel/SemrelPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ class SemrelPlugin implements Plugin<Project> {
grgit.close()

def config = new SemanticReleaseConfig(project.rootProject.file(".releaserc.yml"))
def execConfig = ExecConfig.instance()
.registry(config.npmConfig?.registry);

def nodeVersion = config.nodeVersion;

def nodeExec = new NodeExec(project, null);
def nodeExec = new NodeExec(project, null, execConfig);

project.configure(project) {

Expand Down Expand Up @@ -77,9 +80,6 @@ class SemrelPlugin implements Plugin<Project> {
}
}

// sync with possible project npmrc
setup.copyNpmRc(project.file(semrelDir));

nodeExec.nodePath = setup.nodeBinPath;

if (!cacheCompleteMarker.exists()) { // prepare cache for faster executions
Expand All @@ -101,13 +101,14 @@ class SemrelPlugin implements Plugin<Project> {
def versionFound = false
def branch = null;
def lastVersion = null;
def version;

for (String line : result.log) { // iterate through log and try to find version marker
def matcher = (line =~ versionPattern)
if(matcher.find()) {
branch = matcher.group(1);
lastVersion = matcher.group(2);
project.version = matcher.group(3)
version = matcher.group(3)
versionFound = true
break;
}
Expand Down Expand Up @@ -136,9 +137,9 @@ class SemrelPlugin implements Plugin<Project> {

if (snapshot || !versionFound) { // append snapshot tag to version
if (gitDescribe == null) { // no git describe is possible
project.version = "${currentBranch.name}-SNAPSHOT"
version = "${currentBranch.name}-SNAPSHOT"
} else {
project.version = "${gitDescribe}-${currentBranch.name}-SNAPSHOT"
version = "${gitDescribe}-${currentBranch.name}-SNAPSHOT"
}
}

Expand All @@ -147,11 +148,16 @@ class SemrelPlugin implements Plugin<Project> {
project.logger.info "Assuming this is not a release branch."

// remove invalid characters
project.version = project.version.replace('/', '-')
version = version.replace('/', '-')
}

// remove 'v' prefix from version string to comply to artifact repository version standards
project.version = (project.version =~ /[v]?(.+)/)[0][1];
version = (version =~ /[v]?(.+)/)[0][1];

// set version on all projects
project.getAllprojects().each {
it.version = version
}

project.logger.quiet "Inferred version: ${project.version}"
project.ext.isSnapshot = snapshot
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/de/illjut/gradle/semrel/ExecConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package de.illjut.gradle.semrel;

import java.util.HashMap;
import java.util.Map;

public class ExecConfig {
private String registry = null;

public static ExecConfig instance() {
return new ExecConfig();
}

private ExecConfig() {

}

public ExecConfig registry(String registry) {
this.registry = registry;
return this;
}

public Map<String, String> buildEnvVarMap() {
Map<String, String> envVars = new HashMap<String, String>();

envVars.put("npm_config_registry", this.registry);

return envVars;
}

}
6 changes: 4 additions & 2 deletions src/main/java/de/illjut/gradle/semrel/LogStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ public LogStream(Logger logger, InputStream input) {
}

private void addLogLine(String line) {
this.log.add(line);
this.logger.info(line);
if (line.trim().length() > 0) {
this.log.add(line);
this.logger.info(line);
}
}

protected void processData(byte[] data) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/de/illjut/gradle/semrel/NodeExec.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ public class NodeExec {
private static final String NPM_EXECUTABLE = "npm";

private File nodePath = null;
private ExecConfig execConfig;

private final Logger logger;

public NodeExec(Project project, File nodePath) {
public NodeExec(Project project, File nodePath, ExecConfig config) {
this.nodePath = nodePath;
this.logger = project.getLogger();
this.execConfig = config;
}

public void setNodePath(File path) {
Expand Down Expand Up @@ -72,6 +74,8 @@ private ProcessResult exec(List<String> command, File workDir, File nodePathOver
.redirectErrorStream(true);

if (pathVar != null) processBuilder.environment().put(pathVar, pathValue);

processBuilder.environment().putAll(this.execConfig.buildEnvVarMap());

Process proc = processBuilder.start();

Expand Down

0 comments on commit b6718c1

Please sign in to comment.