-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.yml
More file actions
229 lines (206 loc) · 7.73 KB
/
action.yml
File metadata and controls
229 lines (206 loc) · 7.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: 'Setup Android CLI'
description: 'Install and cache Google''s agent-first android CLI plus SDK packages. Drop-in setup-android replacement.'
author: 'Premex'
branding:
icon: 'smartphone'
color: 'green'
inputs:
packages:
description: >-
SDK packages to install via `android sdk install`. Space- or
newline-separated, slash syntax (e.g. `platforms/android-34
build-tools/34.0.0 platform-tools`). Leave empty to install only the
CLI with no SDK packages.
required: false
default: ''
sdk-path:
description: >-
Override where the Android SDK is installed. Defaults to
`~/Library/Android/sdk` on macOS and `~/Android/Sdk` on Linux. The
chosen path is exported as `ANDROID_HOME` and `ANDROID_SDK_ROOT` for
subsequent steps.
required: false
default: ''
cache:
description: >-
Cache the CLI's unpacked resources (`~/.android/bin`) and the SDK
between runs. Set to `false` to disable. Does not affect Gradle
caching - use `gradle/actions/setup-gradle@v4` for that.
required: false
default: 'true'
cache-key:
description: >-
Extra input appended to the cache key. Change to bust the cache. The
default key already includes OS, arch, and the hash of
`**/libs.versions.toml` / `**/build.gradle*`.
required: false
default: ''
no-metrics:
description: >-
Pass `--no-metrics` on `android` invocations made by this action
(opts out of Google's usage telemetry). Defaults to `true`.
required: false
default: 'true'
install-url-base:
description: >-
Override the base URL for downloading the CLI binary. The action
appends `/<platform>/android` (for example `/linux_x86_64/android`).
Useful for internal mirrors or air-gapped environments. Defaults to
Google's redirector.
required: false
default: 'https://redirector.gvt1.com/edgedl/android/cli/latest'
outputs:
sdk-path:
description: Absolute path to the Android SDK managed by this action.
value: ${{ steps.summary.outputs.sdk-path }}
cli-version:
description: Version string returned by `android --version`.
value: ${{ steps.summary.outputs.cli-version }}
cache-hit:
description: >-
Whether the `~/.android/bin` + SDK cache was hit. Empty when caching
is disabled.
value: ${{ steps.cache.outputs.cache-hit }}
runs:
using: composite
steps:
- name: Resolve platform and paths
id: platform
shell: bash
env:
INPUT_SDK_PATH: ${{ inputs.sdk-path }}
run: |
set -euo pipefail
os=$(uname -s)
arch=$(uname -m)
case "$os/$arch" in
Linux/x86_64) slug=linux_x86_64 ;;
Darwin/arm64) slug=darwin_arm64 ;;
Darwin/x86_64)
echo "::warning::Intel Mac runner detected. Google only ships darwin_arm64; using that binary under Rosetta. Prefer an Apple Silicon runner for faster builds."
slug=darwin_arm64
;;
*)
echo "::error::Unsupported platform: $os/$arch. Supported: Linux x86_64, macOS arm64 (darwin_arm64)."
exit 1
;;
esac
if [[ -n "${INPUT_SDK_PATH}" ]]; then
sdk_path="${INPUT_SDK_PATH}"
elif [[ "$os" == "Darwin" ]]; then
sdk_path="$HOME/Library/Android/sdk"
else
sdk_path="$HOME/Android/Sdk"
fi
tool_dir="$RUNNER_TOOL_CACHE/android-cli/latest/$slug"
mkdir -p "$tool_dir" "$sdk_path"
{
echo "slug=$slug"
echo "sdk-path=$sdk_path"
echo "tool-dir=$tool_dir"
} >> "$GITHUB_OUTPUT"
- name: Cache Android CLI and SDK
if: inputs.cache == 'true'
id: cache
uses: actions/cache@v5
with:
path: |
~/.android/bin
${{ steps.platform.outputs.sdk-path }}
key: setup-android-cli-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.platform.outputs.slug }}-${{ hashFiles('**/libs.versions.toml', '**/build.gradle*', '**/settings.gradle*') }}${{ inputs.cache-key && format('-{0}', inputs.cache-key) || '' }}
restore-keys: |
setup-android-cli-v1-${{ runner.os }}-${{ runner.arch }}-${{ steps.platform.outputs.slug }}-
- name: Install CLI launcher
shell: bash
env:
SLUG: ${{ steps.platform.outputs.slug }}
TOOL_DIR: ${{ steps.platform.outputs.tool-dir }}
INSTALL_URL_BASE: ${{ inputs.install-url-base }}
run: |
set -euo pipefail
if [[ -x "$TOOL_DIR/android" ]]; then
echo "android CLI launcher already present in $TOOL_DIR (from runner tool cache)."
else
echo "::group::Downloading android CLI ($SLUG)"
url="${INSTALL_URL_BASE%/}/${SLUG}/android"
echo "Source: $url"
curl -fsSL --retry 3 --retry-delay 2 "$url" -o "$TOOL_DIR/android"
chmod +x "$TOOL_DIR/android"
echo "::endgroup::"
fi
echo "$TOOL_DIR" >> "$GITHUB_PATH"
export PATH="$TOOL_DIR:$PATH"
# First run unpacks the embedded resources into ~/.android/bin. If
# that directory was cache-restored, this is effectively a no-op.
echo "::group::Bootstrapping CLI (one-time unpack if needed)"
ANDROID_CLI_FRESH_INSTALL=1 android --version
echo "::endgroup::"
- name: Configure ANDROID_HOME and ANDROID_SDK_ROOT
shell: bash
env:
SDK_PATH: ${{ steps.platform.outputs.sdk-path }}
run: |
set -euo pipefail
echo "ANDROID_HOME=$SDK_PATH" >> "$GITHUB_ENV"
echo "ANDROID_SDK_ROOT=$SDK_PATH" >> "$GITHUB_ENV"
# Also export common adjacent PATH entries so later steps can call
# adb / emulator without setting PATH themselves. These are only
# populated once their packages are installed.
{
echo "$SDK_PATH/platform-tools"
echo "$SDK_PATH/emulator"
echo "$SDK_PATH/cmdline-tools/latest/bin"
} >> "$GITHUB_PATH"
- name: Install SDK packages
if: inputs.packages != ''
shell: bash
env:
PACKAGES: ${{ inputs.packages }}
SDK_PATH: ${{ steps.platform.outputs.sdk-path }}
NO_METRICS: ${{ inputs.no-metrics }}
run: |
set -euo pipefail
metrics_flag=""
if [[ "$NO_METRICS" == "true" ]]; then
metrics_flag="--no-metrics"
fi
echo "::group::Installing SDK packages"
# shellcheck disable=SC2086
android $metrics_flag --sdk="$SDK_PATH" sdk install $PACKAGES
echo "::endgroup::"
- name: Register Android/Gradle problem matchers
shell: bash
run: |
set -euo pipefail
echo "::add-matcher::${GITHUB_ACTION_PATH}/matchers.json"
- name: Summary
id: summary
shell: bash
env:
SDK_PATH: ${{ steps.platform.outputs.sdk-path }}
SLUG: ${{ steps.platform.outputs.slug }}
PACKAGES: ${{ inputs.packages }}
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
run: |
set -euo pipefail
cli_version=$(android --version 2>/dev/null || echo "unknown")
{
echo "sdk-path=$SDK_PATH"
echo "cli-version=$cli_version"
} >> "$GITHUB_OUTPUT"
{
echo "### 🤖 Setup Android CLI"
echo ""
echo "| | |"
echo "|---|---|"
echo "| CLI version | \`$cli_version\` |"
echo "| Platform | \`$SLUG\` |"
echo "| SDK path | \`$SDK_PATH\` |"
if [[ -n "$PACKAGES" ]]; then
pkgs_md=$(echo "$PACKAGES" | tr '\n' ' ' | sed 's/ */ /g' | sed 's/ $//')
echo "| Packages | \`$pkgs_md\` |"
fi
if [[ -n "$CACHE_HIT" ]]; then
echo "| Cache hit | \`$CACHE_HIT\` |"
fi
} >> "$GITHUB_STEP_SUMMARY"