Skip to content

Commit ff311e8

Browse files
committed
Add support for setting a custom working-directory.
1 parent d0fa6c6 commit ff311e8

File tree

5 files changed

+27
-7
lines changed

5 files changed

+27
-7
lines changed

.github/workflows/workflow.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@ jobs:
2828
npm run lint
2929
npm test
3030
31-
- name: Prepare test fixture
32-
run: cp -a ./test-fixture/* ./
33-
3431
- name: Java 13
3532
uses: actions/setup-java@v1
3633
with:
@@ -45,6 +42,7 @@ jobs:
4542
profile: Nexus 6
4643
emulator-options: -no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim -camera-back none
4744
disable-animations: true
45+
working-directory: ./test-fixture/
4846
script: |
4947
echo $GITHUB_REPOSITORY
5048
./gradlew help

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
| `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`. |
7777
| `disable-animations` | Optional | `true` | Whether to disable animations - `true` or `false`. |
7878
| `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. |
79+
| `working-directory` | Optional | `./` | A custom working directory - e.g. `./android` if your root Gradle project is under the `./android` sub-directory within your repository. |
7980
| `script` | Required | N/A | Custom script to run - e.g. to run Android instrumented tests on the emulator: `./gradlew connectedCheck` |
8081

8182
Default `emulator-options`: `-no-window -gpu swiftshader_indirect -no-snapshot -noaudio -no-boot-anim`.

lib/main.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ function run() {
6060
console.log(`using emulator build: ${emulatorBuildInput}`);
6161
}
6262
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
63+
// custom working directory
64+
const workingDirectoryInput = core.getInput('working-directory');
65+
if (workingDirectoryInput) {
66+
console.log(`custom working directory: ${workingDirectoryInput}`);
67+
}
68+
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
6369
// custom script to run
6470
const scriptInput = core.getInput('script', { required: true });
6571
const scripts = script_parser_1.parseScript(scriptInput);
@@ -83,6 +89,10 @@ function run() {
8389
java_version_manager_1.setJavaHome(defaultJavaHome);
8490
// execute the custom script
8591
try {
92+
// move to custom working directory if set
93+
if (workingDirectory) {
94+
process.chdir(workingDirectory);
95+
}
8696
for (const script of scripts) {
8797
yield exec.exec(`sh -c \\"${script}"`);
8898
}

lib/sdk-installer.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ const BUILD_TOOLS_VERSION = '29.0.3';
2323
*/
2424
function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
2525
return __awaiter(this, void 0, void 0, function* () {
26-
const sdkmangerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
26+
const sdkmanagerPath = `${process.env.ANDROID_HOME}/tools/bin/sdkmanager`;
2727
console.log('Installing latest build tools, platform tools, and platform.');
28-
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
28+
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'build-tools;${BUILD_TOOLS_VERSION}' platform-tools 'platforms;android-${apiLevel}' > /dev/null"`);
2929
if (emulatorBuild) {
3030
console.log(`Installing emulator build ${emulatorBuild}.`);
3131
yield exec.exec(`curl -fo emulator.zip https://dl.google.com/android/repository/emulator-darwin-${emulatorBuild}.zip`);
@@ -35,10 +35,10 @@ function installAndroidSdk(apiLevel, target, arch, emulatorBuild) {
3535
}
3636
else {
3737
console.log('Installing latest emulator.');
38-
yield exec.exec(`sh -c \\"${sdkmangerPath} --install emulator > /dev/null"`);
38+
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install emulator > /dev/null"`);
3939
}
4040
console.log('Installing system images.');
41-
yield exec.exec(`sh -c \\"${sdkmangerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
41+
yield exec.exec(`sh -c \\"${sdkmanagerPath} --install 'system-images;android-${apiLevel};${target};${arch}' > /dev/null"`);
4242
});
4343
}
4444
exports.installAndroidSdk = installAndroidSdk;

src/main.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ async function run() {
5151
}
5252
const emulatorBuild = !emulatorBuildInput ? undefined : emulatorBuildInput;
5353

54+
// custom working directory
55+
const workingDirectoryInput = core.getInput('working-directory');
56+
if (workingDirectoryInput) {
57+
console.log(`custom working directory: ${workingDirectoryInput}`);
58+
}
59+
const workingDirectory = !workingDirectoryInput ? undefined : workingDirectoryInput;
60+
5461
// custom script to run
5562
const scriptInput = core.getInput('script', { required: true });
5663
const scripts = parseScript(scriptInput);
@@ -78,6 +85,10 @@ async function run() {
7885

7986
// execute the custom script
8087
try {
88+
// move to custom working directory if set
89+
if (workingDirectory) {
90+
process.chdir(workingDirectory);
91+
}
8192
for (const script of scripts) {
8293
await exec.exec(`sh -c \\"${script}"`);
8394
}

0 commit comments

Comments
 (0)