diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e3cd69df..af6594e2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,26 +4,47 @@ on: push: workflow_dispatch: +env: + OFFICIAL: false + jobs: build_and_test_ubuntu: strategy: matrix: platform: [ubuntu-22.04] mg_version: - - "2.7.0" + - "2.18.0-rc1" runs-on: ${{ matrix.platform }} steps: + - name: Set up and check memgraph download link + run: | + mg_version=${{ matrix.mg_version }} + mg_version_short=${mg_version%%-*} + if [ "${{ env.OFFICIAL }}" = "true" ]; then + mg_url="https://download.memgraph.com/memgraph/v${mg_version}/${{ matrix.platform }}/memgraph_${mg_version_short}-1_amd64.deb" + else + mg_url="https://s3.eu-west-1.amazonaws.com/deps.memgraph.io/memgraph/v${mg_version}/${{ matrix.platform }}/memgraph_${mg_version_short}-1_amd64.deb" + fi + echo "Checking Memgraph download link: $mg_url" + if curl --output /dev/null --silent --head --fail $mg_url; then + echo "Memgraph download link is valid" + echo "MEMGRAPH_DOWNLOAD_LINK=${mg_url}" >> $GITHUB_ENV + else + echo "Memgraph download link is not valid" + exit 1 + fi + - name: Install dependencies (Ubuntu 22.04) if: matrix.platform == 'ubuntu-22.04' run: | sudo apt install -y git cmake make gcc g++ libssl-dev # mgconsole deps sudo apt install -y libpython3.10 python3-pip # memgraph deps mkdir ~/memgraph - curl -L https://download.memgraph.com/memgraph/v${{ matrix.mg_version }}/ubuntu-22.04/memgraph_${{ matrix.mg_version }}-1_amd64.deb > ~/memgraph/memgraph_${{ matrix.mg_version }}-1_amd64.deb + curl -L ${{ env.MEMGRAPH_DOWNLOAD_LINK }} > ~/memgraph/memgraph_${{ matrix.mg_version }}-1_amd64.deb sudo systemctl mask memgraph sudo dpkg -i ~/memgraph/memgraph_${{ matrix.mg_version }}-1_amd64.deb - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Install and test mgconsole run: | mkdir build @@ -32,8 +53,15 @@ jobs: make sudo make install ctest + - name: Save mgconsole test results + if: always() + uses: actions/upload-artifact@v4 + with: + name: "mgconsole_ctest.log" + path: build/Testing/Temporary/LastTest.log build_windows: + if: false runs-on: windows-latest steps: - uses: msys2/setup-msys2@v2 @@ -46,16 +74,17 @@ jobs: # First make sure python would resolve to the windows native python, not mingw one echo "C:/msys64/mingw64/bin" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 echo "${{ env.pythonLocation }}" | Out-File -Append -FilePath $env:GITHUB_PATH -Encoding utf8 - - uses: actions/checkout@v1 + - uses: actions/checkout@v4 - name: Install mgconsole run: | + $env:OPENSSL_ROOT_DIR = "C:/msys64/mingw64" mkdir build cd build cmake -G "MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release .. make make install - name: Save mgconsole Windows build - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: "mgconsole Windows build" path: build/src/mgconsole.exe @@ -69,7 +98,7 @@ jobs: runs-on: ${{ matrix.platform }} steps: - name: Set-up repository - uses: actions/checkout@v2 + uses: actions/checkout@v4 # NOTE: CI can't execute end2end tests because there is no way to run # Memgraph on CI MacOS machines. - name: Install openssl @@ -83,7 +112,7 @@ jobs: cmake -DOPENSSL_ROOT_DIR="$(brew --prefix openssl)" -DCMAKE_BUILD_TYPE=Release .. make - name: Save mgconsole MacOS build - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v4 with: name: "mgconsole MacOS build" path: build/src/mgconsole diff --git a/src/utils/utils.cpp b/src/utils/utils.cpp index 11fa81c2..ae6511d1 100644 --- a/src/utils/utils.cpp +++ b/src/utils/utils.cpp @@ -141,6 +141,37 @@ void PrintStringUnescaped(std::ostream &os, const mg_string *str) { os.write(mg_string_data(str), mg_string_size(str)); } +std::string GetMemgraphSpecificType(const mg_value *mg_val) { + std::string type; + if (mg_val && mg_value_get_type(mg_val) == MG_VALUE_TYPE_STRING) { + auto *type_val_mg_str = mg_value_string(mg_val); + type = std::string(mg_string_data(type_val_mg_str), mg_string_size(type_val_mg_str)); + } + return type; +} + +bool PrintIfMemgraphSpecificType(std::ostream &os, const mg_map *map) { + // Current format is + // { "__type": "", "__value": } + static const char kTypeKey[] = "__type"; + static const char kMgEnum[] = "mg_enum"; + static const char kValue[] = "__value"; + + if (mg_map_size(map) != 2) { + return false; + } + + auto memgraph_type = GetMemgraphSpecificType(mg_map_at(map, kTypeKey)); + if (memgraph_type == kMgEnum) { + auto *enum_value = mg_map_at(map, kValue); + if (mg_value_get_type(enum_value) == MG_VALUE_TYPE_STRING) { + PrintStringUnescaped(os, mg_value_string(enum_value)); + return true; + } + } + return false; +} + void PrintValue(std::ostream &os, const mg_string *str) { os << utils::Escape(std::string(mg_string_data(str), mg_string_size(str))); } @@ -157,6 +188,10 @@ void PrintValue(std::ostream &os, const mg_list *list) { } void PrintValue(std::ostream &os, const mg_map *map) { + if (PrintIfMemgraphSpecificType(os, map)) { + return; + } + os << "{"; for (uint32_t i = 0; i < mg_map_size(map); ++i) { if (i > 0) { diff --git a/tests/input_output/input/enum.txt b/tests/input_output/input/enum.txt new file mode 100644 index 00000000..745493e6 --- /dev/null +++ b/tests/input_output/input/enum.txt @@ -0,0 +1,4 @@ +SHOW ENUMS; +CREATE (n :l1 {s: Status::Good}) RETURN n; +CREATE (n :l2 {s: {__type: "test", __value: "test_value"}}) RETURN n; +MATCH (n) return n; \ No newline at end of file diff --git a/tests/input_output/output_csv/enum.txt b/tests/input_output/output_csv/enum.txt new file mode 100644 index 00000000..1fd0632f --- /dev/null +++ b/tests/input_output/output_csv/enum.txt @@ -0,0 +1,6 @@ +"Enum Name","Enum Values" +"""Status""","[""Good"", ""Bad""]" +"n" +"(:l1 {s: Status::Good})" +"n" +"(:l2 {s: {__type: ""test"", __value: ""test_value""}})" \ No newline at end of file diff --git a/tests/input_output/output_tabular/enum.txt b/tests/input_output/output_tabular/enum.txt new file mode 100644 index 00000000..ea7bfd66 --- /dev/null +++ b/tests/input_output/output_tabular/enum.txt @@ -0,0 +1,15 @@ ++-----------------+-----------------+ +| Enum Name | Enum Values | ++-----------------+-----------------+ +| "Status" | ["Good", "Bad"] | ++-----------------+-----------------+ ++-------------------------+ +| n | ++-------------------------+ +| (:l1 {s: Status::Good}) | ++-------------------------+ ++----------------------------------------------------+ +| n | ++----------------------------------------------------+ +| (:l2 {s: {__type: "test", __value: "test_value"}}) | ++----------------------------------------------------+ \ No newline at end of file diff --git a/tests/input_output/prepare.cypher b/tests/input_output/prepare.cypher new file mode 100644 index 00000000..b38f3fd2 --- /dev/null +++ b/tests/input_output/prepare.cypher @@ -0,0 +1 @@ +CREATE ENUM Status VALUES { Good, Bad }; diff --git a/tests/input_output/run-tests.sh b/tests/input_output/run-tests.sh index 951f90ef..1b44df9a 100755 --- a/tests/input_output/run-tests.sh +++ b/tests/input_output/run-tests.sh @@ -102,6 +102,13 @@ echo_success "Started memgraph" ## Tests +client_flags="--use-ssl=$use_ssl" + +echo_info "Prepare database" +echo # Blank line + +$client_binary $client_flags < ${DIR}/prepare.cypher > $tmpdir/prepare.log + echo_info "Running tests" echo # Blank line