Improved UX

- Gracefully handle URL not found
- Gracefully handle I/O error
- Add emojis
- Use a stable JAR file name
This commit is contained in:
Andres Almiray 2021-03-29 10:57:32 +02:00
parent 39f2d2f979
commit 9aff858685
2 changed files with 28 additions and 13 deletions

View file

@ -25,14 +25,12 @@ runs:
shell: bash shell: bash
run: | run: |
echo "::group::📦 Download JReleaser" echo "::group::📦 Download JReleaser"
JAR="jreleaser-tool-provider-${{ inputs.version }}.jar" java "${{ github.action_path }}/copy.java" ${{ inputs.version }}
URL="https://github.com/jreleaser/jreleaser/releases/download/${{ inputs.version }}/$JAR" java -jar jreleaser-cli.jar --version
java "${{ github.action_path }}/copy.java" $URL $JAR
java -jar $JAR --version
echo "::endgroup::" echo "::endgroup::"
- name: 'Execute JReleaser' - name: 'Execute JReleaser'
shell: bash shell: bash
run: | run: |
JAR="jreleaser-tool-provider-${{ inputs.version }}.jar" echo "☕ java -jar jreleaser-cli.jar ${{ inputs.arguments }}"
echo "☕ java -jar $JAR ${{ inputs.arguments }}" java -jar jreleaser-cli.jar ${{ inputs.arguments }}
java -jar $JAR ${{ inputs.arguments }}

View file

@ -1,19 +1,36 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URL; import java.net.URL;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Paths;
import java.nio.file.StandardCopyOption; import java.nio.file.StandardCopyOption;
class copy { class copy {
public static void main(String... args) throws Exception { public static void main(String... args) throws Exception {
if (args.length != 2) { if (args.length != 1) {
System.err.println("Usage: java copy.java URL FILENAME"); System.err.println("Usage: java copy.java VERSION");
System.exit(1); 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()) { 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); 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);
} }
} }
} }