Resolve latest JReleaser release
This commit is contained in:
parent
f994696671
commit
b3708ba54c
3 changed files with 61 additions and 28 deletions
|
@ -89,7 +89,7 @@ Following inputs can be used as `step.with` keys
|
||||||
[%header,cols="<2,<,<2,<3",width="100%"]
|
[%header,cols="<2,<,<2,<3",width="100%"]
|
||||||
|===
|
|===
|
||||||
| Name | Type | Default | Description
|
| Name | Type | Default | Description
|
||||||
| version | String | early-access | The JReleaser version to use. +
|
| version | String | latest | The JReleaser version to use. +
|
||||||
Should match any of the link:https://github.com/jreleaser/jreleaser/releases[published releases].
|
Should match any of the link:https://github.com/jreleaser/jreleaser/releases[published releases].
|
||||||
| arguments | String | full-release | The JReleaser command to run.
|
| arguments | String | full-release | The JReleaser command to run.
|
||||||
| working-directory | String | ${{ github.workspace }} | The directory to change into. +
|
| working-directory | String | ${{ github.workspace }} | The directory to change into. +
|
||||||
|
|
|
@ -10,7 +10,7 @@ inputs:
|
||||||
|
|
||||||
version:
|
version:
|
||||||
description: 'The version of JReleaser to download and execute.'
|
description: 'The version of JReleaser to download and execute.'
|
||||||
default: 'early-access'
|
default: 'latest'
|
||||||
required: true
|
required: true
|
||||||
|
|
||||||
arguments:
|
arguments:
|
||||||
|
|
|
@ -6,31 +6,64 @@ import java.nio.file.Path;
|
||||||
import java.nio.file.StandardCopyOption;
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
class get_jreleaser {
|
class get_jreleaser {
|
||||||
public static void main(String... args) throws Exception {
|
public static void main(String... args) throws Exception {
|
||||||
if (args.length != 1) {
|
// default version
|
||||||
System.err.println("Usage: java get_jreleaser.java VERSION");
|
var version = "latest";
|
||||||
System.exit(1);
|
|
||||||
|
if (args.length > 1) {
|
||||||
|
System.err.println("Usage: java get_jreleaser.java [VERSION]");
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// grab the version if specified
|
||||||
|
if (args.length == 1) {
|
||||||
|
version = args[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// check
|
||||||
|
if (null == version || version.isEmpty()) {
|
||||||
|
System.out.printf("❌ Version '%s' is invalid%n", version);
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// resolve latest to a tagged release
|
||||||
|
if ("latest".equalsIgnoreCase(version)) {
|
||||||
|
var url = "https://jreleaser.org/releases/latest/download/VERSION";
|
||||||
|
var file = Path.of("VERSION");
|
||||||
|
|
||||||
|
try (var stream = new URL(url).openStream()) {
|
||||||
|
System.out.printf("✅ Located version marker%n");
|
||||||
|
Files.copy(stream, file, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
version = new String(Files.readAllBytes(file)).trim();
|
||||||
|
System.out.printf("✅ JReleaser latest resolves to %s%n", version);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.printf("❌ JReleaser %s not found%n", version);
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.printf("☠️ JReleaser %s could not be downloaded/copied%n", version);
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// setup the actual download
|
||||||
|
var url = "https://github.com/jreleaser/jreleaser/releases/download/" + version + "/jreleaser-tool-provider-" + version + ".jar";
|
||||||
|
var file = Path.of("jreleaser-cli.jar");
|
||||||
|
|
||||||
|
try (var stream = new URL(url).openStream()) {
|
||||||
|
System.out.printf("✅ Located JReleaser %s%n", version);
|
||||||
|
System.out.printf("⬇️ Downloading %s%n", url);
|
||||||
|
var size = Files.copy(stream, file, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
System.out.printf("%s << copied %d bytes%n", file, size);
|
||||||
|
System.out.printf("✅ JReleaser installed successfully%n");
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
System.out.printf("❌ JReleaser %s not found%n", version);
|
||||||
|
System.exit(1);
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.printf("☠️ JReleaser %s could not be downloaded/copied%n", version);
|
||||||
|
e.printStackTrace();
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle version = 'latest'
|
|
||||||
|
|
||||||
var version = args[0];
|
|
||||||
var url = "https://github.com/jreleaser/jreleaser/releases/download/" + version + "/jreleaser-tool-provider-" + version + ".jar";
|
|
||||||
var file = Path.of("jreleaser-cli.jar");
|
|
||||||
|
|
||||||
try (var stream = new URL(url).openStream()) {
|
|
||||||
System.out.printf("✅ Located JReleaser %s%n", version);
|
|
||||||
System.out.printf("⬇️ Downloading %s%n", url);
|
|
||||||
var size = Files.copy(stream, file, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
System.out.printf("%s << copied %d bytes%n", file, size);
|
|
||||||
System.out.printf("✅ JReleaser installed successfully%n");
|
|
||||||
} catch(FileNotFoundException e) {
|
|
||||||
System.out.printf("❌ JReleaser %s not found%n", version);
|
|
||||||
System.exit(1);
|
|
||||||
} catch(IOException e) {
|
|
||||||
System.out.printf("☠️ JReleaser %s could not be downloaded/copied%n", version);
|
|
||||||
e.printStackTrace();
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue