@@ -33912,7 +33912,15 @@ function requireSrc () {
3391233912 const __filename = fileURLToPath(import.meta.url);
3391333913 const __dirname = path.dirname(__filename);
3391433914
33915- async function downloadRelease(version, binaryName) {
33915+ /**
33916+ * Downloads the specified release of the Docker Scout Action binary from GitHub and saves it to the specified path.
33917+ *
33918+ * @param version The version of the release to download (e.g. "v1.2.3")
33919+ * @param binaryPath The path to download the binary to
33920+ * @param binaryName The name of the binary to download (e.g. "docker-scout-action_linux_amd64")
33921+ * @returns {Promise<void>}
33922+ */
33923+ async function downloadRelease(version, binaryPath, binaryName) {
3391633924 const octokit = github.getOctokit(core.getInput('github-token'));
3391733925
3391833926 let release;
@@ -33928,22 +33936,27 @@ function requireSrc () {
3392833936 throw e
3392933937 }
3393033938
33931- const downloadDir = path.join(os.tmpdir(), `scout-action-${version}`);
33932- fs.mkdirSync(downloadDir, { recursive: true });
33939+ fs.mkdirSync(binaryPath, { recursive: true });
3393333940
3393433941 for (const asset of release.data.assets) {
3393533942 if (asset.name === binaryName) {
33936- let binaryPath = path.join(downloadDir , asset.name);
33943+ const binary = path.join(binaryPath , asset.name);
3393733944 core.info(`Downloading asset: ${asset.name} (${(asset.size / 1024 / 1024).toFixed(1)} MB)`);
33938- return await tc.downloadTool(asset.url, binaryPath , undefined, {
33945+ await tc.downloadTool(asset.url, binary , undefined, {
3393933946 accept: 'application/octet-stream',
33940- })
33947+ });
33948+ return
3394133949 }
3394233950 }
3394333951
3394433952 throw new Error(`Binary ${binaryName} not found in release ${version}`)
3394533953 }
3394633954
33955+ /**
33956+ * Retrieves the appropriate binary name for the current platform and architecture.
33957+ *
33958+ * @returns {string}
33959+ */
3394733960 function getBinaryName() {
3394833961 const platform = os.platform();
3394933962 const arch = os.arch();
@@ -33971,28 +33984,28 @@ function requireSrc () {
3397133984 }
3397233985
3397333986 async function main() {
33974- const version = "v1.20.1 ";
33987+ const version = "v1.20.2 ";
3397533988
33976- let binaryName = getBinaryName();
33977- let binaryPath;
33989+ const binaryName = getBinaryName();
33990+ const binaryPath = path.join(__dirname, "dist");
33991+ const binary = path.join(binaryPath, binaryName);
3397833992
33979- const localBinaryPath = path.join(__dirname, "dist", binaryName);
33980- if (fs.existsSync(localBinaryPath)) {
33981- binaryPath = localBinaryPath;
33993+ // If the binary already exists (e.g. bundled with the action), use it. Otherwise, download it from GitHub.
33994+ if (fs.existsSync(binary)) {
3398233995 core.info(`Using bundled binary: ${binaryPath}`);
3398333996 } else {
33984- binaryPath = await downloadRelease(version, binaryName);
33997+ await downloadRelease(version, binaryPath , binaryName);
3398533998 }
3398633999
33987- if (!fs.existsSync(binaryPath )) {
33988- throw new Error(`Binary not found at ${binaryPath }`)
34000+ if (!fs.existsSync(binary )) {
34001+ throw new Error(`Binary not found at ${binary }`)
3398934002 }
3399034003
33991- fs.chmodSync(binaryPath , 0o755);
34004+ fs.chmodSync(binary , 0o755);
3399234005
33993- core.info(`Using binary: ${binaryPath }`);
34006+ core.info(`Using binary: ${binary }`);
3399434007
33995- const result = childProcess.spawnSync(binaryPath , { stdio: 'inherit' });
34008+ const result = childProcess.spawnSync(binary , { stdio: 'inherit' });
3399634009 if (typeof result.status === 'number') {
3399734010 process.exit(result.status);
3399834011 }
0 commit comments