From 9aff858685712f29569024cc203d1f71623c67e0 Mon Sep 17 00:00:00 2001 From: Andres Almiray Date: Mon, 29 Mar 2021 10:57:32 +0200 Subject: [PATCH] Improved UX - Gracefully handle URL not found - Gracefully handle I/O error - Add emojis - Use a stable JAR file name --- action.yml | 12 +++++------- copy.java | 29 +++++++++++++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/action.yml b/action.yml index af64521..fe0da7f 100644 --- a/action.yml +++ b/action.yml @@ -25,14 +25,12 @@ runs: shell: bash run: | echo "::group::📦 Download JReleaser" - JAR="jreleaser-tool-provider-${{ inputs.version }}.jar" - URL="https://github.com/jreleaser/jreleaser/releases/download/${{ inputs.version }}/$JAR" - java "${{ github.action_path }}/copy.java" $URL $JAR - java -jar $JAR --version + java "${{ github.action_path }}/copy.java" ${{ inputs.version }} + java -jar jreleaser-cli.jar --version echo "::endgroup::" + - name: 'Execute JReleaser' shell: bash run: | - JAR="jreleaser-tool-provider-${{ inputs.version }}.jar" - echo "☕ java -jar $JAR ${{ inputs.arguments }}" - java -jar $JAR ${{ inputs.arguments }} + echo "☕ java -jar jreleaser-cli.jar ${{ inputs.arguments }}" + java -jar jreleaser-cli.jar ${{ inputs.arguments }} diff --git a/copy.java b/copy.java index c07188d..20ec7e7 100644 --- a/copy.java +++ b/copy.java @@ -1,19 +1,36 @@ +import java.io.FileNotFoundException; +import java.io.IOException; import java.net.URL; import java.nio.file.Files; -import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.StandardCopyOption; class copy { public static void main(String... args) throws Exception { - if (args.length != 2) { - System.err.println("Usage: java copy.java URL FILENAME"); + if (args.length != 1) { + System.err.println("Usage: java copy.java VERSION"); System.exit(1); } - var url = args[0]; + + // 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 = Paths.get("jreleaser-cli.jar"); + try (var stream = new URL(url).openStream()) { - var file = Path.of(args[1]); + 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 << %s%n", file, size, url); + 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); } } }