Skip to content

Commit 15a2ce2

Browse files
committed
feat: Initial commit
1 parent 36c0241 commit 15a2ce2

File tree

5 files changed

+72
-28
lines changed

5 files changed

+72
-28
lines changed

src/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
})()

src/inputs.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
}

src/main.ts

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/run.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

src/wait.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)