Skip to content

Commit

Permalink
Handle upload myself
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashdoughty committed Nov 12, 2019
1 parent 305de95 commit 6410e49
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 18 deletions.
42 changes: 41 additions & 1 deletion .github/actions/output-event/output-event.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
const core = require('@actions/core');
const { release } = require(process.env.GITHUB_EVENT_PATH);
const { GitHub } = require('@actions/github');
const { release: { upload_url } } = require(process.env.GITHUB_EVENT_PATH);
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);
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: upload_url,
headers,
name: assetName,
file: fs.readFileSync(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;

module.exports = () => {
Object.entries(release).forEach(([key, value]) => {
Expand Down
22 changes: 5 additions & 17 deletions .github/workflows/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,11 @@ jobs:
run: npm install

- name: Get release event
id: get_release_event
id: upload_existing_release_asset
uses: ./.github/actions/output-event

- name: Upload release
uses: yakuhzi/action-release@v1
with:
file: ./dist/my-artifact.zip
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Upload Release Asset
# id: upload-release-asset
# uses: actions/[email protected]
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# with:
# upload_url: ${{ steps.get_release_event.outputs.upload_url }}
# asset_path: ./dist/my-artifact.zip
# asset_name: my-artifact.zip
# asset_content_type: application/zip
with:
asset_path: ./dist/my-artifact.zip
asset_name: my-artifact.zip
asset_content_type: application/zip

0 comments on commit 6410e49

Please sign in to comment.