Skip to content

Commit

Permalink
Revert "use the @file mechanism of octokit-5"
Browse files Browse the repository at this point in the history
This reverts commit e5e4b80.
  • Loading branch information
ggreif committed Jan 31, 2023
1 parent 9927d3f commit af306bd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
});
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const fs = __importStar(__nccwpck_require__(7147));
const core = __importStar(__nccwpck_require__(2186));
const github = __importStar(__nccwpck_require__(5438));
const path = __importStar(__nccwpck_require__(1017));
Expand Down Expand Up @@ -68,6 +69,13 @@ function get_release_by_tag(tag, prerelease, release_name, body, octokit) {
}
function upload_to_release(release, file, asset_name, tag, overwrite, octokit) {
return __awaiter(this, void 0, void 0, function* () {
const stat = fs.statSync(file);
if (!stat.isFile()) {
core.debug(`Skipping ${file}, since its not a file`);
return;
}
const file_size = stat.size;
const file_bytes = fs.readFileSync(file).toString('binary');
// Check for duplicates.
const assets = yield octokit.paginate(repoAssets, Object.assign(Object.assign({}, repo()), { release_id: release.data.id }));
const duplicate_asset = assets.find(a => a.name === asset_name);
Expand All @@ -85,7 +93,10 @@ function upload_to_release(release, file, asset_name, tag, overwrite, octokit) {
core.debug(`No pre-existing asset called ${asset_name} found in release ${tag}. All good.`);
}
core.debug(`Uploading ${file} to ${asset_name} in release ${tag}.`);
const uploaded_asset = yield octokit.request(uploadAssets, Object.assign(Object.assign({}, repo()), { release_id: release.data.id, name: asset_name, data: '@' + file }));
const uploaded_asset = yield octokit.request(uploadAssets, Object.assign(Object.assign({}, repo()), { release_id: release.data.id, url: release.data.upload_url, name: asset_name, data: file_bytes, headers: {
'content-type': 'binary/octet-stream',
'content-length': file_size
} }));
return uploaded_asset.data.browser_download_url;
});
}
Expand Down
16 changes: 15 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as fs from 'fs'
import {Octokit} from '@octokit/core'
import {Endpoints} from '@octokit/types'
import * as core from '@actions/core'
Expand Down Expand Up @@ -59,6 +60,14 @@ async function upload_to_release(
overwrite: boolean,
octokit: ReturnType<(typeof github)['getOctokit']>
): Promise<undefined | string> {
const stat = fs.statSync(file)
if (!stat.isFile()) {
core.debug(`Skipping ${file}, since its not a file`)
return
}
const file_size = stat.size
const file_bytes = fs.readFileSync(file).toString('binary')

// Check for duplicates.
const assets: RepoAssetsResp = await octokit.paginate(repoAssets, {
...repo(),
Expand Down Expand Up @@ -88,8 +97,13 @@ async function upload_to_release(
const uploaded_asset: UploadAssetResp = await octokit.request(uploadAssets, {
...repo(),
release_id: release.data.id,
url: release.data.upload_url,
name: asset_name,
data: '@' + file
data: file_bytes,
headers: {
'content-type': 'binary/octet-stream',
'content-length': file_size
}
})
return uploaded_asset.data.browser_download_url
}
Expand Down

0 comments on commit af306bd

Please sign in to comment.