name: Lower null checks on: pull_request: workflow_dispatch: concurrency: group: ${{ github.workflow }}-${{ github.ref }} cancel-in-progress: true jobs: build: runs-on: ubuntu-latest env: MAIN_BRANCH: main strategy: matrix: node-version: [18.x] steps: - name: Checkout current branch uses: actions/checkout@v3 with: path: current - name: Checkout main branch uses: actions/checkout@v3 with: ref: ${{ env.MAIN_BRANCH }} path: main - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v3 with: node-version: ${{ matrix.node-version }} cache: 'yarn' cache-dependency-path: | current/yarn.lock main/yarn.lock - name: Compare errors if enabling strictNullChecks env: URL: ${{ github.event.pull_request.comments_url }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | find_comment() { curl -L \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN"\ -H "X-GitHub-Api-Version: 2022-11-28" \ $URL/comments } comment () { if [ -z $URL ]; then echo "Comment URL is not set" exit 0 fi curl -X POST $URL \ -H "Accept: application/vnd.github+json" \ -H "Authorization: Bearer $GITHUB_TOKEN" \ --data "{ \"body\": \"${1}\" }" } echo "${{ toJSON(github.event) }}" set -x YARN_1="yarn --mutex network --cwd ./current" YARN_2="yarn --mutex network --cwd ./main" $YARN_1 install --ignore-scripts &> /dev/null && $YARN_1 build:backend --strictNullChecks true 2> .stderr-current > .out-current & pid1=$! $YARN_2 install --ignore-scripts &> /dev/null && $YARN_2 build:backend --strictNullChecks true 2> .stderr-main > .out-main & pid2=$! # wait for the processes that are expected to fail set +e wait $pid1 wait $pid2 set -e CURRENT=$(grep "Found [0-9]* errors" .out-current | sed 's/Found \(.*\) errors in .* files./\1/') MAIN=$(grep "Found [0-9]* errors" .out-main | sed 's/Found \(.*\) errors in .* files./\1/') if [ $CURRENT -gt $MAIN ] || [ $MAIN -gt 5000 ]; then comment "After enabling [\`strictNullChecks\`](https://www.typescriptlang.org/tsconfig#strictNullChecks) this PR would be **increasing** the number of null check errors from ${MAIN} to ${CURRENT}.
Make sure your branch is up-to-date with ${MAIN_BRANCH} and **check the diff in the console output** to pinpoint the offending files." cat .out-current | sed 's/^/[out-current] /' cat .out-main | sed 's/^/[out-main] /' diff .out-current .out-main | sed 's/^/[diff] /' exit 1 else echo "The PR has $CURRENT null check errors against $MAIN in main. You're good to go!" fi