2023-02-14 15:52:21 +01:00
name : Lower null checks
on :
2023-05-22 18:06:52 +02:00
workflow_dispatch :
2023-02-14 15:52:21 +01:00
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 :
2024-05-23 14:14:09 +02:00
node-version : [ 20. x]
2023-02-14 15:52:21 +01:00
steps :
- name : Checkout current branch
2023-10-05 10:19:57 +02:00
uses : actions/checkout@v4
2023-02-14 15:52:21 +01:00
with :
path : current
- name : Checkout main branch
2023-10-05 10:19:57 +02:00
uses : actions/checkout@v4
2023-02-14 15:52:21 +01:00
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 }}
2024-01-17 08:56:41 +01:00
uses : actions/setup-node@v4
2023-02-14 15:52:21 +01:00
with :
2024-05-23 14:14:09 +02:00
node-version : 20. x
2023-02-14 15:52:21 +01:00
cache : 'yarn'
cache-dependency-path : |
current/yarn.lock
main/yarn.lock
2024-06-27 12:52:43 +02:00
- name : Enable corepack
run : corepack enable
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-03-10 10:27:56 +01:00
YARN_1="yarn --mutex network --cwd ./current"
YARN_2="yarn --mutex network --cwd ./main"
2023-02-16 13:35:54 +01:00
2024-06-27 12:52:43 +02:00
$YARN_1 install &> /dev/null && $YARN_1 build:backend --strictNullChecks true 2> .stderr-current > .out-current &
2023-02-14 15:52:21 +01:00
pid1=$!
2024-06-27 12:52:43 +02:00
$YARN_2 install &> /dev/null && $YARN_2 build:backend --strictNullChecks true 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-03-10 10:27:56 +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 pinpoint the offending files."
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!"
2023-04-18 10:35:32 +02:00
fi