Skip to content

Commit

Permalink
Fix read file
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonEtco committed May 14, 2020
1 parent dcd482e commit 3f8a77d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "build-and-tag-action",
"private": true,
"main": "src/index.ts",
"main": "dist/index.js",
"scripts": {
"start": "npx ncc run ./src/index.ts",
"build": "npx ncc build ./src/index.ts",
Expand Down
17 changes: 11 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@ import path from 'path'
import { Toolkit } from 'actions-toolkit'
import semver from 'semver'

async function readFile (tools: Toolkit, file: string) {
const pathToFile = path.join(tools.workspace, file)
if (!fs.existsSync(file)) {
throw new Error(`${file} does not exist.`)
}

return fs.promises.readFile(pathToFile, 'utf8')
}

Toolkit.run(async tools => {
const { main } = tools.getPackageJSON()

const [actionYaml, code] = await Promise.all(['action.yml', main].map(name =>
fs.promises.readFile(path.join(tools.workspace, name), 'utf8')
))

tools.log.info('Creating tree')
const tree = await tools.github.git.createTree({
...tools.context.repo,
Expand All @@ -18,14 +23,14 @@ Toolkit.run(async tools => {
path: 'action.yml',
mode: '100644',
type: 'blob',
content: actionYaml,
content: await readFile(tools, 'action.yml'),
sha: tools.context.sha
},
{
path: main,
mode: '100644',
type: 'blob',
content: code,
content: await readFile(tools, main),
sha: tools.context.sha
}
]
Expand Down

0 comments on commit 3f8a77d

Please sign in to comment.