Skip to content

Commit

Permalink
Merge branch 'master' into release/v2
Browse files Browse the repository at this point in the history
* master:
  Prepare for release 2.4.0.
  Add support for setting a custom working-directory.
  Fix typo
  • Loading branch information
ychescale9 committed Feb 15, 2020
2 parents bdf1f83 + aaa1121 commit 2754675
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ jobs:
npm run lint
npm test
- name: Prepare test fixture
run: cp -a ./test-fixture/* ./

- name: Java 13
uses: actions/setup-java@v1
with:
Expand All @@ -45,6 +42,7 @@ jobs:
profile: Nexus 6
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
disable-animations: true
working-directory: ./test-fixture/
script: |
echo $GITHUB_REPOSITORY
./gradlew help
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## v2.4.0

* Added support for setting custom `working-directory` - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository.

## v2.3.2

* Fixed an issue where environment variables are escaped in script.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ jobs:
| `emulator-options` | Optional | See below | Command-line options used when launching the emulator (replacing all default options) - e.g. `-no-window -no-snapshot -camera-back emulated`. |
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
| `emulator-build` | Optional | N/A | Build number of a specific version of the emulator binary to use e.g. `6061023` for emulator v29.3.0.0. |
| `working-directory` | Optional | `./` | A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository. |
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |

Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`.
10 changes: 10 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ function run() {
console.log(`using emulator build: ${emulatorBuildInput}`);
}
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
// custom working directory
const workingDirectoryInput = core.getInput('working-directory');
if (workingDirectoryInput) {
console.log(`custom working directory: ${workingDirectoryInput}`);
}
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
// custom script to run
const scriptInput = core.getInput('script', { required: true });
const scripts = script_parser_1.parseScript(scriptInput);
Expand All @@ -83,6 +89,10 @@ function run() {
java_version_manager_1.setJavaHome(defaultJavaHome);
// execute the custom script
try {
// move to custom working directory if set
if (workingDirectory) {
process.chdir(workingDirectory);
}
for (const script of scripts) {
yield exec.exec(`sh -c \\"${script}"`);
}
Expand Down
8 changes: 4 additions & 4 deletions lib/sdk-installer.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const BUILD_TOOLS_VERSION = '29.0.3';
*/
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
return __awaiter(this, void 0, void 0, function* () {
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
const sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
console.log('Installing latest build tools, platform tools, and platform.');
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
if (emulatorBuild) {
console.log(`Installing emulator build ${emulatorBuild}.`);
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
Expand All @@ -35,10 +35,10 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
}
else {
console.log('Installing latest emulator.');
yield exec.exec(`sh -c \\"${sdkmangerPath} --install emulator > /dev/null"`);
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
}
console.log('Installing system images.');
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
});
}
exports.installAndroidSdk = installAndroidSdk;
11 changes: 11 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ async function run() {
}
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;

// custom working directory
const workingDirectoryInput = core.getInput('working-directory');
if (workingDirectoryInput) {
console.log(`custom working directory: ${workingDirectoryInput}`);
}
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;

// custom script to run
const scriptInput = core.getInput('script', { required: true });
const scripts = parseScript(scriptInput);
Expand Down Expand Up @@ -78,6 +85,10 @@ async function run() {

// execute the custom script
try {
// move to custom working directory if set
if (workingDirectory) {
process.chdir(workingDirectory);
}
for (const script of scripts) {
await exec.exec(`sh -c \\"${script}"`);
}
Expand Down
8 changes: 4 additions & 4 deletions src/sdk-installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const BUILD_TOOLS_VERSION = '29.0.3';
* and the system image for the chosen API level, CPU arch, and target.
*/
export async function installAndroidSdk(apiLevel: number, target: string, arch: string, emulatorBuild?: string): Promise<void> {
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
const sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
console.log('Installing latest build tools, platform tools, and platform.');
await exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
await exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
if (emulatorBuild) {
console.log(`Installing emulator build ${emulatorBuild}.`);
await exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
Expand All @@ -18,8 +18,8 @@ export async function installAndroidSdk(apiLevel: number, target: string, arch:
await exec.exec(`rm -f emulator.zip`);
} else {
console.log('Installing latest emulator.');
await exec.exec(`sh -c \\"${sdkmangerPath} --install emulator > /dev/null"`);
await exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
}
console.log('Installing system images.');
await exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
await exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
}

0 comments on commit 2754675

Please sign in to comment.