Skip to content

Commit

Permalink
[brew] support the binary stanza in cask template. Resolves #300
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Jul 21, 2021
1 parent 36374b9 commit 77cd581
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.jreleaser.model.JReleaserModel;
import org.jreleaser.util.Env;
import org.jreleaser.util.Errors;
import org.jreleaser.util.PlatformUtils;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -108,36 +109,51 @@ public static void validateBrew(JReleaserContext context, Distribution distribut
}

private static void validateCask(JReleaserContext context, Distribution distribution, Brew tool, Errors errors) {
if (distribution.getType() == Distribution.DistributionType.SINGLE_JAR) {
tool.getCask().disable();
return;
}

context.getLogger().debug("distribution.{}.brew.cask", distribution.getName());

// look for a .dmg o .pkg
// look for a .dmg, .pkg. or .zip
int dmgFound = 0;
int pkgFound = 0;
int zipFound = 0;
String pkgName = "";
for (Artifact artifact : distribution.getArtifacts()) {
if (!artifact.isActive()) continue;
if (artifact.getPath().endsWith(".dmg") && !isTrue(artifact.getExtraProperties().get("skipBrew")))
if (!artifact.isActive() || !PlatformUtils.isMac(artifact.getPlatform())) continue;
if (artifact.getPath().endsWith(".dmg") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
dmgFound++;
if (artifact.getPath().endsWith(".pkg") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
} else if (artifact.getPath().endsWith(".pkg") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
pkgFound++;
pkgName = artifact.getEffectivePath(context).getFileName().toString();
} else if (artifact.getPath().endsWith(".zip") && !isTrue(artifact.getExtraProperties().get("skipBrew"))) {
zipFound++;
}
}

Cask cask = tool.getCask();

if (dmgFound == 0 && pkgFound == 0) {
if (dmgFound == 0 && pkgFound == 0 && zipFound == 0) {
// no artifacts found, disable cask
cask.disable();
return;
} else if (dmgFound > 0 && pkgFound > 0) {
errors.configuration("distribution." + distribution.getName() + ".brew can only have a single .dmg or .pkg artifact");
return;
} else if (dmgFound > 1) {
errors.configuration("distribution." + distribution.getName() + ".brew has more than one .dmg artifact");
cask.disable();
return;
} else if (pkgFound > 1) {
errors.configuration("distribution." + distribution.getName() + ".brew has more than one .pkg artifact");
cask.disable();
return;
} else if (zipFound > 1) {
errors.configuration("distribution." + distribution.getName() + ".brew has more than one .zip artifact");
cask.disable();
return;
} else if (dmgFound + pkgFound + zipFound > 1) {
errors.configuration("distribution." + distribution.getName() + ".brew can only have a single matching .dmg, .pkg, or .zip artifact");
cask.disable();
return;
}

Expand All @@ -156,6 +172,10 @@ private static void validateCask(JReleaserContext context, Distribution distribu
} else if (!cask.getAppName().endsWith(".app")) {
cask.setAppName(cask.getAppName() + ".app");
}
if (zipFound > 0) {
cask.setAppName("");
cask.setPkgName("");
}

if (isBlank(cask.getName())) {
cask.setName(tool.getResolvedFormulaName(context).toLowerCase());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cask "{{brewCaskName}}" do
version "{{projectVersion}}"
sha256 "{{distributionChecksumSha256}}"

url "{{distributionUrl}}",
verified: "{{repoHost}}"
name "{{brewCaskDisplayName}}"
desc "{{projectDescription}}"
homepage "{{projectWebsite}}"
{{#brewCaskHasAppcast}}
appcast {{brewCaskAppcast}}
{{/brewCaskHasAppcast}}
auto_updates true

{{#brewHasLivecheck}}
livecheck do
{{#brewLivecheck}}
{{.}}
{{/brewLivecheck}}
end
{{/brewHasLivecheck}}
{{#brewDependencies}}
depends_on {{.}}
{{/brewDependencies}}

{{#brewCaskHasPkg}}
pkg "{{brewCaskPkg}}"
{{/brewCaskHasPkg}}
{{#brewCaskHasApp}}
app "{{brewCaskApp}}"
{{/brewCaskHasApp}}
{{#brewCaskHasBinary}}
binary "{{distributionArtifactName}}/bin/{{distributionExecutable}}"
{{/brewCaskHasBinary}}
{{#brewCaskHasUninstall}}
{{#brewCaskUninstall}}
uninstall {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskUninstall}}
{{/brewCaskHasUninstall}}
{{#brewCaskHasZap}}
{{#brewCaskZap}}
zap {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskZap}}
{{/brewCaskHasZap}}
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cask "{{brewCaskName}}" do
version "{{projectVersion}}"
sha256 "{{distributionChecksumSha256}}"

url "{{distributionUrl}}",
verified: "{{repoHost}}"
name "{{brewCaskDisplayName}}"
desc "{{projectDescription}}"
homepage "{{projectWebsite}}"
{{#brewCaskHasAppcast}}
appcast {{brewCaskAppcast}}
{{/brewCaskHasAppcast}}
auto_updates true

{{#brewHasLivecheck}}
livecheck do
{{#brewLivecheck}}
{{.}}
{{/brewLivecheck}}
end
{{/brewHasLivecheck}}
{{#brewDependencies}}
depends_on {{.}}
{{/brewDependencies}}

{{#brewCaskHasPkg}}
pkg "{{brewCaskPkg}}"
{{/brewCaskHasPkg}}
{{#brewCaskHasApp}}
app "{{brewCaskApp}}"
{{/brewCaskHasApp}}
{{#brewCaskHasBinary}}
binary "{{distributionArtifactName}}/bin/{{distributionExecutable}}"
{{/brewCaskHasBinary}}
{{#brewCaskHasUninstall}}
{{#brewCaskUninstall}}
uninstall {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskUninstall}}
{{/brewCaskHasUninstall}}
{{#brewCaskHasZap}}
{{#brewCaskZap}}
zap {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskZap}}
{{/brewCaskHasZap}}
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cask "{{brewCaskName}}" do
version "{{projectVersion}}"
sha256 "{{distributionChecksumSha256}}"

url "{{distributionUrl}}",
verified: "{{repoHost}}"
name "{{brewCaskDisplayName}}"
desc "{{projectDescription}}"
homepage "{{projectWebsite}}"
{{#brewCaskHasAppcast}}
appcast {{brewCaskAppcast}}
{{/brewCaskHasAppcast}}
auto_updates true

{{#brewHasLivecheck}}
livecheck do
{{#brewLivecheck}}
{{.}}
{{/brewLivecheck}}
end
{{/brewHasLivecheck}}
{{#brewDependencies}}
depends_on {{.}}
{{/brewDependencies}}

{{#brewCaskHasPkg}}
pkg "{{brewCaskPkg}}"
{{/brewCaskHasPkg}}
{{#brewCaskHasApp}}
app "{{brewCaskApp}}"
{{/brewCaskHasApp}}
{{#brewCaskHasBinary}}
binary "{{distributionArtifactName}}/bin/{{distributionExecutable}}"
{{/brewCaskHasBinary}}
{{#brewCaskHasUninstall}}
{{#brewCaskUninstall}}
uninstall {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskUninstall}}
{{/brewCaskHasUninstall}}
{{#brewCaskHasZap}}
{{#brewCaskZap}}
zap {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskZap}}
{{/brewCaskHasZap}}
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
cask "{{brewCaskName}}" do
version "{{projectVersion}}"
sha256 "{{distributionChecksumSha256}}"

url "{{distributionUrl}}",
verified: "{{repoHost}}"
name "{{brewCaskDisplayName}}"
desc "{{projectDescription}}"
homepage "{{projectWebsite}}"
{{#brewCaskHasAppcast}}
appcast {{brewCaskAppcast}}
{{/brewCaskHasAppcast}}
auto_updates true

{{#brewHasLivecheck}}
livecheck do
{{#brewLivecheck}}
{{.}}
{{/brewLivecheck}}
end
{{/brewHasLivecheck}}
{{#brewDependencies}}
depends_on {{.}}
{{/brewDependencies}}

{{#brewCaskHasPkg}}
pkg "{{brewCaskPkg}}"
{{/brewCaskHasPkg}}
{{#brewCaskHasApp}}
app "{{brewCaskApp}}"
{{/brewCaskHasApp}}
{{#brewCaskHasBinary}}
binary "{{distributionArtifactName}}/bin/{{distributionExecutable}}"
{{/brewCaskHasBinary}}
{{#brewCaskHasUninstall}}
{{#brewCaskUninstall}}
uninstall {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskUninstall}}
{{/brewCaskHasUninstall}}
{{#brewCaskHasZap}}
{{#brewCaskZap}}
zap {{name}}: [
{{#items}}
"{{.}}",
{{/items}}
]
{{/brewCaskZap}}
{{/brewCaskHasZap}}
end
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ cask "{{brewCaskName}}" do
{{#brewCaskHasApp}}
app "{{brewCaskApp}}"
{{/brewCaskHasApp}}
{{#brewCaskHasBinary}}
binary "{{distributionArtifactName}}/bin/{{distributionExecutable}}"
{{/brewCaskHasBinary}}
{{#brewCaskHasUninstall}}
{{#brewCaskUninstall}}
uninstall {{name}}: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ protected boolean verifyAndAddArtifacts(Map<String, Object> props,
}
Map<String, Object> newProps = new LinkedHashMap<>(props);
newProps.put(Constants.KEY_ARTIFACT_FILE_NAME, artifactFileName);
String artifactUrl = applyTemplate(context.getModel().getRelease().getGitService().getDownloadUrl(), newProps, "downloadUrl");
String artifactUrl = applyTemplate(context.getModel().getRelease().getGitService().getDownloadUrl(), newProps);
props.put("artifact" + platform + "Url", artifactUrl);
props.putAll(context.getModel().getUpload()
.resolveDownloadUrls(context, distribution, artifact, "artifact" + platform));
Expand Down

0 comments on commit 77cd581

Please sign in to comment.