Skip to content

Commit

Permalink
feat: deploy
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed Jul 15, 2024
1 parent d72ead1 commit b69f8de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 179 deletions.
60 changes: 4 additions & 56 deletions dist/post_run/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

60 changes: 4 additions & 56 deletions dist/run/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 5 additions & 67 deletions src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,27 +162,15 @@ const printOutput = (res: ExecRes): void => {
}
}

async function runLint(lintPath: string, patchPath: string): Promise<void> {
async function runLint(lintPath: string): Promise<void> {
const debug = core.getInput(`debug`)
if (debug.split(`,`).includes(`cache`)) {
const res = await execShellCommand(`${lintPath} cache status`)
printOutput(res)
}

let userArgs = core.getInput(`args`)
const addedArgs: string[] = []

const userArgsList = userArgs
.trim()
.split(/\s+/)
.filter((arg) => arg.startsWith(`-`))
.map((arg) => arg.replace(/^-+/, ``))
.map((arg) => arg.split(/=(.*)/, 2))
.map<[string, string]>(([key, value]) => [key.toLowerCase(), value ?? ""])

const userArgsMap = new Map<string, string>(userArgsList)
const userArgNames = new Set<string>(userArgsList.map(([key]) => key))

const problemMatchers = core.getBooleanInput(`problem-matchers`)

if (problemMatchers) {
Expand All @@ -194,68 +182,18 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {
}
}

const formats = (userArgsMap.get("out-format") || "")
.trim()
.split(",")
.filter((f) => f.length > 0)
.filter((f) => !f.startsWith(`github-actions`)) // Removes `github-actions` format.
.join(",")

if (formats) {
// Adds formats but without `github-actions` format.
addedArgs.push(`--out-format=${formats}`)
}

// Removes `--out-format` from the user flags because it's already inside `addedArgs`.
userArgs = userArgs.replace(/--out-format=\S*/gi, "").trim()

if (isOnlyNewIssues()) {
if (userArgNames.has(`new`) || userArgNames.has(`new-from-rev`) || userArgNames.has(`new-from-patch`)) {
throw new Error(`please, don't specify manually --new* args when requesting only new issues`)
}

const ctx = github.context

core.info(`only new issues on ${ctx.eventName}: ${patchPath}`)

switch (ctx.eventName) {
case `pull_request`:
case `pull_request_target`:
case `push`:
if (patchPath) {
addedArgs.push(`--new-from-patch=${patchPath}`)

// Override config values.
addedArgs.push(`--new=false`)
addedArgs.push(`--new-from-rev=`)
}
break
case `merge_group`:
addedArgs.push(`--new-from-rev=${ctx.payload.merge_group.base_sha}`)

// Override config values.
addedArgs.push(`--new=false`)
addedArgs.push(`--new-from-patch=`)
break
default:
break
}
}

const cmdArgs: ExecOptions = {}

const workingDirectory = core.getInput(`working-directory`)
if (workingDirectory) {
if (!fs.existsSync(workingDirectory) || !fs.lstatSync(workingDirectory).isDirectory()) {
throw new Error(`working-directory (${workingDirectory}) was not a path`)
}
if (!userArgNames.has(`path-prefix`)) {
addedArgs.push(`--path-prefix=${workingDirectory}`)
}

cmdArgs.cwd = path.resolve(workingDirectory)
}

const cmd = `${lintPath} lint ${addedArgs.join(` `)} ${userArgs}`.trimEnd()
const cmd = `${lintPath} lint ${addedArgs.join(` `)}`.trimEnd()

core.info(`Running [${cmd}] in [${cmdArgs.cwd || process.cwd()}] ...`)

Expand All @@ -281,9 +219,9 @@ async function runLint(lintPath: string, patchPath: string): Promise<void> {

export async function run(): Promise<void> {
try {
const { lintPath, patchPath } = await core.group(`prepare environment`, prepareEnv)
const { lintPath } = await core.group(`prepare environment`, prepareEnv)
core.addPath(path.dirname(lintPath))
await core.group(`run gnoci-lint`, () => runLint(lintPath, patchPath))
await core.group(`run gnoci-lint`, () => runLint(lintPath))
} catch (error) {
core.error(`Failed to run: ${error}, ${error.stack}`)
core.setFailed(error.message)
Expand Down

0 comments on commit b69f8de

Please sign in to comment.