test: hi #57
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 base 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 base tsc output artifact | |
# uses: actions/download-artifact@v2 | |
# with: | |
# name: ${{ steps.extract_branch.outputs.branch }}-tsc-output | |
# path: artifact-tsc-output.txt | |
# continue-on-error: true | |
- name: Check if base artifact exists | |
id: check_tsc_output | |
run: | | |
if [ -d artifact-tsc-output.txt ]; then | |
echo "base branch artifact found" | |
cp artifact-tsc-output.txt base-tsc-output.txt | |
echo "tsc_output_exists=true" >> $GITHUB_ENV | |
else | |
echo "base branch artifact not found" | |
echo "tsc_output_exists=false" >> $GITHUB_ENV | |
fi | |
- name: Checkout base branch | |
# if: env.tsc_output_exists == 'false' | |
run: git checkout ${{ github.base_ref }} | |
- 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: Upload base tsc output as artifact | |
# if: env.tsc_output_exists == 'false' | |
# uses: actions/upload-artifact@v2 | |
# with: | |
# name: ${{ steps.extract_branch.outputs.branch }}-tsc-output | |
# path: base-tsc-output.txt | |
- 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 output file not found!" | |
exit 1 | |
fi | |
if [ ! -f head-tsc-output.txt ]; then | |
echo "PR output file not found!" | |
exit 1 | |
fi | |
- name: Compare base errors with PR errors | |
run: | | |
diff_output=$(diff -u base-tsc-output.txt head-tsc-output.txt | grep -E '^\+' | grep -vE '^\+\+\+|^---') | |
if [ -n "$diff_output" ]; then | |
echo "New TypeScript errors introduced:" | |
echo "$diff_output" | |
exit 1 | |
else | |
echo "No new TypeScript errors introduced." | |
fi |