From 9f56c47ae4b4d66d2c2bfc5d2c013457346aa27a Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Wed, 29 Jan 2025 15:05:53 +0100 Subject: [PATCH 1/5] adding GitHub actions and working script --- .github/scripts/checkParser.sh | 26 +++++++++++++++++++++++++ .github/workflows/verifyParserFiles.yml | 25 ++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100755 .github/scripts/checkParser.sh create mode 100644 .github/workflows/verifyParserFiles.yml diff --git a/.github/scripts/checkParser.sh b/.github/scripts/checkParser.sh new file mode 100755 index 000000000000..9f71a0716de4 --- /dev/null +++ b/.github/scripts/checkParser.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +START_DIR=$(pwd) +ROOT_DIR=$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")") +cd "$ROOT_DIR" || exit 1 + +autocomplete_parser_backup="src/libs/SearchParser/autocompleteParser.js.bak" +search_parser_backup="src/libs/SearchParser/searchParser.js.bak" + +cp src/libs/SearchParser/autocompleteParser.js "$autocomplete_parser_backup" 2>/dev/null +cp src/libs/SearchParser/searchParser.js "$search_parser_backup" 2>/dev/null + +npm run generate-search-parser +npm run generate-autocomplete-parser + + +if ! diff -q "$autocomplete_parser_backup" src/libs/SearchParser/autocompleteParser.js >/dev/null || + ! diff -q "$search_parser_backup" src/libs/SearchParser/searchParser.js >/dev/null; then + echo "The files generated from the .peggy files using the commands: generate-search-parser and generate-autocomplete-parser are not identical to those currently on this branch." + exit 1 +else + echo "The files generated from the .peggy files using the commands: generate-search-parser and generate-autocomplete-parser are identical to those currently on this branch." + exit 0 +fi diff --git a/.github/workflows/verifyParserFiles.yml b/.github/workflows/verifyParserFiles.yml new file mode 100644 index 000000000000..4ab40ef153d7 --- /dev/null +++ b/.github/workflows/verifyParserFiles.yml @@ -0,0 +1,25 @@ +name: Check consistency of search parser files + +on: + pull_request: + types: [opened, synchronize] + branches-ignore: [staging, production] + paths: + - "src/libs/SearchParser/**" + +jobs: + verify: + if: github.actor != 'OSBotify' && github.actor != 'imgbot[bot]' + runs-on: macos-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node + uses: ./.github/actions/composite/setupNode + + - name: Check file format + run: file .github/scripts/checkParser.sh + + - name: Checking consistency + run: ./.github/scripts/checkParser.sh From 07c33487b2bfdf342d746ba8a367f8c5cb912d5f Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Wed, 29 Jan 2025 15:08:32 +0100 Subject: [PATCH 2/5] adding GitHub actions and working script --- .github/workflows/verifyParserFiles.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.github/workflows/verifyParserFiles.yml b/.github/workflows/verifyParserFiles.yml index 4ab40ef153d7..a3e1f5c9ac2c 100644 --- a/.github/workflows/verifyParserFiles.yml +++ b/.github/workflows/verifyParserFiles.yml @@ -18,8 +18,5 @@ jobs: - name: Setup Node uses: ./.github/actions/composite/setupNode - - name: Check file format - run: file .github/scripts/checkParser.sh - - name: Checking consistency run: ./.github/scripts/checkParser.sh From 10465955c551bc841b0bb99600a4d7605625cc31 Mon Sep 17 00:00:00 2001 From: sumo_slonik Date: Wed, 29 Jan 2025 15:35:53 +0100 Subject: [PATCH 3/5] adding comments to script --- .github/scripts/checkParser.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/scripts/checkParser.sh b/.github/scripts/checkParser.sh index 9f71a0716de4..18ea8822b6f9 100755 --- a/.github/scripts/checkParser.sh +++ b/.github/scripts/checkParser.sh @@ -2,23 +2,25 @@ set -e -START_DIR=$(pwd) ROOT_DIR=$(dirname "$(dirname "$(dirname "${BASH_SOURCE[0]}")")") cd "$ROOT_DIR" || exit 1 autocomplete_parser_backup="src/libs/SearchParser/autocompleteParser.js.bak" search_parser_backup="src/libs/SearchParser/searchParser.js.bak" +#Copying the current .js parser files cp src/libs/SearchParser/autocompleteParser.js "$autocomplete_parser_backup" 2>/dev/null cp src/libs/SearchParser/searchParser.js "$search_parser_backup" 2>/dev/null +#Running the scripts that generate the .js parser files npm run generate-search-parser npm run generate-autocomplete-parser - +#Checking if the saved files differ from the newly generated if ! diff -q "$autocomplete_parser_backup" src/libs/SearchParser/autocompleteParser.js >/dev/null || ! diff -q "$search_parser_backup" src/libs/SearchParser/searchParser.js >/dev/null; then echo "The files generated from the .peggy files using the commands: generate-search-parser and generate-autocomplete-parser are not identical to those currently on this branch." + echo "If it didn’t work, make sure you’ve run locally: npm run generate-search-parser and npm run generate-autocomplete-parser, and committed those changes." exit 1 else echo "The files generated from the .peggy files using the commands: generate-search-parser and generate-autocomplete-parser are identical to those currently on this branch." From fce23f49f3949ebcb9b2ec53bf47af74bbe768b6 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski <61011609+sumo-slonik@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:01:45 +0100 Subject: [PATCH 4/5] Update .github/scripts/checkParser.sh Co-authored-by: Mateusz Titz --- .github/scripts/checkParser.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/scripts/checkParser.sh b/.github/scripts/checkParser.sh index 18ea8822b6f9..d63f4a01452f 100755 --- a/.github/scripts/checkParser.sh +++ b/.github/scripts/checkParser.sh @@ -20,7 +20,7 @@ npm run generate-autocomplete-parser if ! diff -q "$autocomplete_parser_backup" src/libs/SearchParser/autocompleteParser.js >/dev/null || ! diff -q "$search_parser_backup" src/libs/SearchParser/searchParser.js >/dev/null; then echo "The files generated from the .peggy files using the commands: generate-search-parser and generate-autocomplete-parser are not identical to those currently on this branch." - echo "If it didn’t work, make sure you’ve run locally: npm run generate-search-parser and npm run generate-autocomplete-parser, and committed those changes." + echo "The parser .js files should never be edited manually. Make sure you’ve run locally: npm run generate-search-parser and npm run generate-autocomplete-parser, and committed the changes." exit 1 else echo "The files generated from the .peggy files using the commands: generate-search-parser and generate-autocomplete-parser are identical to those currently on this branch." From 9a63ffa81bba977cefd836d31e1db8026c6a0485 Mon Sep 17 00:00:00 2001 From: Jakub Nowakowski <61011609+sumo-slonik@users.noreply.github.com> Date: Thu, 30 Jan 2025 17:01:55 +0100 Subject: [PATCH 5/5] Update .github/workflows/verifyParserFiles.yml Co-authored-by: Mateusz Titz --- .github/workflows/verifyParserFiles.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verifyParserFiles.yml b/.github/workflows/verifyParserFiles.yml index a3e1f5c9ac2c..66fec63f40f8 100644 --- a/.github/workflows/verifyParserFiles.yml +++ b/.github/workflows/verifyParserFiles.yml @@ -18,5 +18,5 @@ jobs: - name: Setup Node uses: ./.github/actions/composite/setupNode - - name: Checking consistency + - name: Verify parser files consistency run: ./.github/scripts/checkParser.sh