Skip to content

Commit c5d2c0f

Browse files
authored
fix: use which instead of npx to authenticate (#147)
* fix: use which instead of npx to authenticate * chore: test both with and without cache * chore: update test for authentication
1 parent 439ff4c commit c5d2c0f

4 files changed

Lines changed: 17 additions & 6 deletions

File tree

.github/workflows/test.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ jobs:
1717
- macos-latest
1818
- ubuntu-latest
1919
- windows-latest
20+
cache:
21+
- true
22+
- false
2023
runs-on: ${{ matrix.os }}
2124
steps:
2225
- name: 🏗 Setup repo
@@ -26,9 +29,9 @@ jobs:
2629
uses: ./
2730
with:
2831
eas-version: latest
29-
eas-cache: true
32+
eas-cache: ${{ matrix.cache }}
3033
expo-version: latest
31-
expo-cache: true
34+
expo-cache: ${{ matrix.cache }}
3235
token: ${{ secrets.EXPO_TOKEN }}
3336

3437
- name: 🧪 EAS installed

build/setup/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64755,6 +64755,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
6475564755
exports.executeAction = exports.expoAuthenticate = exports.patchWatchers = exports.installToolFromPackage = exports.toolPath = exports.tempPath = exports.cacheTool = exports.findTool = void 0;
6475664756
const core_1 = __nccwpck_require__(2186);
6475764757
const exec_1 = __nccwpck_require__(1514);
64758+
const io_1 = __nccwpck_require__(7436);
6475864759
const os_1 = __importDefault(__nccwpck_require__(2037));
6475964760
const path_1 = __importDefault(__nccwpck_require__(1017));
6476064761
var tool_cache_1 = __nccwpck_require__(7784);
@@ -64825,7 +64826,7 @@ async function expoAuthenticate(token, cli) {
6482564826
(0, core_1.info)(`Skipped token validation: no CLI installed, can't run 'whoami'.`);
6482664827
}
6482764828
else {
64828-
await (0, exec_1.exec)('npx --no-install', [cli, 'whoami'], {
64829+
await (0, exec_1.exec)(await (0, io_1.which)(cli), ['whoami'], {
6482964830
env: { ...process.env, EXPO_TOKEN: token },
6483064831
});
6483164832
}

src/worker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { addPath, exportVariable, info, setFailed, warning } from '@actions/core';
22
import { exec } from '@actions/exec';
3+
import { which } from '@actions/io';
34
import os from 'os';
45
import path from 'path';
56

@@ -71,7 +72,7 @@ export async function expoAuthenticate(token: string, cli?: 'expo' | 'eas'): Pro
7172
if (!cli) {
7273
info(`Skipped token validation: no CLI installed, can't run 'whoami'.`);
7374
} else {
74-
await exec('npx --no-install', [cli, 'whoami'], {
75+
await exec(await which(cli), ['whoami'], {
7576
env: { ...process.env, EXPO_TOKEN: token },
7677
});
7778
}

tests/worker.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import * as core from '@actions/core';
22
import * as exec from '@actions/exec';
3+
import * as io from '@actions/io';
34
import os from 'os';
45
import path from 'path';
56

@@ -15,6 +16,7 @@ import { resetEnv, setEnv, setPlatform, resetPlatform } from './utils';
1516

1617
jest.mock('@actions/core');
1718
jest.mock('@actions/exec');
19+
jest.mock('@actions/io');
1820

1921
describe(tempPath, () => {
2022
afterEach(resetEnv);
@@ -93,15 +95,19 @@ describe(expoAuthenticate, () => {
9395
});
9496

9597
it('validates EXPO_TOKEN with expo-cli', async () => {
98+
jest.mocked(io.which).mockResolvedValue('expo');
9699
await expoAuthenticate('faketoken', 'expo');
97-
expect(exec.exec).toBeCalledWith('npx --no-install', ['expo', 'whoami'], {
100+
expect(io.which).toBeCalledWith('expo');
101+
expect(exec.exec).toBeCalledWith('expo', ['whoami'], {
98102
env: expect.objectContaining({ EXPO_TOKEN: 'faketoken' }),
99103
});
100104
});
101105

102106
it('validates EXPO_TOKEN with eas-cli', async () => {
107+
jest.mocked(io.which).mockResolvedValue('eas');
103108
await expoAuthenticate('faketoken', 'eas');
104-
expect(exec.exec).toBeCalledWith('npx --no-install', ['eas', 'whoami'], {
109+
expect(io.which).toBeCalledWith('eas');
110+
expect(exec.exec).toBeCalledWith('eas', ['whoami'], {
105111
env: expect.objectContaining({ EXPO_TOKEN: 'faketoken' }),
106112
});
107113
});

0 commit comments

Comments
 (0)