Skip to content

Commit

Permalink
Merge pull request #93 from ggreif/gabor/fix
Browse files Browse the repository at this point in the history
Fix uploading of assets
  • Loading branch information
svenstaro authored Jan 31, 2023
2 parents 9927d3f + f2899b4 commit 72f6bf5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
17 changes: 15 additions & 2 deletions 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.createReadStream(file);
// 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 Expand Up @@ -9561,7 +9572,9 @@ function fetch(url, opts) {
return;
}

destroyStream(response.body, err);
if (response && response.body) {
destroyStream(response.body, err);
}
});

/* c8 ignore next 18 */
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: any = fs.createReadStream(file)

// 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 72f6bf5

Please sign in to comment.