Skip to content

test 2 errors #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 57 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
29d4bd2
test 2 errors
abenhamdine Jun 23, 2021
4cc392d
churn
abenhamdine Jun 23, 2021
03cffba
Churn 2
abenhamdine Jun 23, 2021
03469b5
Churn 3
abenhamdine Jun 23, 2021
1d06f15
Churn 4
abenhamdine Jun 23, 2021
f9b00d6
Churn 5
abenhamdine Jun 24, 2021
37f0e3f
test 2 errors
abenhamdine Jun 23, 2021
a9145d7
Churn 2
abenhamdine Jun 23, 2021
93f2064
Merge branch 'main' into test-action-2
abenhamdine Jun 24, 2021
57da46c
Merge branch 'main' into test-action-2
abenhamdine Jun 24, 2021
973c8e6
Merge branch 'main' into test-action-2
abenhamdine Jun 24, 2021
588ff46
Merge branch 'main' into test-action-2
abenhamdine Jun 24, 2021
cc73bbd
Merge branch 'main' into test-action-2
abenhamdine Jun 25, 2021
7b53217
Merge branch 'main' into test-action-2
abenhamdine Jun 25, 2021
c6fa935
Merge branch 'main' into test-action-2
abenhamdine Jun 25, 2021
9567b94
Merge branch 'main' into test-action-2
abenhamdine Jun 25, 2021
9be7887
Merge branch 'main' into test-action-2
abenhamdine Jun 25, 2021
5c85677
Merge branch 'main' into test-action-2
abenhamdine Jun 28, 2021
afca176
Merge branch 'main' into test-action-2
abenhamdine Jun 28, 2021
5e25866
Merge branch 'main' into test-action-2
abenhamdine Jun 28, 2021
3aefd53
Merge branch 'main' into test-action-2
abenhamdine Jun 28, 2021
403e161
Merge branch 'main' into test-action-2
abenhamdine Jun 28, 2021
323508f
Merge branch 'main' into test-action-2
abenhamdine Jun 29, 2021
53439c8
Merge branch 'main' into test-action-2
abenhamdine Jun 29, 2021
5a8adff
Merge branch 'main' into test-action-2
abenhamdine Jul 8, 2021
77421cd
Add union type fake error
abenhamdine Jul 8, 2021
a99cc71
Update fakeErrors.ts
abenhamdine Jul 8, 2021
07fd95e
Merge branch 'main' into test-action-2
abenhamdine Jun 29, 2022
0b6254b
Merge branch 'update-all-deps' into test-action-2
abenhamdine Jun 29, 2022
bd478bd
Churn
abenhamdine Jun 29, 2022
06c5155
Remove unused interface
t3chguy Aug 24, 2022
bf9b57f
Fix log output grouping
t3chguy Aug 24, 2022
77474b0
Fix checkout and install base branch ref grabbing
t3chguy Aug 24, 2022
afe7b36
Wire up github pr annotation support
t3chguy Aug 24, 2022
d4dd78d
Update README
t3chguy Aug 24, 2022
af0120e
Merge branch 'main' into test-action-2
abenhamdine Nov 27, 2022
2eadb32
Merge branch 'main' into pr/367
abenhamdine Nov 27, 2022
9e3f74f
Add debug for args
abenhamdine Nov 27, 2022
1f79af0
Package
abenhamdine Nov 27, 2022
a7f4e3b
Merge branch 'pr/367' into test-action-2
abenhamdine Nov 27, 2022
620181e
Test annotate
abenhamdine Nov 27, 2022
d2dd58b
Revert "Test annotate"
abenhamdine Nov 27, 2022
eb61574
Test annotate
abenhamdine Nov 27, 2022
6dbab65
Parse line, column and code in ts errors as numbers
abenhamdine Nov 27, 2022
ea8d7a2
Merge branch 'improve-tsc-parsed-types' into test-action-2
abenhamdine Nov 27, 2022
badcb28
Package
abenhamdine Nov 27, 2022
a7aba54
Allow to pass args to tsc
abenhamdine Nov 27, 2022
b3859e8
Merge branch 'tsc-extra-args' into test-action-2
abenhamdine Nov 27, 2022
6e380b5
Pass extra arg to tsc
abenhamdine Nov 27, 2022
c5bb188
Revert "Merge branch 'tsc-extra-args' into test-action-2"
abenhamdine Nov 27, 2022
9b1a43c
Revert "Pass extra arg to tsc"
abenhamdine Nov 27, 2022
a38f099
Merge branch 'main' into test-action-2
abenhamdine Nov 27, 2022
cf31a19
Squashed commit of the following:
abenhamdine Apr 26, 2023
7e54f29
Merge branch 'main' into test-action-2
abenhamdine Apr 26, 2023
2d4aabe
Churn
abenhamdine Apr 26, 2023
05c30c4
Merge branch 'test-action-2' of https://github.com/Arhia/action-check…
abenhamdine Apr 26, 2023
7732870
Squashed commit of the following:
abenhamdine Apr 26, 2023
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
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ jobs:
uses: Equip-Collaboration/diff-line-numbers@v1.0.0
with:
include: '["\\.ts$"]'
node-version: '16'
- name: Print line numbers of changed lines
run: echo Line numbers = ${{ toJSON(steps.diff.outputs.lineNumbers) }}
- name: Detecting files changed
id: files
uses: futuratrepadeira/changed-files@v3.2.1
uses: umani/changed-files@v4.0.1
with:
repo-token: ${{ github.token }}
pattern: '^.*\.ts$'
Expand All @@ -34,3 +35,4 @@ jobs:
files-deleted: ${{steps.files.outputs.files_deleted}}
line-numbers: ${{steps.diff.outputs.lineNumbers}}
debug: true
output-behaviour: 'both'
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"
7 changes: 5 additions & 2 deletions src/fakeErrors.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@

let foo: string = 'EE'

//foo = 1
foo = 1

const bar = 1

//bar = 2
bar = 2

let foo2: string | number = true
// again again again
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