-
Notifications
You must be signed in to change notification settings - Fork 1
96 lines (77 loc) · 2.99 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
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 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: Checkout base branch
run: git checkout ${{ github.base_ref }}
- name: Check for tsc_output.txt in base branch
id: check_tsc_output
run: |
if git show ${GITHUB_SHA}:${{ steps.extract_branch.outputs.branch }}/tsc_output.txt >/dev/null 2>&1; then
echo "tsc_output.txt found in base branch"
cp tsc_output.txt base-tsc-errors.txt
echo "tsc_output_exists=true" >> $GITHUB_ENV
else
echo "tsc_output.txt not found in base branch"
echo "tsc_output_exists=false" >> $GITHUB_ENV
fi
- name: Install dependencies for base branch
if: env.tsc_output_exists == 'false'
uses: ./.github/actions/setup
- name: Generate base branch tsc output
if: env.tsc_output_exists == 'false'
run: |
echo "Running tsc"
npx tsc --noEmit --pretty false --p tsconfig.json 2> base-tsc-output.txt || true
- 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 || true
- name: Check both tsc outputs exist
run: |
if [ ! -f base-tsc-output.txt ]; then
echo "Base errors file not found!"
exit 1
fi
if [ ! -f head-tsc-output.txt ]; then
echo "PR errors file not found!"
exit 1
fi
- name: Print head-tsc-output.txt for debugging
run: cat head-tsc-output.txt
- name: Compare base errors with PR errors
run: |
base_errors=$(grep -oE '^[^ ]+.ts:[0-9]+:[0-9]+' base-tsc-output.txt | sort -u)
pr_errors=$(grep -oE '^[^ ]+.ts:[0-9]+:[0-9]+' head-tsc-output.txt | sort -u)
echo "Base branch TypeScript errors:"
echo "$base_errors"
echo "PR branch TypeScript errors:"
echo "$pr_errors"
new_errors=$(comm -13 <(echo "$base_errors") <(echo "$pr_errors"))
if [ -n "$new_errors" ]; then
echo "New TypeScript errors introduced:"
echo "$new_errors"
exit 1
else
echo "No new TypeScript errors introduced."
fi