Download of CircleCI artifacts to store on the download page.
[SquirrelJME.git] / tools / cicd-release-bundle / src / main / java / cc / squirreljme / cicd / Main.java
blob78238ee77924758e117b826ade852f5f74bd0a01
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.cicd;
12 import cc.squirreljme.cicd.circleci.CircleCiArtifact;
13 import cc.squirreljme.cicd.circleci.CircleCiJob;
14 import cc.squirreljme.cicd.circleci.CircleCiJobArtifacts;
15 import cc.squirreljme.cicd.circleci.CircleCiWorkflowJobs;
16 import cc.squirreljme.runtime.cldc.util.StreamUtils;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.net.URI;
20 import java.nio.file.Path;
21 import java.nio.file.Paths;
22 import java.util.Arrays;
24 /**
25 * Main entry point.
27 * @since 2024/10/04
29 public class Main
31 /**
32 * Main entry point.
34 * @param __args Program arguments.
35 * @throws IOException On read/write errors.
36 * @since 2024/10/04
38 public static void main(String... __args)
39 throws IOException
41 // Needs to have something
42 if (__args == null || __args.length < 1)
43 throw new IllegalArgumentException(
44 "Usage: [version] [task=output...]");
46 // Get the SquirrelJME version
47 String version = __args[0];
49 // Upload files into the un-versioned space
50 // romNanoCoatRelease=/home/.../squirreljme.jar
51 FossilCommand fossil = FossilCommand.instance();
52 if (fossil != null)
53 for (String arg : Arrays.asList(__args).subList(1, __args.length))
55 int eq = arg.indexOf('=');
56 if (eq < 0)
57 continue;
59 // Split task name and the target file
60 String name = arg.substring(0, eq);
61 Path path = Paths.get(arg.substring(eq + 1));
63 // Determine target name
64 String target = Main.uvTarget(version, name);
66 // Store into un-versioned space
67 System.err.printf("Storing `%s` as `%s`...%n",
68 path, target);
69 fossil.add(path, target);
72 // Read in workflow jobs
73 String workflowId = System.getenv("CIRCLE_WORKFLOW_ID");
74 if (workflowId != null)
76 CircleCiWorkflowJobs jobs = CircleCiComm.workflowJobs(workflowId);
78 // Go through all jobs
79 for (CircleCiJob job : jobs.getItems())
81 // Is this a job we care about?
82 String target;
83 try
85 target = Main.uvTarget(version, job.getName());
86 if (target == null)
87 continue;
89 catch (IllegalArgumentException __ignored)
91 continue;
94 // Get artifacts for this job
95 CircleCiJobArtifacts artifacts =
96 CircleCiComm.jobArtifacts(job.getJobNumber());
97 for (CircleCiArtifact artifact : artifacts.getItems())
99 // Get the URL to the artifact
100 System.err.printf("Downloading `%s` as `%s`...%n",
101 artifact.getUrl(), target);
102 try (InputStream in = URI.create(artifact.getUrl())
103 .toURL().openStream())
105 // Store into un-versioned space
106 fossil.add(StreamUtils.readAll(1048576, in),
107 target);
110 // Only care about the first
111 break;
118 * Determines the un-versioned space target.
120 * @param __version The version of SquirrelJME.
121 * @param __name The task name.
122 * @return The resultant target.
123 * @throws IllegalArgumentException If the target is unknown.
124 * @throws NullPointerException On null arguments.
125 * @since 2024/10/05
127 public static String uvTarget(String __version, String __name)
128 throws IllegalArgumentException, NullPointerException
130 if (__version == null || __name == null)
131 throw new NullPointerException("NARG");
133 // Determine actual name
134 String name;
135 switch (__name)
137 case "romNanoCoatRelease":
138 name = "squirreljme-%s-fast.jar";
139 break;
141 case "romNanoCoatDebug":
142 name = "squirreljme-%s-slow.jar";
143 break;
145 case "romTestNanoCoatDebug":
146 name = "squirreljme-%s-slow-test.jar";
147 break;
149 case "build_windows_i386_standalone":
150 name = "squirreljme-standalone-%s-windows-x86.jar";
151 break;
153 case "build_windows_amd64_standalone":
154 name = "squirreljme-standalone-%s-windows-amd64.jar";
155 break;
157 case "build_macosx_arm64_standalone":
158 name = "squirreljme-standalone-%s-macos-aarch64.jar";
159 break;
161 case "build_macosx_amd64_standalone":
162 name = "squirreljme-standalone-%s-macos-x86_64.jar";
163 break;
165 case "build_linux_arm64_standalone":
166 name = "squirreljme-standalone-%s-linux-arm64.jar";
167 break;
169 case "build_linux_amd64_standalone":
170 name = "squirreljme-standalone-%s-linux-amd64.jar";
171 break;
173 case "build_linux_arm64_standalone_flatpak":
174 name = "squirreljme-%s-arm64.flatpak";
175 break;
177 case "build_linux_amd64_standalone_flatpak":
178 name = "squirreljme-%s-amd64.flatpak";
179 break;
181 default:
182 throw new IllegalArgumentException(
183 "Unknown target: " + __name);
186 // Construct
187 return String.format("unstable/%s",
188 String.format(name, __version));