Test action #34
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: Download TSC Output from Cache | |
uses: actions/cache@v2 | |
id: download-cache | |
with: | |
path: tsc_output.txt | |
key: ${{ steps.extract_branch.outputs.branch }}-tsc-output | |
- name: Check if cache exists | |
id: cache-check | |
run: | | |
if [ -f tsc_output.txt ]; then | |
echo "Cache found." | |
cp tsc_output.txt base-tsc-errors.txt | |
echo "cache-found=true" >> $GITHUB_ENV | |
else | |
echo "Cache not found." | |
echo "cache-found=false" >> $GITHUB_ENV | |
fi | |
- name: Checkout base branch | |
if: env.cache-found == 'false' | |
run: git checkout ${{ github.base_ref }} | |
- name: Install dependencies for base branch | |
if: env.cache-found == 'false' | |
uses: ./.github/actions/setup | |
- name: Generate base branch tsc errors | |
if: env.cache-found == 'false' | |
run: | | |
echo "Running tsc" | |
npx tsc --noEmit --pretty false --p tsconfig.json 2> base-tsc-errors.txt || true | |
echo "Extracting errors" | |
grep -oE '^[^ ]+.ts:[0-9]+:[0-9]+' base-tsc-errors.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: Compare errors with cached output | |
run: | | |
cached_errors=$(cat base-tsc-errors.txt | sort -u) | |
pr_errors=$(cat head-tsc-errors.txt | sort -u) | |
new_errors=$(comm -13 <(echo "$cached_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 |