From 1dc5c6071eafcfb585efbed45d78cdeadf6ac430 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Tue, 26 Nov 2019 14:47:44 +0800 Subject: [PATCH] Remove Travis and use Github Actions (#487) --- .editorconfig | 17 ++++ .github/workflows/dotnetcore.yml | 30 +++++++ .../workflows/rpc-tests.sh | 11 +-- {ci => .github/workflows}/test-neo-cli.expect | 2 +- .travis.yml | 8 -- ci/Dockerfile | 31 ------- ci/README.md | 20 ----- ci/build-and-test.sh | 28 ------ neo-cli/Shell/MainService.cs | 90 +++++++++---------- 9 files changed, 95 insertions(+), 142 deletions(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/dotnetcore.yml rename ci/run-tests-in-docker.sh => .github/workflows/rpc-tests.sh (81%) rename {ci => .github/workflows}/test-neo-cli.expect (95%) delete mode 100644 .travis.yml delete mode 100644 ci/Dockerfile delete mode 100644 ci/README.md delete mode 100755 ci/build-and-test.sh diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..5acd074d2 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +############################### +# Core EditorConfig Options # +############################### + +# dotnet-format requires version 3.1.37601 +# dotnet tool update -g dotnet-format +# remember to have: git config --global core.autocrlf false #(which is usually default) + +root = true + +# Every file + +[*] +insert_final_newline = true +trim_trailing_whitespace = true +charset = utf-8 +end_of_line = lf diff --git a/.github/workflows/dotnetcore.yml b/.github/workflows/dotnetcore.yml new file mode 100644 index 000000000..2980260d6 --- /dev/null +++ b/.github/workflows/dotnetcore.yml @@ -0,0 +1,30 @@ +name: .NET Core Test + +on: pull_request + +env: + DOTNET_VERSION: 3.0.100 + +jobs: + + Test: + runs-on: ubuntu-latest + steps: + - name: Chectout + uses: actions/checkout@v1 + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ env.DOTNET_VERSION }} + - name: Check format + run: | + dotnet tool install --tool-path ./ dotnet-format + ./dotnet-format --check --dry-run -v diagnostic + - name: Build + run: dotnet publish -o ./out -c Release + - name: Install dependencies + run: sudo apt-get install libleveldb-dev expect + - name: Run tests with expect + run: expect ./.github/workflows/test-neo-cli.expect + - name: Run RPC tests + run: ./.github/workflows/rpc-tests.sh diff --git a/ci/run-tests-in-docker.sh b/.github/workflows/rpc-tests.sh similarity index 81% rename from ci/run-tests-in-docker.sh rename to .github/workflows/rpc-tests.sh index 2d5baab9f..f468e82e3 100755 --- a/ci/run-tests-in-docker.sh +++ b/.github/workflows/rpc-tests.sh @@ -1,16 +1,9 @@ #!/bin/bash -# -# This script is run inside the Docker container and tests neo-cli -# -set -e - -cd /opt/neo-cli -# Run tests with expect -expect /opt/ci/test-neo-cli.expect +set -e # Start neo-cli in background for additional JSON-RPC tests -screen -dmS node1 bash -c "dotnet neo-cli.dll --rpc" +screen -dmS node1 bash -c "dotnet out/neo-cli.dll --rpc" # Wait a little bit sleep 3 diff --git a/ci/test-neo-cli.expect b/.github/workflows/test-neo-cli.expect similarity index 95% rename from ci/test-neo-cli.expect rename to .github/workflows/test-neo-cli.expect index dfac0ea3a..ff1f1ba88 100755 --- a/ci/test-neo-cli.expect +++ b/.github/workflows/test-neo-cli.expect @@ -5,7 +5,7 @@ set timeout 10 # Start neo-cli -spawn dotnet neo-cli.dll --rpc +spawn dotnet out/neo-cli.dll --rpc # Expect the main input prompt expect { diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 2f93a0507..000000000 --- a/.travis.yml +++ /dev/null @@ -1,8 +0,0 @@ -sudo: required - -services: - - docker - -script: - - docker build -f ci/Dockerfile -t neo-cli-ci . - - docker run neo-cli-ci /opt/ci/run-tests-in-docker.sh diff --git a/ci/Dockerfile b/ci/Dockerfile deleted file mode 100644 index 2f9dfc402..000000000 --- a/ci/Dockerfile +++ /dev/null @@ -1,31 +0,0 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:3.0 - -# Install dependencies: -RUN apt-get update && apt-get install -y \ - libleveldb-dev \ - sqlite3 \ - libsqlite3-dev \ - libunwind8-dev \ - wget \ - expect \ - screen \ - zip - -# APT cleanup to reduce image size -RUN rm -rf /var/lib/apt/lists/* - -WORKDIR /opt - -# Get code to test -ADD neo-cli /opt/neo-cli-github -ADD ci /opt/ci -COPY NuGet.Config /opt - -WORKDIR /opt/neo-cli-github - -# Build the project -RUN dotnet restore -RUN dotnet publish -c Release -RUN mv bin/Release/netcoreapp3.0/publish /opt/neo-cli - -WORKDIR /opt diff --git a/ci/README.md b/ci/README.md deleted file mode 100644 index a8d48230f..000000000 --- a/ci/README.md +++ /dev/null @@ -1,20 +0,0 @@ -### Test & Continuous Integration Setup - -The test suite can be run manually, and is automatically run by [Travis CI](https://travis-ci.org/neo-project/neo-cli) on each code push. - -To run the tests manually, you need to install [Docker CE](https://www.docker.com/community-edition#/download), and run the test script from a bash compatible shell (eg. Git bash on Windows) like this: - - ./ci/build-and-test.sh - -The test suite performs the following tasks: - -* Build the latest code -* Verify the basic neo-cli functionality using [expect](https://linux.die.net/man/1/expect) -* Verify JSON-RPC functionality with curl - -Files: - -* `Dockerfile`: the system to build neo-cli and to run the tests -* `build-and-test.sh`: this builds the Docker image, starts it and runs the tests inside. This is useful for testing the CI run on a local dev machine. -* `run-tests-in-docker.sh`: is run inside the Docker container and executes the tests -* `test-neo-cli.expect`: [expect](https://linux.die.net/man/1/expect) script which verifies neo-cli functionality diff --git a/ci/build-and-test.sh b/ci/build-and-test.sh deleted file mode 100755 index ddfc3f453..000000000 --- a/ci/build-and-test.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/bash -# -# This script builds neo-cli with dotnet 2.0, and runs the tests. -# -CONTAINER_NAME="neo-cli-ci" - -# Get absolute path of code and ci folder. This allows to run this script from -# anywhere, whether from inside this directory or outside. -DIR_CI="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -DIR_BASE="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && cd .. && pwd )" -# echo "CI directory: $DIR_CI" -# echo "Base directory: $DIR_BASE" - -# Build the Docker image (includes building the current neo-cli code) -# docker build --no-cache -f $DIR_CI/Dockerfile -t $CONTAINER_NAME $DIR_BASE -docker build -f $DIR_CI/Dockerfile -t $CONTAINER_NAME $DIR_BASE - -# Stop already running containers -CONTAINER=$(docker ps -aqf name=$CONTAINER_NAME) -if [ -n "$CONTAINER" ]; then - echo "Stopping container named $CONTAINER_NAME" - docker stop $CONTAINER_NAME 1>/dev/null - echo "Removing container named $CONTAINER_NAME" - docker rm -f $CONTAINER_NAME 1>/dev/null -fi - -# Start a new test container -docker run --name $CONTAINER_NAME $CONTAINER_NAME /opt/ci/run-tests-in-docker.sh diff --git a/neo-cli/Shell/MainService.cs b/neo-cli/Shell/MainService.cs index 7a370c984..51f2964bf 100644 --- a/neo-cli/Shell/MainService.cs +++ b/neo-cli/Shell/MainService.cs @@ -140,9 +140,9 @@ private bool OnBroadcastCommand(string[] args) private bool OnDeployCommand(string[] args) { if (NoWallet()) return true; - byte[] script = LoadDeploymentScript( - /* filePath */ args[1], - /* manifest */ args.Length == 2 ? "" : args[2], + byte[] script = LoadDeploymentScript( + /* filePath */ args[1], + /* manifest */ args.Length == 2 ? "" : args[2], /* scriptHash */ out var scriptHash); Transaction tx; @@ -220,9 +220,9 @@ private bool OnInvokeCommand(string[] args) private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, out UInt160 scriptHash) { - if (string.IsNullOrEmpty(manifestFilePath)) - { - manifestFilePath = Path.ChangeExtension(nefFilePath, ".manifest.json"); + if (string.IsNullOrEmpty(manifestFilePath)) + { + manifestFilePath = Path.ChangeExtension(nefFilePath, ".manifest.json"); } // Read manifest @@ -251,41 +251,41 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath, // Basic script checks - using (var engine = new ApplicationEngine(TriggerType.Application, null, null, 0, true)) - { - var context = engine.LoadScript(file.Script); - - while (context.InstructionPointer <= context.Script.Length) - { - // Check bad opcodes - - var ci = context.CurrentInstruction; - - if (ci == null || !Enum.IsDefined(typeof(OpCode), ci.OpCode)) - { - throw new FormatException($"OpCode not found at {context.InstructionPointer}-{((byte)ci.OpCode).ToString("x2")}"); - } - - switch (ci.OpCode) - { - case OpCode.SYSCALL: - { - // Check bad syscalls (NEO2) - - if (!InteropService.SupportedMethods().ContainsKey(ci.TokenU32)) - { - throw new FormatException($"Syscall not found {ci.TokenU32.ToString("x2")}. Are you using a NEO2 smartContract?"); - } - break; - } - } - - context.InstructionPointer += ci.Size; - } - } - - // Build script - + using (var engine = new ApplicationEngine(TriggerType.Application, null, null, 0, true)) + { + var context = engine.LoadScript(file.Script); + + while (context.InstructionPointer <= context.Script.Length) + { + // Check bad opcodes + + var ci = context.CurrentInstruction; + + if (ci == null || !Enum.IsDefined(typeof(OpCode), ci.OpCode)) + { + throw new FormatException($"OpCode not found at {context.InstructionPointer}-{((byte)ci.OpCode).ToString("x2")}"); + } + + switch (ci.OpCode) + { + case OpCode.SYSCALL: + { + // Check bad syscalls (NEO2) + + if (!InteropService.SupportedMethods().ContainsKey(ci.TokenU32)) + { + throw new FormatException($"Syscall not found {ci.TokenU32.ToString("x2")}. Are you using a NEO2 smartContract?"); + } + break; + } + } + + context.InstructionPointer += ci.Size; + } + } + + // Build script + scriptHash = file.ScriptHash; using (ScriptBuilder sb = new ScriptBuilder()) { @@ -1071,10 +1071,10 @@ private bool OnShowStateCommand(string[] args) maxLines = Math.Max(maxLines, linesWritten); - while (linesWritten < maxLines) - { - WriteLineWithoutFlicker("", Console.WindowWidth - 1); - maxLines--; + while (linesWritten < maxLines) + { + WriteLineWithoutFlicker("", Console.WindowWidth - 1); + maxLines--; } await Task.Delay(500, cancel.Token);