-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
8b83f86
commit da14ab3
Showing
3 changed files
with
35 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,34 @@ | ||
const run = require('./upload-artifact'); | ||
const core = require('@actions/core'); | ||
const { GitHub } = require('@actions/github'); | ||
const fs = require('fs'); | ||
|
||
if (require.main === module) { | ||
run(); | ||
} | ||
(async () => { | ||
try { | ||
const event = JSON.parse(fs.readFileSync(process.env.GITHUB_EVENT_PATH)); | ||
console.log(event); | ||
|
||
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage | ||
const github = new GitHub(process.env.GITHUB_TOKEN); | ||
const assetPath = core.getInput('asset_path', { required: true }); | ||
const assetName = core.getInput('asset_name', { 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': 'application/zip', '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 | ||
await github.repos.uploadReleaseAsset({ | ||
url: event.release.upload_url, | ||
headers, | ||
name: assetName, | ||
file: fs.readFileSync(assetPath) | ||
}); | ||
|
||
} catch (error) { | ||
core.setFailed(error.message); | ||
} | ||
})(); |
34 changes: 0 additions & 34 deletions
34
.github/actions/upload_release_artifact/upload-artifact.js
This file was deleted.
Oops, something went wrong.
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