Skip to content

Commit

Permalink
Refactor actions
Browse files Browse the repository at this point in the history
  • Loading branch information
thomashdoughty committed Nov 21, 2019
1 parent 8b83f86 commit da14ab3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 40 deletions.
37 changes: 33 additions & 4 deletions .github/actions/upload_release_artifact/index.js
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 .github/actions/upload_release_artifact/upload-artifact.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Deploy Release
name: Release

on:
release:
Expand Down Expand Up @@ -31,7 +31,7 @@ jobs:
uses: crazy-max/ghaction-github-pages@v1
with:
target_branch: gh-pages
build_dir: out
build_dir: .dist/docs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down

0 comments on commit da14ab3

Please sign in to comment.