Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: clean up dependencies and eslint rules #145

Merged
merged 6 commits into from
Jan 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 2 additions & 14 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
module.exports = {
ignorePatterns: ['/build/**', 'node_modules/**'],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'jest', 'prettier'],
env: {
es6: true,
'jest/globals': true,
node: true,
},
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
rules: {
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'@typescript-eslint/no-var-requires': 'off',
'prettier/prettier': 'error',
},
ignorePatterns: ['build/**', 'node_modules/**'],
extends: ['universe/node'],
};
45 changes: 28 additions & 17 deletions build/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function restoreCache(paths, primaryKey, restoreKeys, options) {
if (core.isDebug()) {
yield tar_1.listTar(archivePath, compressionMethod);
}
const archiveFileSize = utils.getArchiveFileSizeIsBytes(archivePath);
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath);
core.info(`Cache Size: ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B)`);
yield tar_1.extractTar(archivePath, compressionMethod);
core.info('Cache restored successfully');
Expand Down Expand Up @@ -142,18 +142,29 @@ function saveCache(paths, key, options) {
const archiveFolder = yield utils.createTempDirectory();
const archivePath = path.join(archiveFolder, utils.getCacheFileName(compressionMethod));
core.debug(`Archive Path: ${archivePath}`);
yield tar_1.createTar(archiveFolder, cachePaths, compressionMethod);
if (core.isDebug()) {
yield tar_1.listTar(archivePath, compressionMethod);
try {
yield tar_1.createTar(archiveFolder, cachePaths, compressionMethod);
if (core.isDebug()) {
yield tar_1.listTar(archivePath, compressionMethod);
}
const fileSizeLimit = 10 * 1024 * 1024 * 1024; // 10GB per repo limit
const archiveFileSize = utils.getArchiveFileSizeInBytes(archivePath);
core.debug(`File Size: ${archiveFileSize}`);
if (archiveFileSize > fileSizeLimit) {
throw new Error(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 10GB limit, not saving cache.`);
}
core.debug(`Saving Cache (ID: ${cacheId})`);
yield cacheHttpClient.saveCache(cacheId, archivePath, options);
}
const fileSizeLimit = 5 * 1024 * 1024 * 1024; // 5GB per repo limit
const archiveFileSize = utils.getArchiveFileSizeIsBytes(archivePath);
core.debug(`File Size: ${archiveFileSize}`);
if (archiveFileSize > fileSizeLimit) {
throw new Error(`Cache size of ~${Math.round(archiveFileSize / (1024 * 1024))} MB (${archiveFileSize} B) is over the 5GB limit, not saving cache.`);
finally {
// Try to delete the archive to save space
try {
yield utils.unlinkFile(archivePath);
}
catch (error) {
core.debug(`Failed to delete archive: ${error}`);
}
}
core.debug(`Saving Cache (ID: ${cacheId})`);
yield cacheHttpClient.saveCache(cacheId, archivePath, options);
return cacheId;
});
}
Expand Down Expand Up @@ -321,7 +332,7 @@ function uploadChunk(httpClient, resourceUrl, openStream, start, end) {
function uploadFile(httpClient, cacheId, archivePath, options) {
return __awaiter(this, void 0, void 0, function* () {
// Upload Chunks
const fileSize = fs.statSync(archivePath).size;
const fileSize = utils.getArchiveFileSizeInBytes(archivePath);
const resourceUrl = getCacheApiUrl(`caches/${cacheId.toString()}`);
const fd = fs.openSync(archivePath, 'r');
const uploadOptions = options_1.getUploadOptions(options);
Expand Down Expand Up @@ -371,7 +382,7 @@ function saveCache(cacheId, archivePath, options) {
yield uploadFile(httpClient, cacheId, archivePath, options);
// Commit Cache
core.debug('Commiting cache');
const cacheSize = utils.getArchiveFileSizeIsBytes(archivePath);
const cacheSize = utils.getArchiveFileSizeInBytes(archivePath);
core.info(`Cache Size: ~${Math.round(cacheSize / (1024 * 1024))} MB (${cacheSize} B)`);
const commitCacheResponse = yield commitCache(httpClient, cacheId, cacheSize);
if (!requestUtils_1.isSuccessStatusCode(commitCacheResponse.statusCode)) {
Expand Down Expand Up @@ -451,10 +462,10 @@ function createTempDirectory() {
});
}
exports.createTempDirectory = createTempDirectory;
function getArchiveFileSizeIsBytes(filePath) {
function getArchiveFileSizeInBytes(filePath) {
return fs.statSync(filePath).size;
}
exports.getArchiveFileSizeIsBytes = getArchiveFileSizeIsBytes;
exports.getArchiveFileSizeInBytes = getArchiveFileSizeInBytes;
function resolvePaths(patterns) {
var e_1, _a;
var _b;
Expand Down Expand Up @@ -759,7 +770,7 @@ function downloadCacheHttpClient(archiveLocation, archivePath) {
const contentLengthHeader = downloadResponse.message.headers['content-length'];
if (contentLengthHeader) {
const expectedLength = parseInt(contentLengthHeader);
const actualLength = utils.getArchiveFileSizeIsBytes(archivePath);
const actualLength = utils.getArchiveFileSizeInBytes(archivePath);
if (actualLength !== expectedLength) {
throw new Error(`Incomplete download. Expected file size: ${expectedLength}, actual file size: ${actualLength}`);
}
Expand Down Expand Up @@ -67770,8 +67781,8 @@ exports.toRemoteCache = exports.fromRemoteCache = exports.toLocalCache = exports
const cache_1 = __nccwpck_require__(7799);
const core = __importStar(__nccwpck_require__(2186));
const toolCache = __importStar(__nccwpck_require__(7784));
const path_1 = __importDefault(__nccwpck_require__(1017));
const os_1 = __importDefault(__nccwpck_require__(2037));
const path_1 = __importDefault(__nccwpck_require__(1017));
/**
* Get the path to the `expo-cli` from cache, if any.
* Note, this cache is **NOT** shared between jobs.
Expand Down
1 change: 0 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ module.exports = {
moduleFileExtensions: ['js', 'ts'],
testEnvironment: 'node',
testMatch: ['**/*.test.ts'],
testRunner: 'jest-circus/runner',
transform: {
'^.+\\.ts$': 'ts-jest',
},
Expand Down
2 changes: 1 addition & 1 deletion ncc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const ncc = require('@vercel/ncc');
const fs = require('fs');
const path = require('path');
const ncc = require('@vercel/ncc');

build();

Expand Down
35 changes: 16 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,36 @@
"homepage": "https://github.com/expo/expo-github-action#readme",
"scripts": {
"test": "jest",
"lint": "tsc --noEmit && eslint .",
"lint": "eslint .",
"build": "node ncc.js",
"clean": "rimraf build"
},
"dependencies": {
"@actions/cache": "^1.0.7",
"@actions/cache": "^1.0.8",
"@actions/core": "^1.6.0",
"@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1",
"@actions/tool-cache": "^1.7.1",
"semver": "^7.3.5"
},
"devDependencies": {
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/git": "^9.0.0",
"@semantic-release/changelog": "^6.0.1",
"@semantic-release/git": "^10.0.1",
"@tsconfig/node16": "^1.0.2",
"@types/jest": "^27.0.2",
"@types/jest": "^27.4.0",
"@types/node": "^16.11.19",
"@types/semver": "^7.3.6",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"@types/semver": "^7.3.9",
"@typescript-eslint/eslint-plugin": "^5.9.1",
"@typescript-eslint/parser": "^5.9.1",
"@vercel/ncc": "^0.33.1",
"conventional-changelog-conventionalcommits": "^4.6.0",
"eslint": "^8.2.0",
"eslint-plugin-jest": "^25.2.4",
"eslint-plugin-prettier": "^4.0.0",
"jest": "^27.3.1",
"jest-circus": "^27.3.1",
"prettier": "^2.4.1",
"regenerator-runtime": "^0.13.9",
"conventional-changelog-conventionalcommits": "^4.6.3",
"eslint": "^8.6.0",
"eslint-config-universe": "^10.0.0",
"jest": "^27.4.7",
"prettier": "^2.5.1",
"rimraf": "^3.0.2",
"semantic-release": "^17.4.4",
"ts-jest": "^27.0.7",
"typescript": "^4.4.4"
"semantic-release": "^18.0.1",
"ts-jest": "^27.1.2",
"typescript": "^4.5.4"
}
}
2 changes: 1 addition & 1 deletion src/cache.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { ReserveCacheError, restoreCache, saveCache } from '@actions/cache';
import * as core from '@actions/core';
import * as toolCache from '@actions/tool-cache';
import path from 'path';
import os from 'os';
import path from 'path';

import type { InstallConfig } from './install';

Expand Down
1 change: 1 addition & 0 deletions tests/actions/setup.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/order,import/first */
import { getToolsMock, mockInput } from '../utils';

jest.mock('../../src/tools', () => getToolsMock());
Expand Down
4 changes: 2 additions & 2 deletions tests/cache.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os from 'os';
import { join } from 'path';
import * as remoteCache from '@actions/cache';
import * as core from '@actions/core';
import * as toolCache from '@actions/tool-cache';
import os from 'os';
import { join } from 'path';

import * as cache from '../src/cache';
import * as utils from './utils';
Expand Down
1 change: 1 addition & 0 deletions tests/install.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/order,import/first */
const cli = { exec: jest.fn() };
const io = { mkdirP: jest.fn(), which: jest.fn() };
const cache = {
Expand Down
1 change: 1 addition & 0 deletions tests/packager.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { valid as validVersion } from 'semver';

import { resolveVersion } from '../src/packager';

describe(resolveVersion, () => {
Expand Down
2 changes: 1 addition & 1 deletion tests/tools.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as core from '@actions/core';
import * as cli from '@actions/exec';

import * as tools from '../src/tools';
import * as packager from '../src/packager';
import * as tools from '../src/tools';
import * as utils from './utils';

describe(tools.getBinaryName, () => {
Expand Down
Loading