Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ jobs:
files-deleted: ${{steps.files.outputs.files_deleted}}
line-numbers: ${{steps.diff.outputs.lineNumbers}}
output-behaviour: both
comment-behaviour: new
```
## Customize the check

Expand Down Expand Up @@ -83,6 +84,13 @@ Value|Behaviour
`annotate` | Uses github line annotations with the errors found for this run.
`both` | Does both of the above.

The comment behaviour depends on the value of `comment-behaviour`

Value|Behaviour
-- | --
`new` | Default, adds a new comment for every run of the action.
`edit` | Updates a previous run's comment, if one exists, otherwise creates a new comment.

## Use a specific tsconfig file

By default, this actions uses tsconfig file located at './tsconfig.json'
Expand Down
27 changes: 15 additions & 12 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
name: 'Action Check Typescript errors'
description: 'Check tsc errors and compare errors wih base branch'
author: 'Arhia'
name: "Action Check Typescript errors"
description: "Check tsc errors and compare errors wih base branch"
author: "Arhia"
icon: box
inputs:
repo-token:
description: 'Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}'
description: "Token for the repository. Can be passed in using {{ secrets.GITHUB_TOKEN }}"
required: true
directory:
description: "Directory where to run install and build. Default is '.'"
default: '.'
default: "."
files-changed:
description: "List of files changed in the current PR (separated by space), use action 'futuratrepadeira/changed-files' for that"
default: ''
default: ""
files-added:
description: "List of files added in the current PR (separated by space), use action 'futuratrepadeira/changed-files' for that"
default: ''
default: ""
files-deleted:
description: "List of files deleted in the current PR (separated by space), use action 'futuratrepadeira/changed-files' for that"
default: ''
default: ""
line-numbers:
description: "List of files with added and removed lines, use action 'Equip-Collaboration/diff-line-numbers' for that"
ts-config-path:
description: "Path of tsconfig file. default is './tsconfig.json'"
default: './tsconfig.json'
default: "./tsconfig.json"
use-check:
description: 'Report status as a CI Check'
description: "Report status as a CI Check"
check-fail-mode:
description: "Allowed values : added, errors_in_pr, errors_in_code"
required: true
output-behaviour:
description: "Allowed values : comment, annotate, both"
default: "comment"
comment-behaviour:
description: "Allowed values : new, edit"
default: "new"
debug:
description: "Set true to log ts errors in base branch and pr branch"
default: false
runs:
using: 'node16'
main: 'dist/index.js'
using: "node16"
main: "dist/index.js"
14 changes: 14 additions & 0 deletions src/getAndValidateArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ export const enum OUTPUT_BEHAVIOUR {
COMMENT_AND_ANNOTATE = 'both'
}

export const enum COMMENT_BEHAVIOUR {
NEW = 'new',
EDIT = 'edit'
}

type Args = {
repoToken: string
directory: string
Expand Down Expand Up @@ -47,6 +52,7 @@ type Args = {
useCheck: boolean
checkFailMode: CHECK_FAIL_MODE
outputBehaviour: OUTPUT_BEHAVIOUR
commentBehaviour: COMMENT_BEHAVIOUR
debug: boolean
}

Expand All @@ -62,6 +68,7 @@ export function getAndValidateArgs(): Args {
useCheck: getBooleanInput('use-check'),
checkFailMode: getInput('check-fail-mode', { required: true }) as CHECK_FAIL_MODE,
outputBehaviour: getInput('output-behaviour') as OUTPUT_BEHAVIOUR,
commentBehaviour: getInput('comment-behaviour') as COMMENT_BEHAVIOUR,
debug: getBooleanInput('debug')
}

Expand All @@ -81,5 +88,12 @@ export function getAndValidateArgs(): Args {
throw new Error(`Invalid value ${args.outputBehaviour} for input output-behaviour`)
}

if (![
COMMENT_BEHAVIOUR.NEW,
COMMENT_BEHAVIOUR.EDIT,
].includes(args.commentBehaviour)) {
throw new Error(`Invalid value ${args.commentBehaviour} for input comment-behaviour`)
}

return args
}
3 changes: 2 additions & 1 deletion src/getBodyComment.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ErrorTs } from "./main"

const BLANK_LINE = ' \n'
export const COMMENT_TITLE = '## Typescript errors check'

type Input = {
errorsInProjectBefore: ErrorTs[]
Expand All @@ -13,7 +14,7 @@ type Input = {
export function getBodyComment({ errorsInProjectBefore, errorsInProjectAfter, errorsInModifiedFiles, newErrorsInProject }: Input): string {

const delta = errorsInProjectAfter.length - errorsInProjectBefore.length
let s = `## Typescript errors check \n`
let s = `${COMMENT_TITLE} \n`

const areStillErrors = !!errorsInProjectAfter.length

Expand Down
20 changes: 16 additions & 4 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import { createCheck } from './createCheck'
import * as github from '@actions/github'
import * as fs from 'fs'
import { parseTsConfigFile } from './tscHelpers/parseTsConfigFileToCompilerOptions'
import { getAndValidateArgs, CHECK_FAIL_MODE, OUTPUT_BEHAVIOUR } from './getAndValidateArgs'
import { getAndValidateArgs, CHECK_FAIL_MODE, OUTPUT_BEHAVIOUR, COMMENT_BEHAVIOUR } from './getAndValidateArgs'
import { exec } from '@actions/exec'
import { getBodyComment } from './getBodyComment'
import { COMMENT_TITLE, getBodyComment } from './getBodyComment'
import { checkoutAndInstallBaseBranch } from './checkoutAndInstallBaseBranch'
import { compareErrors } from './compareErrors'
import { runTscCli } from './tscHelpers/runTscCli'
Expand Down Expand Up @@ -174,9 +174,11 @@ async function run(): Promise<void> {
if ([OUTPUT_BEHAVIOUR.COMMENT, OUTPUT_BEHAVIOUR.COMMENT_AND_ANNOTATE].includes(args.outputBehaviour)) {
startGroup(`Creating comment`)

const issueNumber = context.payload.pull_request!.number

const commentInfo = {
...context.repo,
issue_number: context.payload.pull_request!.number
issue_number: issueNumber
}

const comment = {
Expand All @@ -192,7 +194,17 @@ async function run(): Promise<void> {
info(`comment body obtained`)

try {
await octokit.rest.issues.createComment(comment)
const existingComments = await octokit.rest.issues.listComments({owner: context.repo.owner, repo: context.repo.repo, issue_number: issueNumber})
const existingComment = existingComments.data.find(c => !!c.body?.includes(COMMENT_TITLE))

if (args.commentBehaviour === COMMENT_BEHAVIOUR.EDIT && existingComment) {
await octokit.rest.issues.updateComment({
comment_id: existingComment.id,
...comment
})
} else {
await octokit.rest.issues.createComment(comment)
}
} catch (e) {
info(`Error creating comment: ${(e as Error).message}`)
info(`Submitting a PR review comment instead...`)
Expand Down