diff --git a/.github/scripts/checkParser.sh b/.github/scripts/checkParser.sh new file mode 100755 index 000000000000..d63f4a01452f --- /dev/null +++ b/.github/scripts/checkParser.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e + +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 "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." + exit 0 +fi diff --git a/.github/workflows/verifyParserFiles.yml b/.github/workflows/verifyParserFiles.yml new file mode 100644 index 000000000000..66fec63f40f8 --- /dev/null +++ b/.github/workflows/verifyParserFiles.yml @@ -0,0 +1,22 @@ +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: Verify parser files consistency + run: ./.github/scripts/checkParser.sh