Skip to content

Commit 867a1a2

Browse files
authored
Fix broken downloads (#31)
* 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
1 parent d6f2279 commit 867a1a2

File tree

3 files changed

+69
-42
lines changed

3 files changed

+69
-42
lines changed

action.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,13 @@ async function run () {
7272
let url = assetToDownload.browser_download_url
7373
let auth
7474
if (githubToken) {
75+
core.debug(`GitHub Token provided, using API to download`)
7576
auth = 'token ' + (githubToken)
7677
url = assetToDownload.url
7778
}
7879

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

8283
if (expectedArchiveChecksum !== '') {
8384
const downloadedArchiveChecksum = crypto.createHash('sha256').update(await fs.readFile(downloadedArchive)).digest('hex')

dist/index.js

Lines changed: 66 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,13 @@ async function run () {
7979
let url = assetToDownload.browser_download_url
8080
let auth
8181
if (githubToken) {
82+
core.debug(`GitHub Token provided, using API to download`)
8283
auth = 'token ' + (githubToken)
8384
url = assetToDownload.url
8485
}
8586

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

8990
if (expectedArchiveChecksum !== '') {
9091
const downloadedArchiveChecksum = crypto.createHash('sha256').update(await fs.readFile(downloadedArchive)).digest('hex')
@@ -4506,17 +4507,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
45064507
};
45074508
var _a;
45084509
Object.defineProperty(exports, "__esModule", ({ value: true }));
4509-
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;
4510+
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;
45104511
const fs = __importStar(__nccwpck_require__(7147));
45114512
const path = __importStar(__nccwpck_require__(1017));
4512-
_a = fs.promises
4513-
// export const {open} = 'fs'
4514-
, 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;
4515-
// export const {open} = 'fs'
4513+
_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;
45164514
exports.IS_WINDOWS = process.platform === 'win32';
4517-
// See https://github.com/nodejs/node/blob/d0153aee367422d0858105abec186da4dff0a0c5/deps/uv/include/uv/win.h#L691
4518-
exports.UV_FS_O_EXLOCK = 0x10000000;
4519-
exports.READONLY = fs.constants.O_RDONLY;
45204515
function exists(fsPath) {
45214516
return __awaiter(this, void 0, void 0, function* () {
45224517
try {
@@ -4697,8 +4692,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
46974692
Object.defineProperty(exports, "__esModule", ({ value: true }));
46984693
exports.findInPath = exports.which = exports.mkdirP = exports.rmRF = exports.mv = exports.cp = void 0;
46994694
const assert_1 = __nccwpck_require__(9491);
4695+
const childProcess = __importStar(__nccwpck_require__(2081));
47004696
const path = __importStar(__nccwpck_require__(1017));
4697+
const util_1 = __nccwpck_require__(3837);
47014698
const ioUtil = __importStar(__nccwpck_require__(1962));
4699+
const exec = util_1.promisify(childProcess.exec);
4700+
const execFile = util_1.promisify(childProcess.execFile);
47024701
/**
47034702
* Copies a file or folder.
47044703
* Based off of shelljs - https://github.com/shelljs/shelljs/blob/9237f66c52e5daa40458f94f9565e18e8132f5a6/src/cp.js
@@ -4779,23 +4778,61 @@ exports.mv = mv;
47794778
function rmRF(inputPath) {
47804779
return __awaiter(this, void 0, void 0, function* () {
47814780
if (ioUtil.IS_WINDOWS) {
4781+
// Node doesn't provide a delete operation, only an unlink function. This means that if the file is being used by another
4782+
// program (e.g. antivirus), it won't be deleted. To address this, we shell out the work to rd/del.
47824783
// Check for invalid characters
47834784
// https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file
47844785
if (/[*"<>|]/.test(inputPath)) {
47854786
throw new Error('File path must not contain `*`, `"`, `<`, `>` or `|` on Windows');
47864787
}
4788+
try {
4789+
const cmdPath = ioUtil.getCmdPath();
4790+
if (yield ioUtil.isDirectory(inputPath, true)) {
4791+
yield exec(`${cmdPath} /s /c "rd /s /q "%inputPath%""`, {
4792+
env: { inputPath }
4793+
});
4794+
}
4795+
else {
4796+
yield exec(`${cmdPath} /s /c "del /f /a "%inputPath%""`, {
4797+
env: { inputPath }
4798+
});
4799+
}
4800+
}
4801+
catch (err) {
4802+
// if you try to delete a file that doesn't exist, desired result is achieved
4803+
// other errors are valid
4804+
if (err.code !== 'ENOENT')
4805+
throw err;
4806+
}
4807+
// Shelling out fails to remove a symlink folder with missing source, this unlink catches that
4808+
try {
4809+
yield ioUtil.unlink(inputPath);
4810+
}
4811+
catch (err) {
4812+
// if you try to delete a file that doesn't exist, desired result is achieved
4813+
// other errors are valid
4814+
if (err.code !== 'ENOENT')
4815+
throw err;
4816+
}
47874817
}
4788-
try {
4789-
// note if path does not exist, error is silent
4790-
yield ioUtil.rm(inputPath, {
4791-
force: true,
4792-
maxRetries: 3,
4793-
recursive: true,
4794-
retryDelay: 300
4795-
});
4796-
}
4797-
catch (err) {
4798-
throw new Error(`File was unable to be removed ${err}`);
4818+
else {
4819+
let isDir = false;
4820+
try {
4821+
isDir = yield ioUtil.isDirectory(inputPath);
4822+
}
4823+
catch (err) {
4824+
// if you try to delete a file that doesn't exist, desired result is achieved
4825+
// other errors are valid
4826+
if (err.code !== 'ENOENT')
4827+
throw err;
4828+
return;
4829+
}
4830+
if (isDir) {
4831+
yield execFile(`rm`, [`-rf`, `${inputPath}`]);
4832+
}
4833+
else {
4834+
yield ioUtil.unlink(inputPath);
4835+
}
47994836
}
48004837
});
48014838
}
@@ -7958,10 +7995,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
79587995
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
79597996

79607997
var Bottleneck = _interopDefault(__nccwpck_require__(1174));
7961-
var requestError = __nccwpck_require__(537);
79627998

79637999
// @ts-ignore
7964-
async function errorRequest(state, octokit, error, options) {
8000+
async function errorRequest(octokit, state, error, options) {
79658001
if (!error.request || !error.request.request) {
79668002
// address https://github.com/octokit/plugin-retry.js/issues/8
79678003
throw error;
@@ -7976,9 +8012,11 @@ async function errorRequest(state, octokit, error, options) {
79768012
throw error;
79778013
}
79788014

7979-
// @ts-nocheck
7980-
async function wrapRequest(state, octokit, request, options) {
8015+
// @ts-ignore
8016+
// @ts-ignore
8017+
async function wrapRequest(state, request, options) {
79818018
const limiter = new Bottleneck();
8019+
// @ts-ignore
79828020
limiter.on("failed", function (error, info) {
79838021
const maxRetries = ~~error.request.request.retries;
79848022
const after = ~~error.request.request.retryAfter;
@@ -7989,22 +8027,10 @@ async function wrapRequest(state, octokit, request, options) {
79898027
return after * state.retryAfterBaseValue;
79908028
}
79918029
});
7992-
return limiter.schedule(requestWithGraphqlErrorHandling.bind(null, state, octokit, request), options);
7993-
}
7994-
async function requestWithGraphqlErrorHandling(state, octokit, request, options) {
7995-
const response = await request(request, options);
7996-
if (response.data && response.data.errors && /Something went wrong while executing your query/.test(response.data.errors[0].message)) {
7997-
// simulate 500 request error for retry handling
7998-
const error = new requestError.RequestError(response.data.errors[0].message, 500, {
7999-
request: options,
8000-
response
8001-
});
8002-
return errorRequest(state, octokit, error, options);
8003-
}
8004-
return response;
8030+
return limiter.schedule(request, options);
80058031
}
80068032

8007-
const VERSION = "4.1.3";
8033+
const VERSION = "4.0.4";
80088034
function retry(octokit, octokitOptions) {
80098035
const state = Object.assign({
80108036
enabled: true,
@@ -8013,8 +8039,8 @@ function retry(octokit, octokitOptions) {
80138039
retries: 3
80148040
}, octokitOptions.retry);
80158041
if (state.enabled) {
8016-
octokit.hook.error("request", errorRequest.bind(null, state, octokit));
8017-
octokit.hook.wrap("request", wrapRequest.bind(null, state, octokit));
8042+
octokit.hook.error("request", errorRequest.bind(null, octokit, state));
8043+
octokit.hook.wrap("request", wrapRequest.bind(null, state));
80188044
}
80198045
return {
80208046
retry: {

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)