Skip to content

Commit aeaba18

Browse files
[Issue #384] Implement silent licence agreement.
1 parent 423241b commit aeaba18

File tree

6 files changed

+53
-6
lines changed

6 files changed

+53
-6
lines changed

.github/workflows/build-test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ jobs:
5959

6060
runSdkManager:
6161
runs-on: ${{ matrix.os }}
62+
name: ${{ matrix.os }} - ${{ matrix.cmdline-tools-version }}
6263
strategy:
6364
fail-fast: false
6465
matrix:
@@ -89,6 +90,8 @@ jobs:
8990
- run: node dist/index.js
9091
env:
9192
INPUT_CMDLINE-TOOLS-VERSION: ${{ matrix.cmdline-tools-version }}
93+
INPUT_ACCEPT-ANDROID-SDK-LICENSES: 'true'
94+
INPUT_LOG-ACCEPTED-ANDROID-SDK-LICENSES: 'false'
9295

9396
- run: sdkmanager --list
9497

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,16 @@ To install a different version, call setup-android with desired long version as
6464

6565
Current cmdline tools version can be found at https://developer.android.com/studio#command-line-tools-only
6666

67+
68+
# Android SDK Licences
69+
70+
Android SDK (unsurprisingly) is not public domain software, it comes with a licence.
71+
72+
Input parameter `accept-android-sdk-licenses` decides if Android SDK licences should be agreed to on behalf of the user of this action.
73+
Default option is 'yes', because otherwise SDK is unusable until said licences are agreed to.
74+
75+
Licences are quite long, to prevent a wall of text in the action output, licences can be agreed to silently.
76+
Input parameter `log-accepted-android-sdk-licenses` controls whether licence texts should be printed or omitted from the text output. Defaults to 'true'.
77+
6778
# Thanks
6879
Based on the project [android-problem-matchers-action](https://github.com/jonasb/android-problem-matchers-action) from [@jonasb](https://github.com/jonasb)

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,16 @@ inputs:
88
required: false
99
default: '10406996'
1010

11+
accept-android-sdk-licenses:
12+
description: 'Android SDK is usable only after the licence agreement. Should setup-android agree to the licences, provided by "sdkmanager --licenses"'
13+
required: false
14+
default: 'true'
15+
16+
log-accepted-android-sdk-licenses:
17+
description: 'Should accepted licences be logged. If not, accepted licences will be accepted silently'
18+
required: false
19+
default: 'true'
20+
1121
runs:
1222
using: node20
1323
main: 'dist/index.js'

dist/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28183,11 +28183,12 @@ const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/comm
2818328183
const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/commandlinetools-linux-${VERSION_LONG}_latest.zip`;
2818428184
const ANDROID_HOME_SDK_DIR = path.join(os.homedir(), '.android', 'sdk');
2818528185
let ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR;
28186-
function callSdkManager(sdkManager, arg) {
28186+
function callSdkManager(sdkManager, arg, printOutput = true) {
2818728187
return __awaiter(this, void 0, void 0, function* () {
2818828188
const acceptBuffer = Buffer.from(Array(10).fill('y').join('\n'), 'utf8');
2818928189
yield exec.exec(sdkManager, [arg], {
28190-
input: acceptBuffer
28190+
input: acceptBuffer,
28191+
silent: !printOutput
2819128192
});
2819228193
});
2819328194
}
@@ -28264,7 +28265,10 @@ function run() {
2826428265
}
2826528266
}
2826628267
const sdkManagerExe = yield installSdkManager();
28267-
yield callSdkManager(sdkManagerExe, '--licenses');
28268+
if (core.getBooleanInput('accept-android-sdk-licenses')) {
28269+
core.info('Accepting Android SDK licences');
28270+
yield callSdkManager(sdkManagerExe, '--licenses', core.getBooleanInput('log-accepted-android-sdk-licenses'));
28271+
}
2826828272
yield callSdkManager(sdkManagerExe, 'tools');
2826928273
yield callSdkManager(sdkManagerExe, 'platform-tools');
2827028274
core.setOutput('ANDROID_COMMANDLINE_TOOLS_VERSION', VERSION_LONG);

src/main.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,15 @@ const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/comm
3838
const ANDROID_HOME_SDK_DIR = path.join(os.homedir(), '.android', 'sdk')
3939
let ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR
4040

41-
async function callSdkManager(sdkManager: string, arg: string): Promise<void> {
41+
async function callSdkManager(
42+
sdkManager: string,
43+
arg: string,
44+
printOutput: Boolean = true
45+
): Promise<void> {
4246
const acceptBuffer = Buffer.from(Array(10).fill('y').join('\n'), 'utf8')
4347
await exec.exec(sdkManager, [arg], {
44-
input: acceptBuffer
48+
input: acceptBuffer,
49+
silent: !printOutput
4550
})
4651
}
4752

@@ -142,7 +147,15 @@ async function run(): Promise<void> {
142147
}
143148

144149
const sdkManagerExe = await installSdkManager()
145-
await callSdkManager(sdkManagerExe, '--licenses')
150+
151+
if (core.getBooleanInput('accept-android-sdk-licenses')) {
152+
core.info('Accepting Android SDK licences')
153+
await callSdkManager(
154+
sdkManagerExe,
155+
'--licenses',
156+
core.getBooleanInput('log-accepted-android-sdk-licenses')
157+
)
158+
}
146159
await callSdkManager(sdkManagerExe, 'tools')
147160
await callSdkManager(sdkManagerExe, 'platform-tools')
148161

0 commit comments

Comments
 (0)