-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add patch for watchers limit and enospc error
- Loading branch information
Showing
8 changed files
with
212 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
"use strict"; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const core = __importStar(require("@actions/core")); | ||
const cli = __importStar(require("@actions/exec")); | ||
/** | ||
* Try to patch the default watcher/inotify limit. | ||
* This is a limitation from GitHub Actions and might be an issue in some Expo projects. | ||
* It sets the system's `fs.inotify` limits to a more sensible setting. | ||
* | ||
* @see https://github.com/expo/expo-github-action/issues/20 | ||
*/ | ||
function patchWatchers() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (process.platform !== 'linux') { | ||
return core.debug('Skipping patch for watchers, not running on Linux...'); | ||
} | ||
core.debug('Patching system watchers for the `ENOSPC` error...'); | ||
try { | ||
// see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177 | ||
yield cli.exec('sudo sysctl fs.inotify.max_user_instances=524288'); | ||
yield cli.exec('sudo sysctl fs.inotify.max_user_watches=524288'); | ||
yield cli.exec('sudo sysctl fs.inotify.max_queued_events=524288'); | ||
yield cli.exec('sudo sysctl -p'); | ||
} | ||
catch (_a) { | ||
core.warning('Looks like we can\'t patch watchers/inotify limits, you might encouter the `ENOSPC` error.'); | ||
core.warning('For more info, https://github.com/expo/expo-github-action/issues/20'); | ||
} | ||
}); | ||
} | ||
exports.patchWatchers = patchWatchers; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as core from '@actions/core'; | ||
import * as cli from '@actions/exec'; | ||
|
||
/** | ||
* Try to patch the default watcher/inotify limit. | ||
* This is a limitation from GitHub Actions and might be an issue in some Expo projects. | ||
* It sets the system's `fs.inotify` limits to a more sensible setting. | ||
* | ||
* @see https://github.com/expo/expo-github-action/issues/20 | ||
*/ | ||
export async function patchWatchers() { | ||
if (process.platform !== 'linux') { | ||
return core.debug('Skipping patch for watchers, not running on Linux...'); | ||
} | ||
|
||
core.debug('Patching system watchers for the `ENOSPC` error...'); | ||
|
||
try { | ||
// see https://github.com/expo/expo-cli/issues/277#issuecomment-452685177 | ||
await cli.exec('sudo sysctl fs.inotify.max_user_instances=524288'); | ||
await cli.exec('sudo sysctl fs.inotify.max_user_watches=524288'); | ||
await cli.exec('sudo sysctl fs.inotify.max_queued_events=524288'); | ||
await cli.exec('sudo sysctl -p'); | ||
} catch { | ||
core.warning('Looks like we can\'t patch watchers/inotify limits, you might encouter the `ENOSPC` error.'); | ||
core.warning('For more info, https://github.com/expo/expo-github-action/issues/20'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const core = { debug: jest.fn(), warning: jest.fn() }; | ||
const cli = { exec: jest.fn() }; | ||
|
||
jest.mock('@actions/core', () => core); | ||
jest.mock('@actions/exec', () => cli); | ||
|
||
import * as system from '../src/system'; | ||
|
||
describe('patchWatchers', () => { | ||
const originalPlatform = process.platform; | ||
const changePlatform = (platform: NodeJS.Platform) => { | ||
Object.defineProperty(process, 'platform', { value: platform }); | ||
}; | ||
|
||
afterEach(() => { | ||
changePlatform(originalPlatform); | ||
}); | ||
|
||
it('increses fs inotify settings with sysctl', async () => { | ||
changePlatform('linux'); | ||
await system.patchWatchers(); | ||
expect(cli.exec).toHaveBeenCalledWith('sudo sysctl fs.inotify.max_user_instances=524288'); | ||
expect(cli.exec).toHaveBeenCalledWith('sudo sysctl fs.inotify.max_user_watches=524288'); | ||
expect(cli.exec).toHaveBeenCalledWith('sudo sysctl fs.inotify.max_queued_events=524288'); | ||
expect(cli.exec).toHaveBeenCalledWith('sudo sysctl -p'); | ||
}); | ||
|
||
it('warns for unsuccessful patches', async () => { | ||
const error = new Error('Something went wrong'); | ||
cli.exec.mockRejectedValue(error); | ||
changePlatform('linux'); | ||
await system.patchWatchers(); | ||
expect(core.warning).toBeCalledWith(expect.stringContaining('can\'t patch watchers')); | ||
expect(core.warning).toBeCalledWith( | ||
expect.stringContaining('https://github.com/expo/expo-github-action/issues/20') | ||
); | ||
}); | ||
|
||
it('skips on windows platform', async () => { | ||
changePlatform('win32'); | ||
await system.patchWatchers(); | ||
expect(cli.exec).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('skips on macos platform', async () => { | ||
changePlatform('darwin'); | ||
await system.patchWatchers(); | ||
expect(cli.exec).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('runs on linux platform', async () => { | ||
changePlatform('linux'); | ||
await system.patchWatchers(); | ||
expect(cli.exec).toHaveBeenCalled(); | ||
}); | ||
}); |