-
Notifications
You must be signed in to change notification settings - Fork 1
110 lines (92 loc) · 3.79 KB
/
tsc-check.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
name: Check for New TypeScript Errors
on:
workflow_dispatch:
pull_request:
branches:
- main
- test-action
jobs:
check-tsc-errors:
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@v3
- name: Fetch target and PR branches
run: git fetch origin ${{ github.base_ref }}:${{ github.base_ref }} ${{ github.head_ref }}:${{ github.head_ref }}
- name: Extract target branch name
run: |
branch=${{ github.base_ref }}
branch=${branch//\//} # This removes all slashes from the branch name
echo "branch=${branch}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Download artifact from target branch
id: download-artifact
uses: actions/download-artifact@v2
with:
name: ${{ steps.extract_branch.outputs.branch }}-tsc-output
path: base-tsc-output
continue-on-error: true
- name: Check if artifact exists
id: check-artifact
run: |
if [ -f base-tsc-output/tsc_output.txt ]; then
echo "Artifact found."
echo "artifact-found=true" >> $GITHUB_ENV
else
echo "Artifact not found."
echo "artifact-found=false" >> $GITHUB_ENV
fi
- name: Generate base errors if artifact not found
if: env.artifact-found == 'false'
run: |
echo "Checking out base branch"
git checkout ${{ github.base_ref }}
echo "Creating output directory"
mkdir -p base-tsc-output
# Install dependencies from Yarn cache if it exists
if [ -d ~/.cache/yarn ]; then
echo "Using Yarn cache"
cp -r ~/.cache/yarn .cache
else
echo "Yarn cache not found"
yarn install
fi
echo "Running tsc"
npx tsc --noEmit --pretty false --p tsconfig.json 2> base-tsc-output/tsc_errors.txt || { echo 'tsc command failed'; cat base-tsc-output/tsc_errors.txt; exit 1; }
echo "Extracting errors"
grep -oE '^[^ ]+.ts:[0-9]+:[0-9]+' base-tsc-output/tsc_errors.txt | sort -u > base-tsc-errors.txt || { echo 'grep command failed'; exit 1; }
continue-on-error: true
- name: Extract errors from artifact if found
if: env.artifact-found == 'true'
run: |
grep -oE '^[^ ]+.ts:[0-9]+:[0-9]+' base-tsc-output/tsc_output.txt | sort -u > base-tsc-errors.txt || { echo 'grep command failed'; exit 1; }
- name: Checkout PR branch
run: git checkout ${{ github.head_ref }}
- name: Install dependencies for PR branch
uses: ./.github/actions/setup
- name: Run tsc on PR branch
run: |
npx tsc --noEmit --pretty false --p tsconfig.json > head-tsc-output.txt || { echo 'tsc command failed'; exit 1; }
- name: Extract errors from PR branch
run: |
grep -oE '^[^ ]+.ts:[0-9]+:[0-9]+' head-tsc-output.txt | sort -u > head-tsc-errors.txt || { echo 'grep command failed'; exit 1; }
- name: Check PR errors file existence
run: |
if [ ! -f head-tsc-errors.txt ]; then
echo "PR errors file not found!"
exit 1
fi
- name: Sort and compare errors
run: |
sorted_base_errors=$(sort base-tsc-errors.txt)
sorted_pr_errors=$(sort head-tsc-errors.txt)
echo "$sorted_base_errors" > sorted-base-tsc-errors.txt
echo "$sorted_pr_errors" > sorted-head-tsc-errors.txt
new_errors=$(comm -13 sorted-base-tsc-errors.txt sorted-head-tsc-errors.txt)
if [ -n "$new_errors" ]; then
echo "New TypeScript errors introduced:"
echo "$new_errors"
exit 1
else
echo "No new TypeScript errors introduced."
fi