File tree Expand file tree Collapse file tree 5 files changed +72
-28
lines changed Expand file tree Collapse file tree 5 files changed +72
-28
lines changed Original file line number Diff line number Diff line change
1
+ import * as core from '@actions/core'
2
+ import { run } from './run'
3
+ ; ( async ( ) : Promise < void > => {
4
+ try {
5
+ await run ( )
6
+ } catch ( err ) {
7
+ core . setFailed ( `Action failed with "${ err . message } "` )
8
+ }
9
+ } ) ( )
Original file line number Diff line number Diff line change
1
+ import * as core from '@actions/core'
2
+
3
+ export interface Inputs {
4
+ readonly GithubToken : string
5
+ readonly GistID : string
6
+ readonly GistFileName ?: string
7
+ readonly FilePath : string
8
+ }
9
+
10
+ export const showInputs = ( inp : Inputs ) : void => {
11
+ core . info ( `\
12
+ [INFO] GistID: ${ inp . GistID }
13
+ [INFO] GistFileName: ${ inp . GistFileName ? inp . GistFileName : 'No Change' }
14
+ [INFO] FilePath: ${ inp . FilePath }
15
+ ` )
16
+ }
17
+
18
+ export const getInputs = ( ) : Inputs => {
19
+ const inp : Inputs = {
20
+ GithubToken : core . getInput ( 'github_token' ) ,
21
+ GistID : core . getInput ( 'gist_id' ) ,
22
+ GistFileName : core . getInput ( 'gist_file_name' ) ,
23
+ FilePath : core . getInput ( 'file_path' )
24
+ }
25
+
26
+ return inp
27
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ import fs from 'fs'
2
+ import path from 'path'
3
+ import * as core from '@actions/core'
4
+ import * as github from '@actions/github'
5
+ import { showInputs , getInputs } from './inputs'
6
+
7
+ export const run = async ( ) : Promise < void > => {
8
+ try {
9
+ const inp = getInputs ( )
10
+ showInputs ( inp )
11
+
12
+ core . startGroup ( 'Read file content' )
13
+ const workSpace = process . env . GITHUB_WORKSPACE as string
14
+ const filePath = path . join ( workSpace , inp . FilePath )
15
+ const fileContent = fs . readFileSync ( filePath ) . toString ( )
16
+ core . endGroup ( )
17
+
18
+ core . startGroup ( 'Deploy to gist' )
19
+ const octokit = github . getOctokit ( inp . GithubToken )
20
+ const fileName = inp . GistFileName ? inp . GistFileName : path . basename ( filePath )
21
+ octokit . gists . update ( {
22
+ gist_id : inp . GistID ,
23
+ files : {
24
+ [ fileName ] : {
25
+ filename : fileName ,
26
+ content : fileContent
27
+ }
28
+ }
29
+ } )
30
+ core . endGroup ( )
31
+
32
+ core . info ( '[INFO] Action successfully completed' )
33
+ } catch ( err ) {
34
+ throw new Error ( err . message )
35
+ }
36
+ }
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments