Skip to content

Commit

Permalink
fix(ubuntu): verify command line tools is the version we want
Browse files Browse the repository at this point in the history
the directory merely existing is not sufficient to say command
line tools will work, it may be an old version

get the version and explicitly check it, remove it so fresh
install will happen if it is not the desired version
  • Loading branch information
mikehardy committed Oct 11, 2024
1 parent 3a18f50 commit 374532f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
15 changes: 13 additions & 2 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const io = __importStar(require("@actions/io"));
const tc = __importStar(require("@actions/tool-cache"));
const fs = __importStar(require("fs"));
const BUILD_TOOLS_VERSION = '35.0.0';
// SDK command-line tools 16.0
const CMDLINE_TOOLS_VERSION = '16.0'; // the downloads immediately below should correspond to this version
const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-mac-12266719_latest.zip';
const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-12266719_latest.zip';
/**
Expand All @@ -58,7 +58,18 @@ function installAndroidSdk(apiLevel, target, arch, channelId, emulatorBuild, ndk
yield exec.exec(`sh -c \\"sudo chown $USER:$USER ${process.env.ANDROID_HOME}/build-tools/${BUILD_TOOLS_VERSION} -R`);
}
const cmdlineToolsPath = `${process.env.ANDROID_HOME}/cmdline-tools`;
if (!fs.existsSync(cmdlineToolsPath)) {
// it may happen that cmdlineToolsPath exists, but is older than desired
if (fs.existsSync(cmdlineToolsPath)) {
const cmdlineToolsVer = (yield exec.getExecOutput(`sh -c "${cmdlineToolsPath}/latest/bin/sdkmanager --version"`)).stdout.trim();
if (!cmdlineToolsVer.includes(CMDLINE_TOOLS_VERSION)) {
console.log(`latest cmdline-tools is version ${cmdlineToolsVer} instead of ${CMDLINE_TOOLS_VERSION}. Removing.`);
yield exec.exec(`sh -c \\"rm -fr ${cmdlineToolsPath}/latest"`);
}
else {
console.log(`latest cmdline-tools is expected version ${CMDLINE_TOOLS_VERSION}: "${cmdlineToolsVer}"`);
}
}
if (!fs.existsSync(`${cmdlineToolsPath}/latest`)) {
console.log('Installing new cmdline-tools.');
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
const downloadPath = yield tc.downloadTool(sdkUrl);
Expand Down
16 changes: 14 additions & 2 deletions src/sdk-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as tc from '@actions/tool-cache';
import * as fs from 'fs';

const BUILD_TOOLS_VERSION = '35.0.0';
// SDK command-line tools 16.0
const CMDLINE_TOOLS_VERSION = '16.0'; // the downloads immediately below should correspond to this version
const CMDLINE_TOOLS_URL_MAC = 'https://dl.google.com/android/repository/commandlinetools-mac-12266719_latest.zip';
const CMDLINE_TOOLS_URL_LINUX = 'https://dl.google.com/android/repository/commandlinetools-linux-12266719_latest.zip';

Expand All @@ -26,7 +26,19 @@ export async function installAndroidSdk(apiLevel: string, target: string, arch:
}

const cmdlineToolsPath = `${process.env.ANDROID_HOME}/cmdline-tools`;
if (!fs.existsSync(cmdlineToolsPath)) {

// it may happen that cmdlineToolsPath exists, but is older than desired
if (fs.existsSync(cmdlineToolsPath)) {
const cmdlineToolsVer = (await exec.getExecOutput(`sh -c "${cmdlineToolsPath}/latest/bin/sdkmanager --version"`)).stdout.trim();
if (!cmdlineToolsVer.includes(CMDLINE_TOOLS_VERSION)) {
console.log(`latest cmdline-tools is version ${cmdlineToolsVer} instead of ${CMDLINE_TOOLS_VERSION}. Removing.`);
await exec.exec(`sh -c \\"rm -fr ${cmdlineToolsPath}/latest"`);
} else {
console.log(`latest cmdline-tools is expected version ${CMDLINE_TOOLS_VERSION}: "${cmdlineToolsVer}"`);
}
}

if (!fs.existsSync(`${cmdlineToolsPath}/latest`)) {
console.log('Installing new cmdline-tools.');
const sdkUrl = isOnMac ? CMDLINE_TOOLS_URL_MAC : CMDLINE_TOOLS_URL_LINUX;
const downloadPath = await tc.downloadTool(sdkUrl);
Expand Down

0 comments on commit 374532f

Please sign in to comment.