diff --git a/dist/index.js b/dist/index.js index e5d372c..3ef066e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -378,56 +378,11 @@ module.exports._enoent = enoent; /***/ }), /***/ 31: -/***/ (function(module, __unusedexports, __webpack_require__) { - -const core = __webpack_require__(470); -const { GitHub } = __webpack_require__(469); -const fs = __webpack_require__(747); - -async function run() { - try { - // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage - const github = new GitHub(process.env.GITHUB_TOKEN); - - // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs - const uploadUrl = core.getInput('upload_url', { required: true }); - const assetPath = core.getInput('asset_path', { required: true }); - const assetName = core.getInput('asset_name', { required: true }); - const assetContentType = core.getInput('asset_content_type', { required: true }); - - // Determine content-length for header to upload asset - const contentLength = filePath => fs.statSync(filePath).size; - - // Setup headers for API call, see Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset for more information - const headers = { 'content-type': assetContentType, 'content-length': contentLength(assetPath) }; - - // Upload a release asset - // API Documentation: https://developer.github.com/v3/repos/releases/#upload-a-release-asset - // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset - const uploadAssetResponse = await github.repos.uploadReleaseAsset({ - url: uploadUrl, - headers, - name: assetName, - file: assetPath - }); - - // Get the browser_download_url for the uploaded release asset from the response - const { - data: { browser_download_url: browserDownloadUrl } - } = uploadAssetResponse; - - // Set the output variable for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs - core.setOutput('browser_download_url', browserDownloadUrl); - } catch (error) { - core.setFailed(error.message); - } -} +/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) { -module.exports = run; +const run = __webpack_require__(379); -if (require.main === require.cache[eval('__filename')]) { - run(); -} +run(); /***/ }), @@ -4153,6 +4108,57 @@ function octokitDebug (octokit) { } +/***/ }), + +/***/ 379: +/***/ (function(module, __unusedexports, __webpack_require__) { + +const core = __webpack_require__(470); +const { GitHub } = __webpack_require__(469); +const fs = __webpack_require__(747); + +async function run() { + try { + // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage + const github = new GitHub(process.env.GITHUB_TOKEN); + + // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs + const uploadUrl = core.getInput('upload_url', { required: true }); + const assetPath = core.getInput('asset_path', { required: true }); + const assetName = core.getInput('asset_name', { required: true }); + const assetContentType = core.getInput('asset_content_type', { required: true }); + + // Determine content-length for header to upload asset + const contentLength = filePath => fs.statSync(filePath).size; + + // Setup headers for API call, see Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset for more information + const headers = { 'content-type': assetContentType, 'content-length': contentLength(assetPath) }; + + // Upload a release asset + // API Documentation: https://developer.github.com/v3/repos/releases/#upload-a-release-asset + // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset + const uploadAssetResponse = await github.repos.uploadReleaseAsset({ + url: uploadUrl, + headers, + name: assetName, + file: assetPath + }); + + // Get the browser_download_url for the uploaded release asset from the response + const { + data: { browser_download_url: browserDownloadUrl } + } = uploadAssetResponse; + + // Set the output variable for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs + core.setOutput('browser_download_url', browserDownloadUrl); + } catch (error) { + core.setFailed(error.message); + } +} + +module.exports = run; + + /***/ }), /***/ 385: diff --git a/package.json b/package.json index 407bda2..4ca8d42 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "main": "dist/index.js", "scripts": { "lint": "eslint 'src/**.js' 'tests/**.js' --fix", - "test": "eslint 'src/**.js' 'tests/**.js' --fix && jest", + "test": "eslint 'src/**.js' 'tests/**.js' && jest --coverage", "build": "ncc build src/main.js", "precommit": "npm run build && git add dist/" }, @@ -41,7 +41,7 @@ "jest": { "testEnvironment": "node", "collectCoverageFrom": [ - "src/main.js" + "src/upload-release-asset.js" ], "coverageThreshold": { "global": { diff --git a/src/main.js b/src/main.js index 8799239..1e1955b 100644 --- a/src/main.js +++ b/src/main.js @@ -1,48 +1,3 @@ -const core = require('@actions/core'); -const { GitHub } = require('@actions/github'); -const fs = require('fs'); +const run = require('./upload-release-asset'); -async function run() { - try { - // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage - const github = new GitHub(process.env.GITHUB_TOKEN); - - // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs - const uploadUrl = core.getInput('upload_url', { required: true }); - const assetPath = core.getInput('asset_path', { required: true }); - const assetName = core.getInput('asset_name', { required: true }); - const assetContentType = core.getInput('asset_content_type', { required: true }); - - // Determine content-length for header to upload asset - const contentLength = filePath => fs.statSync(filePath).size; - - // Setup headers for API call, see Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset for more information - const headers = { 'content-type': assetContentType, 'content-length': contentLength(assetPath) }; - - // Upload a release asset - // API Documentation: https://developer.github.com/v3/repos/releases/#upload-a-release-asset - // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset - const uploadAssetResponse = await github.repos.uploadReleaseAsset({ - url: uploadUrl, - headers, - name: assetName, - file: assetPath - }); - - // Get the browser_download_url for the uploaded release asset from the response - const { - data: { browser_download_url: browserDownloadUrl } - } = uploadAssetResponse; - - // Set the output variable for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs - core.setOutput('browser_download_url', browserDownloadUrl); - } catch (error) { - core.setFailed(error.message); - } -} - -module.exports = run; - -if (require.main === module) { - run(); -} +run(); diff --git a/src/upload-release-asset.js b/src/upload-release-asset.js new file mode 100644 index 0000000..fb07643 --- /dev/null +++ b/src/upload-release-asset.js @@ -0,0 +1,44 @@ +const core = require('@actions/core'); +const { GitHub } = require('@actions/github'); +const fs = require('fs'); + +async function run() { + try { + // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage + const github = new GitHub(process.env.GITHUB_TOKEN); + + // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs + const uploadUrl = core.getInput('upload_url', { required: true }); + const assetPath = core.getInput('asset_path', { required: true }); + const assetName = core.getInput('asset_name', { required: true }); + const assetContentType = core.getInput('asset_content_type', { required: true }); + + // Determine content-length for header to upload asset + const contentLength = filePath => fs.statSync(filePath).size; + + // Setup headers for API call, see Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset for more information + const headers = { 'content-type': assetContentType, 'content-length': contentLength(assetPath) }; + + // Upload a release asset + // API Documentation: https://developer.github.com/v3/repos/releases/#upload-a-release-asset + // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-upload-release-asset + const uploadAssetResponse = await github.repos.uploadReleaseAsset({ + url: uploadUrl, + headers, + name: assetName, + file: assetPath + }); + + // Get the browser_download_url for the uploaded release asset from the response + const { + data: { browser_download_url: browserDownloadUrl } + } = uploadAssetResponse; + + // Set the output variable for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs + core.setOutput('browser_download_url', browserDownloadUrl); + } catch (error) { + core.setFailed(error.message); + } +} + +module.exports = run; diff --git a/tests/main.test.js b/tests/upload-release-asset.test.js similarity index 97% rename from tests/main.test.js rename to tests/upload-release-asset.test.js index f5c025d..37a2686 100644 --- a/tests/main.test.js +++ b/tests/upload-release-asset.test.js @@ -5,7 +5,7 @@ jest.mock('fs'); const core = require('@actions/core'); const { GitHub, context } = require('@actions/github'); const fs = require('fs'); -const run = require('../src/main.js'); +const run = require('../src/upload-release-asset'); /* eslint-disable no-undef */ describe('Upload Release Asset', () => {