Skip to content

Commit

Permalink
fix: use which instead of npx to authenticate (#147)
Browse files Browse the repository at this point in the history
* fix: use which instead of npx to authenticate

* chore: test both with and without cache

* chore: update test for authentication
  • Loading branch information
byCedric authored Jan 13, 2022
1 parent 439ff4c commit c5d2c0f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
- macos-latest
- ubuntu-latest
- windows-latest
cache:
- true
- false
runs-on: ${{ matrix.os }}
steps:
- name: 🏗 Setup repo
Expand All @@ -26,9 +29,9 @@ jobs:
uses: ./
with:
eas-version: latest
eas-cache: true
eas-cache: ${{ matrix.cache }}
expo-version: latest
expo-cache: true
expo-cache: ${{ matrix.cache }}
token: ${{ secrets.EXPO_TOKEN }}

- name: 🧪 EAS installed
Expand Down
3 changes: 2 additions & 1 deletion build/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64755,6 +64755,7 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.executeAction = exports.expoAuthenticate = exports.patchWatchers = exports.installToolFromPackage = exports.toolPath = exports.tempPath = exports.cacheTool = exports.findTool = void 0;
const core_1 = __nccwpck_require__(2186);
const exec_1 = __nccwpck_require__(1514);
const io_1 = __nccwpck_require__(7436);
const os_1 = __importDefault(__nccwpck_require__(2037));
const path_1 = __importDefault(__nccwpck_require__(1017));
var tool_cache_1 = __nccwpck_require__(7784);
Expand Down Expand Up @@ -64825,7 +64826,7 @@ async function expoAuthenticate(token, cli) {
(0, core_1.info)(`Skipped token validation: no CLI installed, can't run 'whoami'.`);
}
else {
await (0, exec_1.exec)('npx --no-install', [cli, 'whoami'], {
await (0, exec_1.exec)(await (0, io_1.which)(cli), ['whoami'], {
env: { ...process.env, EXPO_TOKEN: token },
});
}
Expand Down
3 changes: 2 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { addPath, exportVariable, info, setFailed, warning } from '@actions/core';
import { exec } from '@actions/exec';
import { which } from '@actions/io';
import os from 'os';
import path from 'path';

Expand Down Expand Up @@ -71,7 +72,7 @@ export async function expoAuthenticate(token: string, cli?: 'expo' | 'eas'): Pro
if (!cli) {
info(`Skipped token validation: no CLI installed, can't run 'whoami'.`);
} else {
await exec('npx --no-install', [cli, 'whoami'], {
await exec(await which(cli), ['whoami'], {
env: { ...process.env, EXPO_TOKEN: token },
});
}
Expand Down
10 changes: 8 additions & 2 deletions tests/worker.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
import * as io from '@actions/io';
import os from 'os';
import path from 'path';

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

jest.mock('@actions/core');
jest.mock('@actions/exec');
jest.mock('@actions/io');

describe(tempPath, () => {
afterEach(resetEnv);
Expand Down Expand Up @@ -93,15 +95,19 @@ describe(expoAuthenticate, () => {
});

it('validates EXPO_TOKEN with expo-cli', async () => {
jest.mocked(io.which).mockResolvedValue('expo');
await expoAuthenticate('faketoken', 'expo');
expect(exec.exec).toBeCalledWith('npx --no-install', ['expo', 'whoami'], {
expect(io.which).toBeCalledWith('expo');
expect(exec.exec).toBeCalledWith('expo', ['whoami'], {
env: expect.objectContaining({ EXPO_TOKEN: 'faketoken' }),
});
});

it('validates EXPO_TOKEN with eas-cli', async () => {
jest.mocked(io.which).mockResolvedValue('eas');
await expoAuthenticate('faketoken', 'eas');
expect(exec.exec).toBeCalledWith('npx --no-install', ['eas', 'whoami'], {
expect(io.which).toBeCalledWith('eas');
expect(exec.exec).toBeCalledWith('eas', ['whoami'], {
env: expect.objectContaining({ EXPO_TOKEN: 'faketoken' }),
});
});
Expand Down

0 comments on commit c5d2c0f

Please sign in to comment.