Skip to content

Commit

Permalink
released v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Jul 28, 2024
1 parent a088d66 commit c14dd25
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 62 deletions.
17 changes: 4 additions & 13 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35993,7 +35993,7 @@ var qmarksTestNoExtDot = function qmarksTestNoExtDot(_ref11) {
};
/* c8 ignore start */
var defaultPlatform = typeof process === 'object' && process ? typeof process.env === 'object' && process.env && process.env.__MINIMATCH_TESTING_PLATFORM__ || process.platform : 'posix';
var esm_path = {
var path = {
win32: {
sep: '\\'
},
Expand All @@ -36002,7 +36002,7 @@ var esm_path = {
}
};
/* c8 ignore stop */
var sep = defaultPlatform === 'win32' ? esm_path.win32.sep : esm_path.posix.sep;
var sep = defaultPlatform === 'win32' ? path.win32.sep : path.posix.sep;
minimatch.sep = sep;
var GLOBSTAR = Symbol('globstar **');
minimatch.GLOBSTAR = GLOBSTAR;
Expand Down Expand Up @@ -44974,17 +44974,8 @@ currentTag=tag||tagName.replace("refs/tags/","");octokit=(0,github.getOctokit)(m
// API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release
// Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release
_context.next=8;return octokit.rest.repos.getReleaseByTag({owner:owner,repo:repo,tag:currentTag});case 8:getReleaseResponse=_context.sent;return _context.abrupt("return",getReleaseResponse.data);case 10:case"end":return _context.stop();}},_callee);}));return _getReleaseURL.apply(this,arguments);}function getAssetName(assetPath){try{return JSON.parse(assetPath);}catch(error){if(assetPath){return assetPath;}}return undefined;}// Function to upload the file
function uploadFile(_x2,_x3,_x4,_x5){return _uploadFile.apply(this,arguments);}// Function to upload the file
function _uploadFile(){_uploadFile=(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee2(owner,repo,releaseId,filePath){var myToken,octokit,fileContent,fileStream,fileStat,fileName,headers,response;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:myToken=(0,core.getInput)('token');octokit=(0,github.getOctokit)(myToken);fileContent=external_fs_default().readFileSync(filePath);// Read file content as Buffer
fileStream=external_fs_default().createReadStream(filePath);fileStat=external_fs_default().statSync(filePath);fileName=external_path_default().basename(filePath);headers={'content-type':'application/octet-stream','content-length':fileStat.size,'X-GitHub-Api-Version':'2022-11-28'};_context2.next=9;return octokit.rest.repos.uploadReleaseAsset({owner:owner,repo:repo,release_id:releaseId,headers:headers,name:fileName,//data: fileContent.toString() // Use file content directly
data:fileStream});case 9:response=_context2.sent;return _context2.abrupt("return",response);case 11:case"end":return _context2.stop();}},_callee2);}));return _uploadFile.apply(this,arguments);}function requestUploadFile(_x6,_x7){return _requestUploadFile.apply(this,arguments);}function _requestUploadFile(){_requestUploadFile=_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee3(releaseId,filePath){var myToken,octokit,fileStream,fileName,fileStat,headers,_context$repo2,owner,repo,response;return _regeneratorRuntime().wrap(function _callee3$(_context3){while(1)switch(_context3.prev=_context3.next){case 0:myToken=getInput('token');octokit=getOctokit(myToken);// const fileStream = fs.createReadStream(filePath);
// const fileName = path.basename(filePath);
// const form = new FormData();
// form.append('file', fileStream, {
// filename: fileName,
// contentType: 'application/octet-stream'
// });
fileStream=fs.createReadStream(filePath);fileName=path.basename(filePath);fileStat=fs.statSync(filePath);headers={'content-type':'application/octet-stream','content-length':fileStat.size,'X-GitHub-Api-Version':'2022-11-28'};_context$repo2=context.repo,owner=_context$repo2.owner,repo=_context$repo2.repo;_context3.next=9;return octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}',{owner:owner,repo:repo,release_id:releaseId,name:fileName,headers:headers,data:fileStream});case 9:response=_context3.sent;return _context3.abrupt("return",response);case 11:case"end":return _context3.stop();}},_callee3);}));return _requestUploadFile.apply(this,arguments);}
function uploadFile(_x2,_x3,_x4,_x5){return _uploadFile.apply(this,arguments);}function _uploadFile(){_uploadFile=(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee2(owner,repo,releaseId,filePath){var myToken,octokit,fileStream,fileStat,fileName,headers,response;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee2$(_context2){while(1)switch(_context2.prev=_context2.next){case 0:myToken=(0,core.getInput)('token');octokit=(0,github.getOctokit)(myToken);fileStream=external_fs_default().createReadStream(filePath);fileStat=external_fs_default().statSync(filePath);fileName=external_path_default().basename(filePath);headers={'content-type':'application/octet-stream','content-length':fileStat.size,'X-GitHub-Api-Version':'2022-11-28'};_context2.next=8;return octokit.rest.repos.uploadReleaseAsset({owner:owner,repo:repo,release_id:releaseId,headers:headers,name:fileName,//data: fileContent.toString() // Use file content directly
data:fileStream});case 8:response=_context2.sent;return _context2.abrupt("return",response);case 10:case"end":return _context2.stop();}},_callee2);}));return _uploadFile.apply(this,arguments);}
;// CONCATENATED MODULE: ./src/index.ts
;(0,asyncToGenerator/* default */.A)(/*#__PURE__*/(0,regeneratorRuntime/* default */.A)().mark(function _callee(){var assetPath,tagName,files,release,downloadURLs,i,assetFile,response;return (0,regeneratorRuntime/* default */.A)().wrap(function _callee$(_context){while(1)switch(_context.prev=_context.next){case 0:/**
* Get the path to the file to upload
Expand Down
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "github-action-upload-assets",
"version": "0.0.3",
"version": "1.0.0",
"private": false,
"description": "GitHub Action to upload multiple assets to a release",
"homepage": "https://jaywcjlove.github.io/github-action-upload-assets/",
Expand Down Expand Up @@ -31,7 +31,6 @@
"@actions/core": "^1.10.1",
"@actions/github": "^6.0.0",
"@octokit/rest": "^21.0.1",
"form-data": "^4.0.0",
"glob": "^11.0.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { context } from '@actions/github';
import { getInput, setFailed, setOutput, info } from '@actions/core';
import { glob } from 'glob';
import { getAssetName, getReleaseURL, uploadFile, requestUploadFile } from './utils';
import { getAssetName, getReleaseURL, uploadFile } from './utils';

;(async () => {
/**
Expand Down
46 changes: 0 additions & 46 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import fs from 'fs';
import path from 'path';
import { context, getOctokit } from '@actions/github';
import { getInput, info } from '@actions/core';
import FormData from 'form-data';

/**
* get the release URL from the tag
Expand Down Expand Up @@ -45,8 +44,6 @@ export function getAssetName(assetPath: string): string | string[] | undefined {
export async function uploadFile(owner: string, repo: string, releaseId: number, filePath: string) {
const myToken = getInput('token')
const octokit = getOctokit(myToken);

const fileContent = fs.readFileSync(filePath); // Read file content as Buffer
const fileStream = fs.createReadStream(filePath);
const fileStat = fs.statSync(filePath);
const fileName = path.basename(filePath);
Expand All @@ -69,46 +66,3 @@ export async function uploadFile(owner: string, repo: string, releaseId: number,

return response;
}

// Function to upload the file
export async function requestUploadFile(releaseId: number, filePath: string) {
const myToken = getInput('token')
const octokit = getOctokit(myToken);
// const fileStream = fs.createReadStream(filePath);
// const fileName = path.basename(filePath);
// const form = new FormData();
// form.append('file', fileStream, {
// filename: fileName,
// contentType: 'application/octet-stream'
// });
const fileStream = fs.createReadStream(filePath);
const fileName = path.basename(filePath);
const fileStat = fs.statSync(filePath);

const headers = {
'content-type': 'application/octet-stream',
'content-length': fileStat.size,
'X-GitHub-Api-Version': '2022-11-28'
};
const { owner, repo } = context.repo;
const response = await octokit.request('POST /repos/{owner}/{repo}/releases/{release_id}/assets{?name,label}', {
owner,
repo,
release_id: releaseId,
name: fileName,
headers,
data: fileStream
});
// const headers = { ...form.getHeaders(), 'Authorization': `token ${myToken}` };
// const url = new URL(uploadUrl);
// url.searchParams.append('name', fileName);
// info(`URL: ${url.toString()}`);
// const response = await octokit.request({
// method: 'POST',
// url: url.toString(),
// headers: headers,
// data: form
// });

return response;
}

0 comments on commit c14dd25

Please sign in to comment.