2023-02-14 15:52:21 +01:00
name : Lower null checks
on :
pull_request :
concurrency :
group : ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress : true
jobs :
build :
runs-on : ubuntu-latest
2023-02-17 11:12:46 +01:00
env :
MAIN_BRANCH : main
2023-02-14 15:52:21 +01:00
strategy :
matrix :
node-version : [ 16. x]
steps :
- name : Checkout current branch
uses : actions/checkout@v3
with :
path : current
- name : Checkout main branch
uses : actions/checkout@v3
with :
2023-02-17 11:12:46 +01:00
ref : ${{ env.MAIN_BRANCH }}
2023-02-14 15:52:21 +01:00
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
2023-02-16 13:35:54 +01:00
- name : Compare errors if enabling strictNullChecks
2023-02-17 11:12:46 +01:00
env :
URL : ${{ github.event.pull_request.comments_url }}
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
2023-02-16 13:35:54 +01:00
run : |
2023-02-17 11:12:46 +01:00
comment () {
curl -X POST $URL \
-H "Content-Type: application/json" \
-H "Authorization: token $GITHUB_TOKEN" \
--data "{ \"body\": \"${1}\" }"
}
2023-02-16 13:35:54 +01:00
sed -i 's/\/\/\s*"strictNullChecks":\s*true,/"strictNullChecks": true,/' "current/tsconfig.json"
sed -i 's/\/\/\s*"strictNullChecks":\s*true,/"strictNullChecks": true,/' "main/tsconfig.json"
yarn --mutex network --cwd ./current 2> .stderr-current > .out-current &
2023-02-14 15:52:21 +01:00
pid1=$!
2023-02-16 13:35:54 +01:00
yarn --mutex network --cwd ./main 2> .stderr-main > .out-main &
2023-02-14 15:52:21 +01:00
pid2=$!
2023-02-16 13:35:54 +01:00
# 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/')
2023-02-14 15:52:21 +01:00
if [ $CURRENT -gt $MAIN ]; then
2023-02-27 13:06:09 +01:00
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}. <br /> Make sure your branch is up-to-date with ${MAIN_BRANCH} and **check the diff in the console output** to gather more details."
2023-02-16 13:35:54 +01:00
diff .out-current .out-main
2023-02-14 15:52:21 +01:00
exit 1
else
echo "The PR has $CURRENT null check errors against $MAIN in main. You're good to go!"
fi