mirror of
https://gitea.com/actions/setup-android.git
synced 2026-03-26 22:58:21 +00:00
Compare commits
66 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
651bceb6f9 | ||
|
|
144235e058 | ||
|
|
200c644fca | ||
|
|
715acc5ce1 | ||
|
|
125835f877 | ||
|
|
c4c8fe5bcd | ||
|
|
6a40db5374 | ||
|
|
641d7f5e80 | ||
|
|
9fc6c4e906 | ||
|
|
edebe8927a | ||
|
|
2022e05939 | ||
|
|
f34c17e4f4 | ||
|
|
29d7cbabdd | ||
|
|
bb5134ce76 | ||
|
|
4b7c168f7a | ||
|
|
39fe32d9f9 | ||
|
|
9b404b77f3 | ||
|
|
b15b7e58c1 | ||
|
|
12a392d9f4 | ||
|
|
f3fd7c000f | ||
|
|
5baef82307 | ||
|
|
3963848dab | ||
|
|
c55407a479 | ||
|
|
4aaec39eee | ||
|
|
e1f5280adf | ||
|
|
961a5d9791 | ||
|
|
00854ea68c | ||
|
|
0d0e8c3af6 | ||
|
|
a9d7b728b4 | ||
|
|
93337aeebc | ||
|
|
c39b220a9b | ||
|
|
76b557c697 | ||
|
|
b7334e0985 | ||
|
|
8252dc7232 | ||
|
|
07976c6290 | ||
|
|
56927e38e2 | ||
|
|
eb7920b260 | ||
|
|
a86cdbf03d | ||
|
|
713cbf481b | ||
|
|
1297b09c09 | ||
|
|
d24156dbc9 | ||
|
|
ade8112388 | ||
|
|
aeaba18a12 | ||
|
|
423241b186 | ||
|
|
4113fd9036 | ||
|
|
0549df86ae | ||
|
|
b6023dae3a | ||
|
|
ded9227d6b | ||
|
|
449627e76b | ||
|
|
8023252681 | ||
|
|
9584f05408 | ||
|
|
13f81365a4 | ||
|
|
110787489d | ||
|
|
4ba30747dc | ||
|
|
a3da945276 | ||
|
|
1cb03f027b | ||
|
|
ccc0939481 | ||
|
|
fabcc053ca | ||
|
|
bee5ac3f90 | ||
|
|
26c86ac3f5 | ||
|
|
bc52f43eb3 | ||
|
|
899d70efad | ||
|
|
7c5672355a | ||
|
|
be14762587 | ||
|
|
02a4c0fae6 | ||
|
|
4963c9b31a |
@@ -1,3 +0,0 @@
|
||||
dist/
|
||||
lib/
|
||||
node_modules/
|
||||
@@ -1,55 +0,0 @@
|
||||
{
|
||||
"plugins": ["jest", "@typescript-eslint"],
|
||||
"extends": ["plugin:github/recommended"],
|
||||
"parser": "@typescript-eslint/parser",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 9,
|
||||
"sourceType": "module",
|
||||
"project": "./tsconfig.json"
|
||||
},
|
||||
"rules": {
|
||||
"eslint-comments/no-use": "off",
|
||||
"import/no-namespace": "off",
|
||||
"no-unused-vars": "off",
|
||||
"@typescript-eslint/no-unused-vars": "error",
|
||||
"@typescript-eslint/explicit-member-accessibility": ["error", {"accessibility": "no-public"}],
|
||||
"@typescript-eslint/no-require-imports": "error",
|
||||
"@typescript-eslint/array-type": "error",
|
||||
"@typescript-eslint/await-thenable": "error",
|
||||
"@typescript-eslint/ban-ts-comment": "error",
|
||||
"camelcase": "off",
|
||||
"@typescript-eslint/consistent-type-assertions": "error",
|
||||
"@typescript-eslint/explicit-function-return-type": ["error", {"allowExpressions": true}],
|
||||
"@typescript-eslint/func-call-spacing": ["error", "never"],
|
||||
"@typescript-eslint/no-array-constructor": "error",
|
||||
"@typescript-eslint/no-empty-interface": "error",
|
||||
"@typescript-eslint/no-explicit-any": "error",
|
||||
"@typescript-eslint/no-extraneous-class": "error",
|
||||
"@typescript-eslint/no-for-in-array": "error",
|
||||
"@typescript-eslint/no-inferrable-types": "error",
|
||||
"@typescript-eslint/no-misused-new": "error",
|
||||
"@typescript-eslint/no-namespace": "error",
|
||||
"@typescript-eslint/no-non-null-assertion": "warn",
|
||||
"@typescript-eslint/no-unnecessary-qualifier": "error",
|
||||
"@typescript-eslint/no-unnecessary-type-assertion": "error",
|
||||
"@typescript-eslint/no-useless-constructor": "error",
|
||||
"@typescript-eslint/no-var-requires": "error",
|
||||
"@typescript-eslint/prefer-for-of": "warn",
|
||||
"@typescript-eslint/prefer-function-type": "warn",
|
||||
"@typescript-eslint/prefer-includes": "error",
|
||||
"@typescript-eslint/prefer-string-starts-ends-with": "error",
|
||||
"@typescript-eslint/promise-function-async": "error",
|
||||
"@typescript-eslint/require-array-sort-compare": "error",
|
||||
"@typescript-eslint/restrict-plus-operands": "error",
|
||||
"semi": "off",
|
||||
"@typescript-eslint/semi": ["error", "never"],
|
||||
"@typescript-eslint/type-annotation-spacing": "error",
|
||||
"i18n-text/no-en": "warn",
|
||||
"@typescript-eslint/unbound-method": "error"
|
||||
},
|
||||
"env": {
|
||||
"node": true,
|
||||
"es6": true,
|
||||
"jest/globals": true
|
||||
}
|
||||
}
|
||||
81
.github/workflows/build-test.yml
vendored
81
.github/workflows/build-test.yml
vendored
@@ -1,13 +1,7 @@
|
||||
name: Build & Test
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- releases/*
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
|
||||
@@ -15,12 +9,12 @@ jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup node 16
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup node 24
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '16'
|
||||
node-version: 24
|
||||
|
||||
- run: npm ci
|
||||
|
||||
@@ -32,12 +26,12 @@ jobs:
|
||||
format-check:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup node 16
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup node 24
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '16'
|
||||
node-version: 24
|
||||
|
||||
- run: npm ci
|
||||
|
||||
@@ -46,12 +40,12 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup node 16
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup node 24
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '16'
|
||||
node-version: 24
|
||||
|
||||
- run: npm ci
|
||||
|
||||
@@ -59,35 +53,64 @@ jobs:
|
||||
|
||||
runSdkManager:
|
||||
runs-on: ${{ matrix.os }}
|
||||
name: ${{ matrix.os }} - ${{ matrix.cmdline-tools-version }}
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
os: [ ubuntu-18.04, ubuntu-20.04, ubuntu-22.04, macos-11, macos-12, windows-2019, windows-2022 ]
|
||||
|
||||
os:
|
||||
- ubuntu-24.04
|
||||
- ubuntu-22.04
|
||||
- macos-26
|
||||
- macos-15
|
||||
- macos-14
|
||||
- windows-2025
|
||||
- windows-2022
|
||||
cmdline-tools-version:
|
||||
- 14742923
|
||||
- 12266719
|
||||
- 11479570
|
||||
- 11076708
|
||||
- 10406996
|
||||
- 9862592
|
||||
- 9477386
|
||||
- 9123335
|
||||
- 8512546
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup node 16
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup node 24
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '16'
|
||||
node-version: 24
|
||||
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
|
||||
- run: npm ci
|
||||
- run: npm run build
|
||||
|
||||
- run: node dist/index.js
|
||||
- name: Run setup-android
|
||||
uses: ./
|
||||
with:
|
||||
cmdline-tools-version: ${{ matrix.cmdline-tools-version }}
|
||||
log-accepted-android-sdk-licenses: 'false'
|
||||
|
||||
- run: sdkmanager --list_installed
|
||||
|
||||
- run: sdkmanager --list
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
|
||||
- name: Setup node 16
|
||||
uses: actions/setup-node@v3
|
||||
- name: Setup node 24
|
||||
uses: actions/setup-node@v6
|
||||
with:
|
||||
node-version: '16'
|
||||
node-version: 24
|
||||
|
||||
- run: npm ci
|
||||
|
||||
|
||||
6
.github/workflows/codeql-analysis.yml
vendored
6
.github/workflows/codeql-analysis.yml
vendored
@@ -31,13 +31,13 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v5
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
uses: github/codeql-action/init@v4
|
||||
with:
|
||||
languages: 'javascript'
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
uses: github/codeql-action/analyze@v4
|
||||
|
||||
21
.github/workflows/run.yml
vendored
21
.github/workflows/run.yml
vendored
@@ -1,17 +1,10 @@
|
||||
name: Run Android build
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
paths:
|
||||
- 'dist/**.js'
|
||||
- '.github/*.json'
|
||||
workflow_dispatch:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
- releases/*
|
||||
paths:
|
||||
- 'dist/**.js'
|
||||
- '.github/*.json'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
@@ -27,19 +20,19 @@ jobs:
|
||||
if: ${{ false }}
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
repository: daveol/SampleApplication
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v5
|
||||
with:
|
||||
path: ./build/
|
||||
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v3
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v5
|
||||
with:
|
||||
java-version: 1.8
|
||||
distribution: 'adopt'
|
||||
java-version: 17
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Setup Android SDK
|
||||
id: 'setup-android'
|
||||
|
||||
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
||||
73
README.md
73
README.md
@@ -3,10 +3,10 @@
|
||||

|
||||
|
||||
This action sets up the Android SDK tools by:
|
||||
- Downloading the SDK commandline tools, if the current version (7.0) is not found in either `$ANDROID_SDK_ROOT` or `$HOME/.android/sdk`.
|
||||
- Downloading the SDK commandline tools, if the current version (16.0) is not found in either `$ANDROID_SDK_ROOT` or `$HOME/.android/sdk`.
|
||||
- Accepting the SDK licenses.
|
||||
- Installing `tools` and `platform-tools`.
|
||||
- Adding `platform-tools` (contains adb) and `cmdline-tools/7.0/bin` (contains sdkmanager) to `$PATH`.
|
||||
- Adding `platform-tools` (contains adb) and `cmdline-tools/16.0/bin` (contains sdkmanager) to `$PATH`.
|
||||
- Setting up problem [matchers](/matchers.json).
|
||||
|
||||
On Windows 2016 runners, this action also checks if `$ANDROID_SDK_ROOT` path contains spaces.
|
||||
@@ -23,20 +23,79 @@ See [action.yml](action.yml)
|
||||
## Basic
|
||||
```yaml
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Set up JDK 1.8
|
||||
uses: actions/setup-java@v3
|
||||
- name: Set up JDK 17
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
java-version: 1.8
|
||||
java-version: '17'
|
||||
distribution: 'temurin'
|
||||
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v2
|
||||
uses: android-actions/setup-android@v3
|
||||
|
||||
- name: Build SampleApplication
|
||||
run: ./gradlew --no-daemon build
|
||||
```
|
||||
|
||||
## Additional packages
|
||||
Input parameter `packages` controls which packages this action will install from Android SDK.
|
||||
|
||||
Default value is `tools platform-tools`, supply an empty string to skip installing additional packages.
|
||||
|
||||
Additional packages can be installed at a later time by calling sdkmanager manually.
|
||||
|
||||
```yaml
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
packages: ''
|
||||
|
||||
# ...
|
||||
|
||||
- run: sdkmanager tools platform-tools
|
||||
```
|
||||
|
||||
## SDK Version selection
|
||||
|
||||
Command line tools are versioned using two variables - short and long.
|
||||
Long one is the build number, used in the zip URL, short one is the human friendly version name.
|
||||
|
||||
By default, setup-android installs version 14742923 (short version 20.0).
|
||||
|
||||
To install a different version, call setup-android with desired long version as the input parameter `cmdline-tools-version`:
|
||||
```yaml
|
||||
- name: Setup Android SDK
|
||||
uses: android-actions/setup-android@v3
|
||||
with:
|
||||
cmdline-tools-version: 8512546
|
||||
```
|
||||
|
||||
#### Version table
|
||||
| Short version | Long version |
|
||||
|---------------| --- |
|
||||
| 20.0 | 14742923 |
|
||||
| 16.0 | 12266719 |
|
||||
| 13.0 | 11479570 |
|
||||
| 12.0 | 11076708 |
|
||||
| 11.0 | 10406996 |
|
||||
| 10.0 | 9862592 |
|
||||
| 9.0 | 9477386 |
|
||||
| 8.0 | 9123335 |
|
||||
| 7.0 | 8512546 |
|
||||
|
||||
Current cmdline tools version can be found at https://developer.android.com/studio#command-line-tools-only
|
||||
|
||||
|
||||
# Android SDK Licenses
|
||||
|
||||
Android SDK is not public domain software, it comes with a license.
|
||||
|
||||
Input parameter `accept-android-sdk-licenses` decides if Android SDK licenses should be agreed to on behalf of the user of this action.
|
||||
Default option is 'yes', because otherwise SDK is unusable until said licenses are agreed to.
|
||||
|
||||
licenses are quite long, to prevent a wall of text in the action output, licenses can be agreed to silently.
|
||||
Input parameter `log-accepted-android-sdk-licenses` controls whether license texts should be printed or omitted from the text output. Defaults to 'true'.
|
||||
|
||||
# Thanks
|
||||
Based on the project [android-problem-matchers-action](https://github.com/jonasb/android-problem-matchers-action) from [@jonasb](https://github.com/jonasb)
|
||||
|
||||
23
action.yml
23
action.yml
@@ -2,8 +2,29 @@ name: 'Setup Android SDK Tools'
|
||||
author: 'Android-Actions'
|
||||
description: 'Setup the Android SDK Tools and add them to the path'
|
||||
|
||||
inputs:
|
||||
cmdline-tools-version:
|
||||
description: 'cmdline-tools-version. See https://developer.android.com/studio#command-line-tools-only'
|
||||
required: false
|
||||
default: '14742923'
|
||||
|
||||
accept-android-sdk-licenses:
|
||||
description: 'Android SDK is usable only after the license agreement. Should setup-android agree to the licences, provided by "sdkmanager --licenses"'
|
||||
required: false
|
||||
default: 'true'
|
||||
|
||||
log-accepted-android-sdk-licenses:
|
||||
description: 'Should accepted licenses be logged. If not, accepted licences will be accepted silently'
|
||||
required: false
|
||||
default: 'true'
|
||||
|
||||
packages:
|
||||
description: 'Additional packages to install'
|
||||
required: false
|
||||
default: 'tools platform-tools'
|
||||
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: node24
|
||||
main: 'dist/index.js'
|
||||
|
||||
branding:
|
||||
|
||||
30548
dist/index.js
vendored
30548
dist/index.js
vendored
File diff suppressed because one or more lines are too long
70
eslint.config.js
Normal file
70
eslint.config.js
Normal file
@@ -0,0 +1,70 @@
|
||||
const jestPlugin = require('eslint-plugin-jest');
|
||||
const tsParser = require('@typescript-eslint/parser');
|
||||
const tsPlugin = require('@typescript-eslint/eslint-plugin');
|
||||
const checkFile = require('eslint-plugin-check-file');
|
||||
const globals = require('globals');
|
||||
|
||||
module.exports = [
|
||||
{
|
||||
ignores: ['dist/', 'lib/', 'node_modules/']
|
||||
},
|
||||
{
|
||||
files: ['**/*.ts', '**/*.tsx'],
|
||||
plugins: {
|
||||
jest: jestPlugin,
|
||||
'@typescript-eslint': tsPlugin,
|
||||
'check-file': checkFile,
|
||||
},
|
||||
languageOptions: {
|
||||
parser: tsParser,
|
||||
parserOptions: {
|
||||
ecmaVersion: 'latest',
|
||||
sourceType: 'module',
|
||||
project: './tsconfig.json',
|
||||
},
|
||||
globals: {
|
||||
...globals.node,
|
||||
...globals.es6,
|
||||
...globals.jest,
|
||||
},
|
||||
},
|
||||
rules: {
|
||||
'check-file/filename-naming-convention': ['error', {
|
||||
'**/*.ts': 'KEBAB_CASE',
|
||||
}],
|
||||
'no-unused-vars': 'off',
|
||||
'@typescript-eslint/no-unused-vars': 'error',
|
||||
'@typescript-eslint/explicit-member-accessibility': ['error', {accessibility: 'no-public'}],
|
||||
'@typescript-eslint/no-require-imports': 'error',
|
||||
'@typescript-eslint/array-type': 'error',
|
||||
'@typescript-eslint/await-thenable': 'error',
|
||||
'@typescript-eslint/ban-ts-comment': 'error',
|
||||
camelcase: 'off',
|
||||
'@typescript-eslint/consistent-type-assertions': 'error',
|
||||
'@typescript-eslint/explicit-function-return-type': ['error', {allowExpressions: true}],
|
||||
'func-call-spacing': ['error', 'never'],
|
||||
'@typescript-eslint/no-array-constructor': 'error',
|
||||
'@typescript-eslint/no-empty-interface': 'error',
|
||||
'@typescript-eslint/no-explicit-any': 'error',
|
||||
'@typescript-eslint/no-extraneous-class': 'error',
|
||||
'@typescript-eslint/no-for-in-array': 'error',
|
||||
'@typescript-eslint/no-inferrable-types': 'error',
|
||||
'@typescript-eslint/no-misused-new': 'error',
|
||||
'@typescript-eslint/no-namespace': 'error',
|
||||
'@typescript-eslint/no-non-null-assertion': 'warn',
|
||||
'@typescript-eslint/no-unnecessary-qualifier': 'error',
|
||||
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
|
||||
'@typescript-eslint/no-useless-constructor': 'error',
|
||||
'@typescript-eslint/no-var-requires': 'error',
|
||||
'@typescript-eslint/prefer-for-of': 'warn',
|
||||
'@typescript-eslint/prefer-function-type': 'warn',
|
||||
'@typescript-eslint/prefer-includes': 'error',
|
||||
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
|
||||
'@typescript-eslint/promise-function-async': 'error',
|
||||
'@typescript-eslint/require-array-sort-compare': 'error',
|
||||
'@typescript-eslint/restrict-plus-operands': 'error',
|
||||
semi: ['error', 'never'],
|
||||
'@typescript-eslint/unbound-method': 'error',
|
||||
},
|
||||
},
|
||||
];
|
||||
11416
package-lock.json
generated
11416
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
36
package.json
36
package.json
@@ -5,7 +5,7 @@
|
||||
"description": "setup android action",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
"build": "ncc build src/main.ts --out dist/",
|
||||
"build": "tsc && esbuild lib/main.js --bundle --platform=node --target=node24 --format=cjs --outfile=dist/index.js",
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/*.ts",
|
||||
@@ -25,26 +25,24 @@
|
||||
"author": "daveol",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@actions/cache": "^3.0.0",
|
||||
"@actions/core": "^1.3.0",
|
||||
"@actions/tool-cache": "^2.0.1",
|
||||
"fs-extra": "^10.0.0"
|
||||
"@actions/core": "^3.0.0",
|
||||
"@actions/tool-cache": "^4.0.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/fs-extra": "^9.0.11",
|
||||
"@types/jest": "^28.1.6",
|
||||
"@types/node": "^16.11.47",
|
||||
"@typescript-eslint/eslint-plugin": "^5.20.0",
|
||||
"@typescript-eslint/parser": "^5.20.0",
|
||||
"@vercel/ncc": "^0.34.0",
|
||||
"eslint": "^8.13.0",
|
||||
"eslint-plugin-github": "^4.3.6",
|
||||
"eslint-plugin-jest": "^26.1.4",
|
||||
"jest": "^28.1.3",
|
||||
"jest-circus": "^28.1.3",
|
||||
"@types/jest": "^30.0.0",
|
||||
"@types/node": "^24.0.0",
|
||||
"@typescript-eslint/eslint-plugin": "^8.57.2",
|
||||
"@typescript-eslint/parser": "^8.57.2",
|
||||
"esbuild": "^0.27.4",
|
||||
"eslint": "^10.1.0",
|
||||
"eslint-plugin-check-file": "^3.3.1",
|
||||
"eslint-plugin-jest": "^29.15.1",
|
||||
"globals": "^17.4.0",
|
||||
"jest": "^30.3.0",
|
||||
"jest-circus": "^30.3.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.3.0",
|
||||
"ts-jest": "^28.0.7",
|
||||
"typescript": "^4.2.4"
|
||||
"prettier": "^3.3.2",
|
||||
"ts-jest": "^29.1.5",
|
||||
"typescript": "^5.9.3"
|
||||
}
|
||||
}
|
||||
|
||||
251
src/main.ts
251
src/main.ts
@@ -3,109 +3,104 @@ import * as tc from '@actions/tool-cache'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
import * as fse from 'fs-extra'
|
||||
import * as os from 'os'
|
||||
|
||||
const CMDLINE_TOOLS_VERSION = '7.0'
|
||||
const COMMANDLINE_TOOLS_VERSION = '8512546'
|
||||
function getVersionShort(versionLong: string): string {
|
||||
switch (versionLong) {
|
||||
case '14742923':
|
||||
return '20.0'
|
||||
case '12266719':
|
||||
return '16.0'
|
||||
case '11479570':
|
||||
return '13.0'
|
||||
case '11076708':
|
||||
return '12.0'
|
||||
case '10406996':
|
||||
return '11.0'
|
||||
case '9862592':
|
||||
return '10.0'
|
||||
case '9477386':
|
||||
return '9.0'
|
||||
case '9123335':
|
||||
return '8.0'
|
||||
case '8512546':
|
||||
return '7.0'
|
||||
default:
|
||||
return versionLong
|
||||
}
|
||||
}
|
||||
|
||||
const COMMANDLINE_TOOLS_WIN_URL = `https://dl.google.com/android/repository/commandlinetools-win-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/commandlinetools-mac-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/commandlinetools-linux-${COMMANDLINE_TOOLS_VERSION}_latest.zip`
|
||||
const VERSION_LONG = core.getInput('cmdline-tools-version', {
|
||||
trimWhitespace: true
|
||||
})
|
||||
if (VERSION_LONG.includes('/') || VERSION_LONG.includes('\\')) {
|
||||
core.setFailed('Malformed cmdline-tools-version!')
|
||||
throw new Error('Malformed cmdline-tools-version!')
|
||||
}
|
||||
const VERSION_SHORT = getVersionShort(VERSION_LONG)
|
||||
|
||||
const HOME = os.homedir()
|
||||
const ANDROID_HOME_DIR = path.join(HOME, '.android')
|
||||
const ANDROID_HOME_SDK_DIR = path.join(ANDROID_HOME_DIR, 'sdk')
|
||||
const COMMANDLINE_TOOLS_WIN_URL = `https://dl.google.com/android/repository/commandlinetools-win-${VERSION_LONG}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_MAC_URL = `https://dl.google.com/android/repository/commandlinetools-mac-${VERSION_LONG}_latest.zip`
|
||||
const COMMANDLINE_TOOLS_LIN_URL = `https://dl.google.com/android/repository/commandlinetools-linux-${VERSION_LONG}_latest.zip`
|
||||
|
||||
const ANDROID_HOME_SDK_DIR = path.join(os.homedir(), '.android', 'sdk')
|
||||
let ANDROID_SDK_ROOT = process.env['ANDROID_SDK_ROOT'] || ANDROID_HOME_SDK_DIR
|
||||
|
||||
function getSdkManagerPath(cmdToolsVersion: string): string {
|
||||
return path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
cmdToolsVersion,
|
||||
'bin',
|
||||
'sdkmanager'
|
||||
)
|
||||
}
|
||||
|
||||
function findPreinstalledSdkManager(): {
|
||||
isFound: boolean
|
||||
isCorrectVersion: boolean
|
||||
exePath: string
|
||||
} {
|
||||
const result = {isFound: false, isCorrectVersion: false, exePath: ''}
|
||||
|
||||
// First try to find the version defined in CMDLINE_TOOLS_VERSION
|
||||
result.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
|
||||
result.isFound = fs.existsSync(result.exePath)
|
||||
if (result.isFound) {
|
||||
result.isCorrectVersion = true
|
||||
return result
|
||||
}
|
||||
|
||||
// cmdline-tools could have a 'latest' version, but if it was installed 2 years ago
|
||||
// it may not be 'latest' as of today
|
||||
result.exePath = getSdkManagerPath('latest')
|
||||
result.isFound = fs.existsSync(result.exePath)
|
||||
if (result.isFound) {
|
||||
const propertiesFile = path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
'latest',
|
||||
'source.properties'
|
||||
)
|
||||
if (fs.existsSync(propertiesFile)) {
|
||||
result.isCorrectVersion = fs
|
||||
.readFileSync(propertiesFile, 'utf8')
|
||||
.includes(`Pkg.Revision=${CMDLINE_TOOLS_VERSION}`)
|
||||
}
|
||||
return result
|
||||
}
|
||||
result.exePath = ''
|
||||
|
||||
// Find whatever version is available in ANDROID_SDK_ROOT
|
||||
const cmdlineToolsDir = path.join(ANDROID_SDK_ROOT, 'cmdline-tools')
|
||||
const foundVersions: string[] = fs.existsSync(cmdlineToolsDir)
|
||||
? fs.readdirSync(cmdlineToolsDir)
|
||||
: []
|
||||
const foundVersionsFiltered: string[] = foundVersions.filter(
|
||||
obj => '.' !== obj && '..' !== obj
|
||||
)
|
||||
|
||||
// Sort by desc, to get 2.0 first, before 1.0
|
||||
const foundVersionsSorted: string[] = foundVersionsFiltered.sort(
|
||||
(a: string, b: string) => (a > b ? -1 : 1)
|
||||
)
|
||||
|
||||
for (const version of foundVersionsSorted) {
|
||||
result.exePath = getSdkManagerPath(version)
|
||||
result.isFound = fs.existsSync(result.exePath)
|
||||
if (result.isFound) {
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
result.exePath = ''
|
||||
return result
|
||||
}
|
||||
|
||||
async function callSdkManager(sdkManager: string, arg: string): Promise<void> {
|
||||
async function callSdkManager(
|
||||
sdkManager: string,
|
||||
arg: string,
|
||||
printOutput: Boolean = true
|
||||
): Promise<void> {
|
||||
const acceptBuffer = Buffer.from(Array(10).fill('y').join('\n'), 'utf8')
|
||||
await exec.exec(sdkManager, [arg], {
|
||||
input: acceptBuffer
|
||||
input: acceptBuffer,
|
||||
silent: !printOutput
|
||||
})
|
||||
}
|
||||
|
||||
async function installSdkManager(): Promise<string> {
|
||||
fs.mkdirSync(ANDROID_SDK_ROOT, {recursive: true})
|
||||
|
||||
// touch $ANDROID_SDK_ROOT/repositories.cfg
|
||||
fs.closeSync(
|
||||
fs.openSync(path.join(ANDROID_SDK_ROOT, 'repositories.cfg'), 'w')
|
||||
const cmdlineTools = path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
VERSION_SHORT
|
||||
)
|
||||
let sdkManagerExe = path.join(cmdlineTools, 'bin', 'sdkmanager')
|
||||
|
||||
const sdkManager = findPreinstalledSdkManager()
|
||||
if (!sdkManager.isFound) {
|
||||
if (!fs.existsSync(sdkManagerExe)) {
|
||||
const latestCmdlineTools = path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
'latest'
|
||||
)
|
||||
const sourcePropertiesFile = path.join(
|
||||
latestCmdlineTools,
|
||||
'source.properties'
|
||||
)
|
||||
const latestSdkManagerExe = path.join(
|
||||
latestCmdlineTools,
|
||||
'bin',
|
||||
'sdkmanager'
|
||||
)
|
||||
if (
|
||||
fs.existsSync(latestCmdlineTools) &&
|
||||
fs.existsSync(sourcePropertiesFile) &&
|
||||
fs.existsSync(latestSdkManagerExe)
|
||||
) {
|
||||
const sourceProperties = fs.readFileSync(sourcePropertiesFile)
|
||||
core.info(
|
||||
`Found preinstalled sdkmanager in ${latestCmdlineTools} with following source.properties:`
|
||||
)
|
||||
core.info(sourceProperties.toString())
|
||||
if (sourceProperties.includes(`Pkg.Revision=${VERSION_SHORT}`)) {
|
||||
core.info(`Preinstalled sdkmanager has the correct version`)
|
||||
sdkManagerExe = latestSdkManagerExe
|
||||
} else {
|
||||
core.info(`Wrong version in preinstalled sdkmanager`)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!fs.existsSync(sdkManagerExe)) {
|
||||
let cmdlineToolsURL
|
||||
if (process.platform === 'linux') {
|
||||
cmdlineToolsURL = COMMANDLINE_TOOLS_LIN_URL
|
||||
@@ -117,43 +112,27 @@ async function installSdkManager(): Promise<string> {
|
||||
core.error(`Unsupported platform: ${process.platform}`)
|
||||
return ''
|
||||
}
|
||||
|
||||
core.info(`Downloading commandline tools from ${cmdlineToolsURL}`)
|
||||
const cmdlineToolsZip = await tc.downloadTool(cmdlineToolsURL)
|
||||
const cmdlineToolsExtractedLocation = await tc.extractZip(cmdlineToolsZip)
|
||||
|
||||
// Move cmdline-tools to where it would be if it was installed through sdkmanager
|
||||
// Will allow calling sdkmanager without --sdk_root='..' argument
|
||||
const desiredLocation = path.join(
|
||||
ANDROID_SDK_ROOT,
|
||||
'cmdline-tools',
|
||||
CMDLINE_TOOLS_VERSION
|
||||
)
|
||||
|
||||
// Create parent directory
|
||||
fs.mkdirSync(path.dirname(desiredLocation), {recursive: true})
|
||||
const extractTo = path.join(ANDROID_SDK_ROOT, 'cmdline-tools')
|
||||
await tc.extractZip(cmdlineToolsZip, extractTo)
|
||||
|
||||
// Make sure we don't have leftover target directory (happens sometimes...)
|
||||
if (fs.existsSync(desiredLocation)) fse.removeSync(desiredLocation)
|
||||
|
||||
// @TODO: use io.mv instead of fs-extra.moveSync once following issue is resolved:
|
||||
// https://github.com/actions/toolkit/issues/706
|
||||
fse.moveSync(
|
||||
path.join(cmdlineToolsExtractedLocation, 'cmdline-tools'),
|
||||
desiredLocation
|
||||
)
|
||||
fse.removeSync(cmdlineToolsExtractedLocation)
|
||||
|
||||
sdkManager.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
|
||||
sdkManager.isCorrectVersion = true
|
||||
if (fs.existsSync(cmdlineTools)) {
|
||||
core.info(`Removing leftovers from ${cmdlineTools}`)
|
||||
fs.rmSync(cmdlineTools, {recursive: true})
|
||||
}
|
||||
fs.renameSync(path.join(extractTo, 'cmdline-tools'), cmdlineTools)
|
||||
}
|
||||
|
||||
if (!sdkManager.isCorrectVersion) {
|
||||
await callSdkManager(
|
||||
sdkManager.exePath,
|
||||
`cmdline-tools;${CMDLINE_TOOLS_VERSION}`
|
||||
// touch $ANDROID_SDK_ROOT/repositories.cfg
|
||||
fs.closeSync(
|
||||
fs.openSync(path.join(ANDROID_SDK_ROOT, 'repositories.cfg'), 'w')
|
||||
)
|
||||
sdkManager.exePath = getSdkManagerPath(CMDLINE_TOOLS_VERSION)
|
||||
}
|
||||
return sdkManager.exePath
|
||||
core.debug(`sdkmanager available at: ${sdkManagerExe}`)
|
||||
return sdkManagerExe
|
||||
}
|
||||
|
||||
async function run(): Promise<void> {
|
||||
@@ -175,21 +154,39 @@ async function run(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const sdkManager = await installSdkManager()
|
||||
core.debug(`sdkmanager installed to: ${sdkManager}`)
|
||||
await callSdkManager(sdkManager, '--licenses')
|
||||
await callSdkManager(sdkManager, 'tools')
|
||||
await callSdkManager(sdkManager, 'platform-tools')
|
||||
const sdkManagerExe = await installSdkManager()
|
||||
|
||||
core.setOutput('ANDROID_COMMANDLINE_TOOLS_VERSION', COMMANDLINE_TOOLS_VERSION)
|
||||
if (core.getBooleanInput('accept-android-sdk-licenses')) {
|
||||
core.info('Accepting Android SDK licenses')
|
||||
await callSdkManager(
|
||||
sdkManagerExe,
|
||||
'--licenses',
|
||||
core.getBooleanInput('log-accepted-android-sdk-licenses')
|
||||
)
|
||||
}
|
||||
|
||||
const packages = core
|
||||
.getInput('packages', {required: false})
|
||||
.split(' ')
|
||||
.map(function (str) {
|
||||
return str.trim()
|
||||
})
|
||||
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
||||
.filter(function (element, index, array) {
|
||||
return element
|
||||
})
|
||||
for (const pkg of packages) {
|
||||
await callSdkManager(sdkManagerExe, pkg)
|
||||
}
|
||||
|
||||
core.setOutput('ANDROID_COMMANDLINE_TOOLS_VERSION', VERSION_LONG)
|
||||
core.exportVariable('ANDROID_HOME', ANDROID_SDK_ROOT)
|
||||
core.exportVariable('ANDROID_SDK_ROOT', ANDROID_SDK_ROOT)
|
||||
|
||||
core.addPath(path.dirname(sdkManager))
|
||||
core.addPath(path.dirname(sdkManagerExe))
|
||||
core.addPath(path.join(ANDROID_SDK_ROOT, 'platform-tools'))
|
||||
|
||||
core.debug('add matchers')
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(`##[add-matcher]${path.join(__dirname, '..', 'matchers.json')}`)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,24 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "es6", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */
|
||||
"module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */
|
||||
"outDir": "./lib", /* Redirect output structure to the directory. */
|
||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||
"strict": true, /* Enable all strict type-checking options. */
|
||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||
"moduleResolution": "node"
|
||||
"target": "ES2024",
|
||||
"module": "es2022",
|
||||
"moduleResolution": "bundler",
|
||||
"lib": [
|
||||
"ES2024"
|
||||
],
|
||||
"outDir": "./lib",
|
||||
"rootDir": "./src",
|
||||
"strict": true,
|
||||
"esModuleInterop": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"skipLibCheck": true,
|
||||
"declaration": true,
|
||||
"declarationMap": true,
|
||||
"sourceMap": true
|
||||
},
|
||||
"exclude": ["node_modules", "**/*.test.ts"]
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/*.test.ts",
|
||||
"lib"
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user