Skip to content

Commit 1128f02

Browse files
authored
Merge pull request #99 from docker/release/v1.20.2
[BOT] Update assets for v1.20.2 release
2 parents 2c5ca4c + d534164 commit 1128f02

2 files changed

Lines changed: 60 additions & 34 deletions

File tree

index.js

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

src/index.js

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ const { fileURLToPath } = require('url');
1313
const __filename = fileURLToPath(import.meta.url);
1414
const __dirname = path.dirname(__filename);
1515

16-
async function downloadRelease(version, binaryName) {
16+
/**
17+
* Downloads the specified release of the Docker Scout Action binary from GitHub and saves it to the specified path.
18+
*
19+
* @param version The version of the release to download (e.g. "v1.2.3")
20+
* @param binaryPath The path to download the binary to
21+
* @param binaryName The name of the binary to download (e.g. "docker-scout-action_linux_amd64")
22+
* @returns {Promise<void>}
23+
*/
24+
async function downloadRelease(version, binaryPath, binaryName) {
1725
const octokit = github.getOctokit(core.getInput('github-token'))
1826

1927
let release;
@@ -29,22 +37,27 @@ async function downloadRelease(version, binaryName) {
2937
throw e
3038
}
3139

32-
const downloadDir = path.join(os.tmpdir(), `scout-action-${version}`)
33-
fs.mkdirSync(downloadDir, { recursive: true })
40+
fs.mkdirSync(binaryPath, { recursive: true })
3441

3542
for (const asset of release.data.assets) {
3643
if (asset.name === binaryName) {
37-
let binaryPath = path.join(downloadDir, asset.name);
44+
const binary = path.join(binaryPath, asset.name);
3845
core.info(`Downloading asset: ${asset.name} (${(asset.size / 1024 / 1024).toFixed(1)} MB)`)
39-
return await tc.downloadTool(asset.url, binaryPath, undefined, {
46+
await tc.downloadTool(asset.url, binary, undefined, {
4047
accept: 'application/octet-stream',
4148
})
49+
return
4250
}
4351
}
4452

4553
throw new Error(`Binary ${binaryName} not found in release ${version}`)
4654
}
4755

56+
/**
57+
* Retrieves the appropriate binary name for the current platform and architecture.
58+
*
59+
* @returns {string}
60+
*/
4861
function getBinaryName() {
4962
const platform = os.platform()
5063
const arch = os.arch()
@@ -74,26 +87,26 @@ function getBinaryName() {
7487
async function main() {
7588
const version = "__VERSION__"
7689

77-
let binaryName = getBinaryName();
78-
let binaryPath;
90+
const binaryName = getBinaryName();
91+
const binaryPath = path.join(__dirname, "dist");
92+
const binary = path.join(binaryPath, binaryName)
7993

80-
const localBinaryPath = path.join(__dirname, "dist", binaryName)
81-
if (fs.existsSync(localBinaryPath)) {
82-
binaryPath = localBinaryPath
94+
// If the binary already exists (e.g. bundled with the action), use it. Otherwise, download it from GitHub.
95+
if (fs.existsSync(binary)) {
8396
core.info(`Using bundled binary: ${binaryPath}`)
8497
} else {
85-
binaryPath = await downloadRelease(version, binaryName)
98+
await downloadRelease(version, binaryPath, binaryName)
8699
}
87100

88-
if (!fs.existsSync(binaryPath)) {
89-
throw new Error(`Binary not found at ${binaryPath}`)
101+
if (!fs.existsSync(binary)) {
102+
throw new Error(`Binary not found at ${binary}`)
90103
}
91104

92-
fs.chmodSync(binaryPath, 0o755)
105+
fs.chmodSync(binary, 0o755)
93106

94-
core.info(`Using binary: ${binaryPath}`)
107+
core.info(`Using binary: ${binary}`)
95108

96-
const result = childProcess.spawnSync(binaryPath, { stdio: 'inherit' })
109+
const result = childProcess.spawnSync(binary, { stdio: 'inherit' })
97110
if (typeof result.status === 'number') {
98111
process.exit(result.status)
99112
}

0 commit comments

Comments
 (0)