-
-
Notifications
You must be signed in to change notification settings - Fork 24
Automatically accept whatever licenses there are #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
hoff2-ACN
wants to merge
3
commits into
Malinskiy:master
Choose a base branch
from
hoff2-ACN:accept-licenses
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,179 +1,70 @@ | ||
| import * as core from "@actions/core"; | ||
| import execWithResult from "./exec-with-result"; | ||
| import * as fs from "fs"; | ||
| import {writeFile} from "fs"; | ||
| import * as util from "util"; | ||
| import {exec} from "@actions/exec/lib/exec"; | ||
| import {Emulator} from "./emulator"; | ||
|
|
||
| const ANDROID_TMP_PATH = "/tmp/android-sdk.zip" | ||
|
|
||
| let writeFileAsync = util.promisify(writeFile) | ||
|
|
||
| export interface AndroidSDK { | ||
| defaultSdkUrl: string | ||
|
|
||
| install(url: string): Promise<boolean>; | ||
|
|
||
| androidHome(): string | ||
|
|
||
| acceptLicense(): Promise<any> | ||
|
|
||
| installEmulatorPackage(api: string, tag: string, abi: string, verbose: boolean): Promise<any> | ||
|
|
||
| installPlatform(api: string, verbose: boolean): Promise<any> | ||
|
|
||
| createEmulator(name: string, api: string, tag: string, abi: string): Promise<Emulator> | ||
|
|
||
| listEmulators(): Promise<any> | ||
|
|
||
| listRunningEmulators(): Promise<Array<Emulator>> | ||
|
|
||
| startAdbServer(): Promise<any> | ||
|
|
||
| verifyHardwareAcceleration(): Promise<boolean> | ||
| } | ||
|
|
||
| export abstract class BaseAndroidSdk implements AndroidSDK { | ||
| abstract defaultSdkUrl: string | ||
|
|
||
| portCounter: number = 5554 | ||
|
|
||
| async install(url: string): Promise<boolean> { | ||
| const ANDROID_HOME = this.androidHome() | ||
|
|
||
| let sdkUrl: string = url | ||
| if (sdkUrl == null || sdkUrl == "") { | ||
| sdkUrl = this.defaultSdkUrl | ||
| } | ||
|
|
||
| if (fs.existsSync(`${process.env.HOME}/.android`)) { | ||
| await execWithResult(`mv ${process.env.HOME}/.android ${process.env.HOME}/.android.backup`) | ||
| } | ||
|
|
||
| await execWithResult(`curl -L ${sdkUrl} -o ${ANDROID_TMP_PATH} -s`) | ||
| await execWithResult(`unzip -q ${ANDROID_TMP_PATH} -d ${ANDROID_HOME}`) | ||
| await execWithResult(`rm ${ANDROID_TMP_PATH}`) | ||
| await execWithResult(`mkdir -p ${ANDROID_HOME}/sdk_home`) | ||
|
|
||
| core.exportVariable('ANDROID_HOME', `${ANDROID_HOME}`); | ||
| core.exportVariable('ANDROID_SDK_ROOT', `${ANDROID_HOME}`); | ||
| core.exportVariable('ANDROID_SDK_HOME', `${ANDROID_HOME}/sdk_home`); | ||
|
|
||
| const PATH = process.env.PATH!! | ||
| let extraPaths = `${ANDROID_HOME}/bin:${ANDROID_HOME}/tools:${PATH}/tools/bin:${PATH}/platform-tools/bin` | ||
|
|
||
| let PATH_WITHOUT_ANDROID = PATH.split(':').filter(entry => { | ||
| !entry.includes("Android") | ||
| }) | ||
|
|
||
| core.exportVariable('PATH', `${PATH_WITHOUT_ANDROID}:${extraPaths}`) | ||
| return true | ||
| } | ||
|
|
||
| androidHome(): string { | ||
| return `${process.env.HOME}/android-sdk` | ||
| import {AndroidSDK} from "./sdk"; | ||
|
|
||
| export class Emulator { | ||
| private sdk: AndroidSDK; | ||
| private readonly name: string; | ||
| private api: string; | ||
| private abi: string; | ||
| private tag: string; | ||
| private adbPort: number; | ||
| private telnetPort: number; | ||
|
|
||
| public constructor(sdk: AndroidSDK, | ||
| name: string, | ||
| api: string, | ||
| abi: string, | ||
| tag: string, | ||
| adbPort: number, | ||
| telnetPort: number) { | ||
| this.sdk = sdk | ||
| this.name = name; | ||
| this.api = api; | ||
| this.abi = abi; | ||
| this.tag = tag; | ||
| this.adbPort = adbPort; | ||
| this.telnetPort = telnetPort; | ||
| } | ||
|
|
||
| async acceptLicense(): Promise<any> { | ||
| await execWithResult(`mkdir -p ${this.androidHome()}/licenses`) | ||
|
|
||
| await writeLicenseFile(`${this.androidHome()}/licenses/android-sdk-license`, "8933bad161af4178b1185d1a37fbf41ea5269c55\n" + | ||
| "d56f5187479451eabf01fb78af6dfcb131a6481e\n" + | ||
| "24333f8a63b6825ea9c5514f83c2829b004d1fee") | ||
| await writeLicenseFile(`${this.androidHome()}/licenses/android-sdk-preview-license`, "84831b9409646a918e30573bab4c9c91346d8abd\n") | ||
| await writeLicenseFile(`${this.androidHome()}/licenses/intel-android-extra-license`, "d975f751698a77b662f1254ddbeed3901e976f5a\n") | ||
| await writeLicenseFile(`${this.androidHome()}/licenses/mips-android-sysimage-license`, "e9acab5b5fbb560a72cfaecce8946896ff6aab9d\n") | ||
| await writeLicenseFile(`${this.androidHome()}/licenses/google-gdk-license`, "33b6a2b64607f11b759f320ef9dff4ae5c47d97a\n") | ||
| await writeLicenseFile(`${this.androidHome()}/licenses/android-googletv-license`, "601085b94cd77f0b54ff86406957099ebe79c4d6\n") | ||
| } | ||
|
|
||
| async installEmulatorPackage(api: string, tag: string, abi: string, verbose: boolean): Promise<any> { | ||
| let args = "" | ||
| if (!verbose) { | ||
| args += " > /dev/null" | ||
| } | ||
|
|
||
| await execWithResult(`bash -c \\\"${this.androidHome()}/tools/bin/sdkmanager emulator tools platform-tools 'system-images;android-${api};${tag};${abi}'${args}"`); | ||
| } | ||
|
|
||
| async installPlatform(api: string, verbose: boolean): Promise<any> { | ||
| let args = "" | ||
| if (!verbose) { | ||
| args += " > /dev/null" | ||
| } | ||
|
|
||
| await execWithResult(`bash -c \\\"${this.androidHome()}/tools/bin/sdkmanager 'platforms;android-${api}'${args}"`) | ||
| } | ||
|
|
||
| async createEmulator(name: string, api: string, tag: string, abi: string): Promise<any> { | ||
| await execWithResult(`bash -c \\\"echo -n no | ${this.androidHome()}/tools/bin/avdmanager create avd -n ${name} --package \\\"system-images;android-${api};${tag};${abi}\\\" --tag ${tag}\"`) | ||
| return new Emulator(this, name, api, abi, tag, this.portCounter++, this.portCounter++) | ||
| } | ||
|
|
||
| async verifyHardwareAcceleration(): Promise<boolean> { | ||
| try { | ||
| let exitCode = await exec(`${this.androidHome()}/tools/emulator -accel-check`); | ||
| return exitCode == 0 | ||
| } catch (e) { | ||
| return false | ||
| } | ||
| async start(): Promise<any> { | ||
| await execWithResult(`bash -c \\\"${this.sdk.emulatorCmd()} @${this.name} -no-snapshot-save &\"`) | ||
| let booted = await this.waitForBoot(); | ||
| console.log(`booted=${booted}`) | ||
| return | ||
| } | ||
|
|
||
| async listEmulators(): Promise<any> { | ||
| await execWithResult(`${this.androidHome()}/tools/emulator -list-avds`) | ||
| async stop(): Promise<any> { | ||
| await execWithResult(`bash -c \\\"${this.sdk.androidHome()}/platform-tools/adb -s emulator-${this.adbPort} emu kill\"`) | ||
| console.log("emu kill finished") | ||
| return | ||
| } | ||
|
|
||
| async listRunningEmulators(): Promise<Array<Emulator>> { | ||
| let output = await execWithResult(`${this.androidHome()}/platform-tools/adb devices`) | ||
| return await this.parseDevicesOutput(output); | ||
| } | ||
|
|
||
| async parseDevicesOutput(output: string): Promise<Array<Emulator>> { | ||
| let result = new Array<Emulator>() | ||
|
|
||
| let lines = output.split(/\r?\n/); | ||
| for (let line in lines) { | ||
| if (line.startsWith("emulator")) { | ||
| let split = line.split(" "); | ||
| let serial = split[0]; | ||
| let port = serial.split("-")[1] | ||
| let nameOutput = await execWithResult(`${this.androidHome()}/platform-tools/adb adb -s ${serial} emu avd name`) | ||
| let nameLines = nameOutput.split(/\r?\n/); | ||
| let name = nameLines[0]; | ||
|
|
||
| result.fill(new Emulator(this, name, "", "", "", parseInt(port), parseInt(port) + 1)) | ||
| async waitForBoot(): Promise<boolean> { | ||
| for (let countdown = 120; countdown > 0; countdown--) { | ||
| if (countdown == 0) { | ||
| console.error("Timeout waiting for the emulator") | ||
| return false | ||
| } | ||
| try { | ||
| let output = await execWithResult(`${this.sdk.androidHome()}/platform-tools/adb shell getprop sys.boot_completed`) | ||
| if (output.trim() == '1') { | ||
| countdown = 0 | ||
| console.log("Emulator booted") | ||
| return true | ||
| } | ||
| } catch (e) { | ||
| console.error(e.message) | ||
| } | ||
| } | ||
| return result; | ||
| } | ||
|
|
||
| async startAdbServer(): Promise<any> { | ||
| await execWithResult(`${this.androidHome()}/platform-tools/adb start-server`) | ||
| } | ||
| } | ||
|
|
||
| class LinuxAndroidSdk extends BaseAndroidSdk { | ||
| defaultSdkUrl = "https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" | ||
| } | ||
|
|
||
| class MacOSAndroidSdk extends BaseAndroidSdk { | ||
| defaultSdkUrl = "https://dl.google.com/android/repository/sdk-tools-darwin-4333796.zip" | ||
| } | ||
|
|
||
| export class SdkFactory { | ||
| getAndroidSdk(): AndroidSDK { | ||
| switch (process.platform) { | ||
| case "linux": | ||
| return new LinuxAndroidSdk() | ||
| case "darwin": | ||
| return new MacOSAndroidSdk() | ||
| default: | ||
| throw new Error("Unsupported OS") | ||
| console.log("Sleeping for 1s") | ||
| await sleep(1000) | ||
| countdown-- | ||
| } | ||
| console.log("Timeout waiting for emulator to boot. Exiting") | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| async function writeLicenseFile(file: string, content: string) { | ||
| await writeFileAsync(file, content) | ||
| function sleep(ms) { | ||
| return new Promise(resolve => setTimeout(resolve, ms)); | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was already broken before so unfortunately we need to specify licenses explicitly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has been working for me, wonder what the trouble was
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "dead" code removed was only the
writeLicenseFilefunction which I was able to determine was only being used hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you look on the diff for this PR, you'll see lot's of other code removed