This repository has been archived by the owner on Mar 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 190
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
103 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters