Skip to content

Commit

Permalink
Fix broken downloads (#31)
Browse files Browse the repository at this point in the history
* Add debug statement

* Temporarily update branch name

* Update action.js

* Helps if I rebuild dist...

* Add header for download

* Remove context dump

* Revert custom branch testing override
  • Loading branch information
CalebAlbers authored Apr 14, 2023
1 parent d6f2279 commit 867a1a2
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 42 deletions.
3 changes: 2 additions & 1 deletion action.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ async function run () {
let url = assetToDownload.browser_download_url
let auth
if (githubToken) {
core.debug(`GitHub Token provided, using API to download`)
auth = 'token ' + (githubToken)
url = assetToDownload.url
}

core.debug(`Downloading ${repo} release from ${url}`)
const downloadedArchive = await tc.downloadTool(url, undefined, auth)
const downloadedArchive = await tc.downloadTool(url, undefined, auth, { accept: 'application/octet-stream' })

if (expectedArchiveChecksum !== '') {
const downloadedArchiveChecksum = crypto.createHash('sha256').update(await fs.readFile(downloadedArchive)).digest('hex')
Expand Down
106 changes: 66 additions & 40 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,13 @@ async function run () {
let url = assetToDownload.browser_download_url
let auth
if (githubToken) {
core.debug(`GitHub Token provided, using API to download`)
auth = 'token ' + (githubToken)
url = assetToDownload.url
}

core.debug(`Downloading ${repo} release from ${url}`)
const downloadedArchive = await tc.downloadTool(url, undefined, auth)
const downloadedArchive = await tc.downloadTool(url, undefined, auth, { accept: 'application/octet-stream' })

if (expectedArchiveChecksum !== '') {
const downloadedArchiveChecksum = crypto.createHash('sha256').update(await fs.readFile(downloadedArchive)).digest('hex')
Expand Down Expand Up @@ -4506,17 +4507,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
};
var _a;
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.READONLY = exports.UV_FS_O_EXLOCK = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rm = exports.rename = exports.readlink = exports.readdir = exports.open = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0;
exports.getCmdPath = exports.tryGetExecutablePath = exports.isRooted = exports.isDirectory = exports.exists = exports.IS_WINDOWS = exports.unlink = exports.symlink = exports.stat = exports.rmdir = exports.rename = exports.readlink = exports.readdir = exports.mkdir = exports.lstat = exports.copyFile = exports.chmod = void 0;
const fs = __importStar(__nccwpck_require__(7147));
const path = __importStar(__nccwpck_require__(1017));
_a = fs.promises
// export const {open} = 'fs'
, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.open = _a.open, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rm = _a.rm, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink;
// export const {open} = 'fs'
_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink;
exports.IS_WINDOWS = process.platform === 'win32';
// See https://github.com/nodejs/node/blob/d0153aee367422d0858105abec186da4dff0a0c5/deps/uv/include/uv/win.h#L691
exports.UV_FS_O_EXLOCK = 0x10000000;
exports.READONLY = fs.constants.O_RDONLY;
function exists(fsPath) {
return __awaiter(this, void 0, void 0, function* () {
try {
Expand Down Expand Up @@ -4697,8 +4692,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.findInPath = exports.which = exports.mkdirP = exports.rmRF = exports.mv = exports.cp = void 0;
const assert_1 = __nccwpck_require__(9491);
const childProcess = __importStar(__nccwpck_require__(2081));
const path = __importStar(__nccwpck_require__(1017));
const util_1 = __nccwpck_require__(3837);
const ioUtil = __importStar(__nccwpck_require__(1962));
const exec = util_1.promisify(childProcess.exec);
const execFile = util_1.promisify(childProcess.execFile);
/**
* Copies a file or folder.
* Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js
Expand Down Expand Up @@ -4779,23 +4778,61 @@ exports.mv = mv;
function rmRF(inputPath) {
return __awaiter(this, void 0, void 0, function* () {
if (ioUtil.IS_WINDOWS) {
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
// Check for invalid characters
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
if (/[*"<>|]/.test(inputPath)) {
throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows');
}
try {
const cmdPath = ioUtil.getCmdPath();
if (yield ioUtil.isDirectory(inputPath, true)) {
yield exec(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, {
env: { inputPath }
});
}
else {
yield exec(`${cmdPath} /s /c "del /f /a "%inputPath%""`, {
env: { inputPath }
});
}
}
catch (err) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if (err.code !== 'ENOENT')
throw err;
}
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
try {
yield ioUtil.unlink(inputPath);
}
catch (err) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if (err.code !== 'ENOENT')
throw err;
}
}
try {
// note if path does not exist, error is silent
yield ioUtil.rm(inputPath, {
force: true,
maxRetries: 3,
recursive: true,
retryDelay: 300
});
}
catch (err) {
throw new Error(`File was unable to be removed ${err}`);
else {
let isDir = false;
try {
isDir = yield ioUtil.isDirectory(inputPath);
}
catch (err) {
// if you try to delete a file that doesn't exist, desired result is achieved
// other errors are valid
if (err.code !== 'ENOENT')
throw err;
return;
}
if (isDir) {
yield execFile(`rm`, [`-rf`, `${inputPath}`]);
}
else {
yield ioUtil.unlink(inputPath);
}
}
});
}
Expand Down Expand Up @@ -7958,10 +7995,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }

var Bottleneck = _interopDefault(__nccwpck_require__(1174));
var requestError = __nccwpck_require__(537);

// @ts-ignore
async function errorRequest(state, octokit, error, options) {
async function errorRequest(octokit, state, error, options) {
if (!error.request || !error.request.request) {
// address https://github.com/octokit/plugin-retry.js/issues/8
throw error;
Expand All @@ -7976,9 +8012,11 @@ async function errorRequest(state, octokit, error, options) {
throw error;
}

// @ts-nocheck
async function wrapRequest(state, octokit, request, options) {
// @ts-ignore
// @ts-ignore
async function wrapRequest(state, request, options) {
const limiter = new Bottleneck();
// @ts-ignore
limiter.on("failed", function (error, info) {
const maxRetries = ~~error.request.request.retries;
const after = ~~error.request.request.retryAfter;
Expand All @@ -7989,22 +8027,10 @@ async function wrapRequest(state, octokit, request, options) {
return after * state.retryAfterBaseValue;
}
});
return limiter.schedule(requestWithGraphqlErrorHandling.bind(null, state, octokit, request), options);
}
async function requestWithGraphqlErrorHandling(state, octokit, request, options) {
const response = await request(request, options);
if (response.data && response.data.errors && /Something went wrong while executing your query/.test(response.data.errors[0].message)) {
// simulate 500 request error for retry handling
const error = new requestError.RequestError(response.data.errors[0].message, 500, {
request: options,
response
});
return errorRequest(state, octokit, error, options);
}
return response;
return limiter.schedule(request, options);
}

const VERSION = "4.1.3";
const VERSION = "4.0.4";
function retry(octokit, octokitOptions) {
const state = Object.assign({
enabled: true,
Expand All @@ -8013,8 +8039,8 @@ function retry(octokit, octokitOptions) {
retries: 3
}, octokitOptions.retry);
if (state.enabled) {
octokit.hook.error("request", errorRequest.bind(null, state, octokit));
octokit.hook.wrap("request", wrapRequest.bind(null, state, octokit));
octokit.hook.error("request", errorRequest.bind(null, octokit, state));
octokit.hook.wrap("request", wrapRequest.bind(null, state));
}
return {
retry: {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

0 comments on commit 867a1a2

Please sign in to comment.