From 1e5f2fc2b63fbcad6430c21defc0e22659057c34 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 15 Jul 2020 13:22:15 -0400 Subject: [PATCH] Switch to GitHub actions for building --- .codecov.yml | 2 - .editorconfig | 16 +- .github/workflows/suite.yml | 232 ++++++++++++++++++ .travis.yml | 128 +--------- build/install_byond.sh | 21 -- build/integration_test.sh | 20 -- tests/DMAPI/BasicOperation/build_byond.sh | 19 -- .../Tgstation.Server.Api.Tests.csproj | 4 + .../Tgstation.Server.Client.Tests.csproj | 4 + ...Tgstation.Server.Host.Console.Tests.csproj | 4 + ...Tgstation.Server.Host.Service.Tests.csproj | 4 + .../Tgstation.Server.Host.Tests.csproj | 4 + ...gstation.Server.Host.Watchdog.Tests.csproj | 4 + 13 files changed, 270 insertions(+), 192 deletions(-) create mode 100644 .github/workflows/suite.yml delete mode 100755 build/install_byond.sh delete mode 100755 build/integration_test.sh delete mode 100755 tests/DMAPI/BasicOperation/build_byond.sh diff --git a/.codecov.yml b/.codecov.yml index 981fbc42cd..0c6bd3659f 100644 --- a/.codecov.yml +++ b/.codecov.yml @@ -1,5 +1,3 @@ -codecov: - strict_yaml_branch: dev ignore: - "src/Tgstation.Server.Host/Database/Migrations" - "src/Tgstation.Server.Host/Database/Design" diff --git a/.editorconfig b/.editorconfig index a9cfa17448..d0556da637 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,16 @@ -[*.dm] -indent_style = tab -indent_size = 4 +[*] charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true +[*.cs] +indent_style = tab +indent_size = 4 +[*.csproj] +indent_style = space +indent_size = 2 +[*.dm] +indent_style = tab +indent_size = 4 +[*.yml] +indent_style = space +indent_size = 2 diff --git a/.github/workflows/suite.yml b/.github/workflows/suite.yml new file mode 100644 index 0000000000..5a641b5267 --- /dev/null +++ b/.github/workflows/suite.yml @@ -0,0 +1,232 @@ +name: 'Test Suite' + +on: + push: + branches: + - dev + - master + pull_request: + branches: + - dev + - master + +jobs: + server-unit-tests: + name: Build Server and Run Unit Tests + strategy: + matrix: + dotnet: [ '3.1.x' ] + node: [ '12.x' ] + configuration: [ 'Debug', 'Release' ] + env: + TGS4_TEST_DISCORD_CHANNEL: ${{ secrets.DISCORD_CHANNEL_ID }} + TGS4_TEST_DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }} + TGS4_TEST_IRC_CHANNEL: ${{ secrets.IRC_CHANNEL }} + TGS4_TEST_IRC_CONNECTION_STRING: ${{ secrets.IRC_CONNECTION_STRING }} + TGS4_TEST_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + runs-on: ubuntu-latest + steps: + - uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node }} + + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ matrix.dotnet }} + + - name: Checkout + uses: actions/checkout@v1 + + - name: Build + run: dotnet build -c ${{ matrix.configuration }} + + - name: Run Unit Tests + run: sudo dotnet test tgstation-server.sln --no-build --filter FullyQualifiedName!~IntegrationTests -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }} /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="./unit_tests.xml" + + - name: Publish Integration Test Artifacts + run: | + cd tests/Tgstation.Server.tests + dotnet publish -c ${{ matrix.configuration }} -o Artifacts --no-build + + - name: Store Integration Test Artifacts + uses: actions/upload-artifact@v2 + with: + name: integration-test-bins + path: tests/Tgstation.Server.Tests/Artifacts/ + + - name: Upload Code Coverage + uses: codecov/codecov-action@v1 + with: + file: ./unit_tests.xml + flags: unittests + fail_ci_if_error: true + + integration-tests: + name: Integration Tests + needs: [server-unit-tests, dmapi-build] + services: # We start all dbs here so we can just code the stuff once + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + # Set health checks to wait until postgres has started + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + mariadb: + image: mariadb + env: + MYSQL_ROOT_PASSWORD: mariadb + options: >- + --health-cmd="mysqladmin ping" + --health-interval=5s + --health-timeout=2s + --health-retries=3 + mysql: + image: mysql:5.7.31 + env: + MYSQL_ROOT_PASSWORD: mysql + options: >- + --health-cmd="mysqladmin ping" + --health-interval=10s + --health-timeout=5s + --health-retries=3 + strategy: + matrix: + database-type: [ 'Sqlite', 'PostgresSql', 'MariaDB', 'MySql' ] + basic-watchdog: [ 'yes', 'no' ] + runs-on: ubuntu-latest + steps: + - name: Install Native Dependencies + run: | + sudo dpkg add-architecture i386 + sudo apt-get update + sudo apt-get install -y libc6-i386 libstdc++6:i386 gdb + + - name: Disable ptrace_scope + run: echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope + + - name: Setup dotnet + uses: actions/setup-dotnet@v1 + with: + dotnet-version: ${{ matrix.dotnet }} + + - name: Set Sqlite Connection Info + if: ${{ matrix.database-type == 'Sqlite' }} + run: | + echo "::set-env name=TGS4_TEST_DATABASE_TYPE::Sqlite" + echo "::set-env name=TGS4_TEST_CONNECTION_STRING::Data Source=TravisTestDB.sqlite3;Mode=ReadWriteCreate" + + - name: Set PostgresSql Connection Info + if: ${{ matrix.database-type == 'PostgresSql' }} + run: | + echo "::set-env name=TGS4_TEST_DATABASE_TYPE::PostgresSql" + echo "::set-env name=TGS4_TEST_CONNECTION_STRING::Application Name=tgstation-server;Port=5432;Host=postgres;Username=postgres;Password=postgres;Database=TGS_Test" + + - name: Set MariaDB Connection Info + if: ${{ matrix.database-type == 'MariaDB' }} + run: | + echo "::set-env name=TGS4_TEST_DATABASE_TYPE::MariaDB" + echo "::set-env name=TGS4_TEST_CONNECTION_STRING::server=mariadb;uid=root;pwd=mariadb;database=tgs_test" + + - name: Set MySQL Connection Info + if: ${{ matrix.database-type == 'MySql' }} + run: | + echo "::set-env name=TGS4_TEST_DATABASE_TYPE::MySql" + echo "::set-env name=TGS4_TEST_CONNECTION_STRING::server=mysql;uid=root;pwd=mysql;database=tgs_test" + echo "::set-env name=Database__ServerVersion::5.7.31" + + - name: Set General__UseBasicWatchdog + if: ${{ matrix.basic-watchdog == 'yes' }} + run: echo "::set-env name=General__UseBasicWatchdog::true" + + - name: Checkout + uses: actions/checkout@v1 + + - name: Set TGS4_TEST_PULL_REQUEST_NUMBER + if: ${{ github.event_name == 'pull_request' }} + run: echo "::set-env name=TGS4_TEST_PULL_REQUEST_NUMBER::${{ github.event.issue.number }}" + + - name: Retrieve Integration Test Artifacts + uses: actions/download-artifact@v2 + with: + name: integration-test-bins + path: tests/Tgstation.Server.Tests/Artifacts + + - name: Run Integration Test + run: | + cd tests/Tgstation.Server.Tests + dotnet test Artifacts/Tgstation.Server.Tests.dll -l "console;verbosity=detailed;noprogress=true" -c ${{ matrix.configuration }} /p:CollectCoverage=true /p:CoverletOutputFormat=opencover /p:CoverletOutput="./integration_tests.xml" + + - name: Upload Code Coverage + uses: codecov/codecov-action@v1 + with: + file: ./integration_tests.xml + flags: integration + fail_ci_if_error: true + + docker-build: + name: Build Docker Image + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v1 + + - name: Build Docker Image + uses: docker build . -f build/Dockerfile + + dmapi-build: + name: Build DMAPI + env: + BYOND_MAJOR: 513 + BYOND_MINOR: 1527 + runs-on: ubuntu-latest + steps: + - name: Install x86 libc Dependencies + run: | + sudo dpkg add-architecture i386 + sudo apt-get update + sudo apt-get install -y libc6-i386 libstdc++6:i386 + + - name: Cache BYOND + id: cache-byond + uses: actions/cache@v2 + with: + path: byond + key: ${{ env.BYOND_MAJOR }}.${{ env.BYOND_MINOR }} + + - name: Install BYOND + if: steps.cache-byond.outputs.cache-hit != 'true' + run: | + echo "Setting up BYOND." + mkdir -p "$HOME/BYOND-${{ env.BYOND_MAJOR }}.${{ env.BYOND_MINOR }}" + cd "$HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}" + curl "http://www.byond.com/download/build/${{ env.BYOND_MAJOR }}/${{ env.BYOND_MAJOR }}.${{ env.BYOND_MINOR }}_byond_linux.zip" -o byond.zip + unzip byond.zip + cd byond + make here + cd ~/ + exit 0 + + - name: Build DMAPI Test Project + run: | + set -e + retval=1 + source $HOME/BYOND-${{ env.BYOND_MAJOR }}.${{ env.BYOND_MINOR }}/byond/bin/byondsetup + + if hash DreamMaker 2>/dev/null + then + DreamMaker $DMEName 2>&1 | tee result.log + retval=$? + if ! grep '\- 0 errors, 0 warnings' result.log + then + retval=1 + fi + else + echo "Couldn't find the DreamMaker executable, aborting." + retval=2 + fi + exit $retval diff --git a/.travis.yml b/.travis.yml index 0c495acc39..333ddccbe2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,138 +12,12 @@ branches: jobs: include: - env: - - DoxGeneration=false - - DockerBuild=false - - DMAPI=false - - CONFIG=Release - - MARIAFIX=true - - TGS4_TEST_DATABASE_TYPE=MySql - - TGS4_TEST_CONNECTION_STRING="server=127.0.0.1;uid=testuser;pwd=password;database=tgs_test" - name: "MariaDB Integration Test" - language: csharp - mono: none - dotnet: 3.1 - cache: - directories: - - $HOME/.nuget/packages: - addons: - mariadb: '10.5' - apt: - packages: - - libc6-i386 - - libstdc++6:i386 - - gdb - - env: - - DoxGeneration=false - - DockerBuild=false - - DMAPI=false - - CONFIG=Release - - General__UseBasicWatchdog=true - - TGS4_TEST_DATABASE_TYPE=Sqlite - - TGS4_TEST_CONNECTION_STRING="Data Source=TravisTestDB.sqlite3;Mode=ReadWriteCreate" - name: "Sqlite & BasicWatchdog Integration Test" - language: csharp - mono: none - dotnet: 3.1 - cache: - directories: - - $HOME/.nuget/packages: - addons: - apt: - packages: - - libc6-i386 - - libstdc++6:i386 - - gdb - - env: - - DoxGeneration=false - - DockerBuild=false - - DMAPI=false - - POSTGRESFIX=true - - CONFIG=Release - - TGS4_TEST_DATABASE_TYPE=PostgresSql - - TGS4_TEST_CONNECTION_STRING="Application Name=tgstation-server;Port=5433;Host=127.0.0.1;Username=testuser;Password=password;Database=TGS_Test" - - PGPORT=5433 - name: "PostgresSql Integration Test" - language: csharp - mono: none - dotnet: 3.1 - cache: - directories: - - $HOME/.nuget/packages: - addons: - postgresql: "12" - apt: - packages: - - postgresql-12 - - libc6-i386 - - libstdc++6:i386 - - gdb - - env: - - DoxGeneration=false - - DockerBuild=false - - DMAPI=false - - CONFIG=Debug - name: "Debug Unit Tests" - language: csharp - mono: none - dotnet: 3.1 - cache: - directories: - - $HOME/.nuget/packages: - - env: - - DoxGeneration=false - - DockerBuild=false - - DMAPI=false - - CONFIG=Release - name: "Release Unit Tests" - language: csharp - mono: none - dotnet: 3.1 - cache: - directories: - - $HOME/.nuget/packages: - - env: - - DoxGeneration=false - - DockerBuild=true - name: "Docker Build" - services: - - docker - - env: - - DoxGeneration=true name: "Dox Generation" addons: apt: packages: - doxygen - graphviz - - env: - - DoxGeneration=false - - DockerBuild=false - - DMAPI=true - - BYOND_MAJOR="513" - - BYOND_MINOR="1517" - - DMEName="tests/DMAPI/travistester.dme" - name: "DMAPI Unit Tests" - cache: - directories: - - $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR} - addons: - apt: - packages: - - libc6-i386 - - libstdc++6:i386 - -before_install: - - if [ $POSTGRESFIX = true ]; then sudo -u postgres psql -c "CREATE USER testuser WITH PASSWORD 'password'"; fi - - if [ $POSTGRESFIX = true ]; then sudo -u postgres psql -c "ALTER ROLE testuser SUPERUSER"; fi - - if [ $MARIAFIX = true ]; then sudo mysql -e "GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost' IDENTIFIED BY 'password';"; fi - -install: - - if [ $DoxGeneration = false ] && [ $DockerBuild = false ] && [ $DMAPI = true ]; then build/install_byond.sh; fi - - if [ $DoxGeneration = false ] && [ $DockerBuild = false ] && [ $DMAPI = false ]; then dotnet restore tgstation-server.sln; fi script: - - if [ $DoxGeneration = false ] && [ $DockerBuild = false ] && [ $DMAPI = true ]; then tests/DMAPI/BasicOperation/build_byond.sh || travis_terminate 1; fi - - if [ $DoxGeneration = false ] && [ $DockerBuild = false ] && [ $DMAPI = false ]; then build/test_core.sh; fi - - if [ $DoxGeneration = false ] && [ $DockerBuild = true ]; then docker build . -f build/Dockerfile; fi - - if [ $DoxGeneration = true ]; then build/build_dox.sh; fi + - build/build_dox.sh diff --git a/build/install_byond.sh b/build/install_byond.sh deleted file mode 100755 index b2da430247..0000000000 --- a/build/install_byond.sh +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/bash -set -e - -if [ -d "$HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}/byond/bin" ]; -then - echo "Using cached directory." - exit 0 -else - echo "Setting up BYOND." - mkdir -p "$HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}" - cd "$HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}" - curl "http://www.byond.com/download/build/${BYOND_MAJOR}/${BYOND_MAJOR}.${BYOND_MINOR}_byond_linux.zip" -o byond.zip - unzip byond.zip - cd byond - make here - cd ~/ - exit 0 -fi - -#some variable not set correctly, panic -exit 1 diff --git a/build/integration_test.sh b/build/integration_test.sh deleted file mode 100755 index a534057c20..0000000000 --- a/build/integration_test.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/bash -set -e - -# Needed so gcore can work -echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope - -export TGS4_TEST_DISCORD_CHANNEL=493119635319947269 -export TGS4_TEST_IRC_CHANNEL=\#botbus -export TGS4_TEST_TEMP_DIRECTORY=~/tgs4_test -#token set in CI settings - -cd tests/Tgstation.Server.Tests - -dotnet build -c $CONFIG - -sudo $HOME/.dotnet/tools/coverlet bin/$CONFIG/netcoreapp3.1/Tgstation.Server.Tests.dll --target "dotnet" --targetargs "test -c $CONFIG --no-build --logger:\"console;noprogress=true\"" --format opencover --output "../../TestResults/integration_test.xml" --include "[Tgstation.Server*]*" --exclude "[Tgstation.Server.Tests*]*" --exclude "[Tgstation.Server.Host]Tgstation.Server.Host.Database.Migrations.*" - -cd ../../TestResults - -bash <(curl -s https://codecov.io/bash) -f integration_test.xml -F integration diff --git a/tests/DMAPI/BasicOperation/build_byond.sh b/tests/DMAPI/BasicOperation/build_byond.sh deleted file mode 100755 index ac4473ad9a..0000000000 --- a/tests/DMAPI/BasicOperation/build_byond.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -set -e -retval=1 -source $HOME/BYOND-${BYOND_MAJOR}.${BYOND_MINOR}/byond/bin/byondsetup - -if hash DreamMaker 2>/dev/null -then - DreamMaker $DMEName 2>&1 | tee result.log - retval=$? - if ! grep '\- 0 errors, 0 warnings' result.log - then - retval=1 #hard fail, due to warnings or errors - fi -else - echo "Couldn't find the DreamMaker executable, aborting." - retval=2 -fi -exit $retval \ No newline at end of file diff --git a/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj b/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj index a6b0eb5ca8..81b42afb96 100644 --- a/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj +++ b/tests/Tgstation.Server.Api.Tests/Tgstation.Server.Api.Tests.csproj @@ -8,6 +8,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj b/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj index 39b7bd44fc..0585c62165 100644 --- a/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj +++ b/tests/Tgstation.Server.Client.Tests/Tgstation.Server.Client.Tests.csproj @@ -8,6 +8,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj b/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj index 16bc54e368..a53fb435d8 100644 --- a/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj +++ b/tests/Tgstation.Server.Host.Console.Tests/Tgstation.Server.Host.Console.Tests.csproj @@ -8,6 +8,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj b/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj index 61104bf6f2..68cbe52649 100644 --- a/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj +++ b/tests/Tgstation.Server.Host.Service.Tests/Tgstation.Server.Host.Service.Tests.csproj @@ -14,6 +14,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj b/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj index 82abc311b9..243e758b8c 100644 --- a/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj +++ b/tests/Tgstation.Server.Host.Tests/Tgstation.Server.Host.Tests.csproj @@ -8,6 +8,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all + diff --git a/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj b/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj index f3e03b7477..0c9e91bb71 100644 --- a/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj +++ b/tests/Tgstation.Server.Host.Watchdog.Tests/Tgstation.Server.Host.Watchdog.Tests.csproj @@ -14,6 +14,10 @@ + + runtime; build; native; contentfiles; analyzers; buildtransitive + all +