From eab255c4bfc764aea50d7d2c933c0ca9fdfdfe27 Mon Sep 17 00:00:00 2001 From: Ted John Date: Fri, 24 Jan 2020 11:46:12 +0000 Subject: [PATCH] Add Linux portable to GitHub CI (#10612) --- .clang-format | 1 + .github/workflows/ci.yml | 148 +++++++++++++++++++++++++--------- .travis.yml | 49 ----------- scripts/build | 47 ++++++----- scripts/build-appimage | 18 +++++ scripts/build-portable | 13 ++- scripts/check-code-formatting | 8 ++ scripts/get-discord-rpc | 8 ++ scripts/run-testpaint | 13 +++ scripts/run-tests | 17 ++-- scripts/setenv | 2 +- 11 files changed, 210 insertions(+), 114 deletions(-) create mode 100755 scripts/build-appimage create mode 100755 scripts/check-code-formatting create mode 100755 scripts/get-discord-rpc create mode 100755 scripts/run-testpaint diff --git a/.clang-format b/.clang-format index ebb3421b67..b81be7ebba 100644 --- a/.clang-format +++ b/.clang-format @@ -20,6 +20,7 @@ AlwaysBreakTemplateDeclarations: false BinPackArguments: true BinPackParameters: true BraceWrapping: + AfterCaseLabel: true AfterClass: true AfterControlStatement: true AfterEnum: true diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ef33866446..6c3d3bb2a5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,11 +9,12 @@ jobs: name: Check code formatting runs-on: ubuntu-latest container: - image: openrct2/openrct2:format + image: openrct2/openrct2-build:0.2.4-format steps: - - uses: actions/checkout@v1 + - name: Checkout + uses: actions/checkout@v1 - name: Run clang-format - run: scripts/run-clang-format.py -r src test --exclude src/openrct2/thirdparty + run: scripts/check-code-formatting windows: name: Windows runs-on: windows-latest @@ -25,8 +26,8 @@ jobs: CONFIGURATION: Release PLATFORM: ${{ matrix.platform }} steps: - - uses: actions/checkout@v1 - name: Checkout + - name: Checkout + uses: actions/checkout@v1 - name: Build OpenRCT2 shell: bash run: . scripts/setenv && build @@ -37,8 +38,8 @@ jobs: build-portable build-symbols build-installer -i - - uses: actions/upload-artifact@master - name: Upload artifacts (CI) + - name: Upload artifacts (CI) + uses: actions/upload-artifact@v1 with: name: "OpenRCT2-Windows-${{ matrix.platform }}" path: artifacts @@ -56,20 +57,20 @@ jobs: else echo 'Not going to push build' fi - osx: + macos: name: macOS runs-on: macos-latest steps: - - uses: actions/checkout@v1 - name: Checkout + - name: Checkout + uses: actions/checkout@v1 - name: Build OpenRCT2 run: | . scripts/setenv xcodebuild mkdir -p artifacts mv build/Release/OpenRCT2.app artifacts - - uses: actions/upload-artifact@master - name: Upload artifacts (CI) + - name: Upload artifacts (CI) + uses: actions/upload-artifact@v1 with: name: "OpenRCT2-macOS" path: artifacts @@ -84,36 +85,111 @@ jobs: else echo 'Not going to push build' fi - build-appimage: + linux-portable: + name: Linux (x64, portable) + runs-on: ubuntu-latest + container: + image: openrct2/openrct2-build:0.2.4-bionic + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Get pre-reqs + shell: bash + run: . scripts/setenv && get-discord-rpc + - name: Build OpenRCT2 + shell: bash + run: . scripts/setenv -q && build -DWITH_TESTS=on -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=ON -DPORTABLE=ON -DCMAKE_CXX_FLAGS="-g -gz" + - name: Build artifacts + shell: bash + run: . scripts/setenv -q && build-portable artifacts/OpenRCT2-Linux-x86_64.tar.gz bin/install/usr + - name: Upload artifacts (CI) + uses: actions/upload-artifact@v1 + with: + name: "OpenRCT2-Linux-x86_64" + path: artifacts + - name: Run Tests + shell: bash + run: . scripts/setenv -q && run-tests + - name: Upload artifacts (openrct2.org) + shell: bash + run: | + . scripts/setenv -q + if [[ "$OPENRCT2_PUSH" == "true" ]]; then + upload-build artifacts/OpenRCT2-Linux-x86_64.tar.gz linux-x86_64 $OPENRCT2_VERSION $OPENRCT2_SHA1 $OPENRCT2_BRANCH + else + echo 'Not going to push build' + fi + linux-portable-32: + name: Linux (i686, portable) + runs-on: ubuntu-latest + container: + image: openrct2/openrct2-build:0.2.4-bionic32 + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Get pre-reqs + shell: bash + run: . scripts/setenv && get-discord-rpc + - name: Build OpenRCT2 + shell: bash + env: + TESTPAINT: true + run: . scripts/setenv -q && build -DWITH_TESTS=on -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=ON -DPORTABLE=ON -DFORCE32=ON -DCMAKE_CXX_FLAGS="-m32 -gz" + - name: Build artifacts + shell: bash + run: . scripts/setenv -q && build-portable artifacts/OpenRCT2-Linux-i686.tar.gz bin/install/usr + - name: Upload artifacts (CI) + uses: actions/upload-artifact@v1 + with: + name: "OpenRCT2-Linux-i686" + path: artifacts + - name: Run Tests + shell: bash + run: . scripts/setenv -q && run-tests + - name: Run testpaint + shell: bash + run: . scripts/setenv -q && run-testpaint + - name: Upload artifacts (openrct2.org) + shell: bash + run: | + . scripts/setenv -q + if [[ "$OPENRCT2_PUSH" == "true" ]]; then + upload-build artifacts/OpenRCT2-Linux-i686.tar.gz linux-i686 $OPENRCT2_VERSION $OPENRCT2_SHA1 $OPENRCT2_BRANCH + else + echo 'Not going to push build' + fi + linux-appimage: name: Linux (x64, AppImage) runs-on: ubuntu-latest container: - image: openrct2/openrct2:ubuntu_amd64 + image: openrct2/openrct2-build:0.2.4-bionic steps: - - uses: actions/checkout@v1 - name: Checkout + - name: Checkout + uses: actions/checkout@v1 - name: Get pre-reqs - run: | - git clone https://github.com/discordapp/discord-rpc -b v3.4.0 - git clone https://github.com/janisozaur/rapidjson discord-rpc/thirdparty/rapidjson -b patch-1 - mkdir bin && cd bin - apt-get update - apt-get install -y wget libcairo2 - wget https://github.com/TheAssassin/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage - chmod +x linuxdeploy*.AppImage + shell: bash + run: . scripts/setenv -q && get-discord-rpc - name: Build OpenRCT2 - working-directory: bin - run: | - cmake .. -G Ninja -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr - ninja -v - DESTDIR=AppDir ninja install + shell: bash + env: + DESTDIR: AppDir + run: . scripts/setenv -q && build -DCMAKE_BUILD_TYPE=Release - name: Build AppImage - working-directory: bin - run: | - ./linuxdeploy*.AppImage --appimage-extract-and-run --appdir AppDir/ --output appimage --desktop-file AppDir/usr/share/applications/openrct2.desktop - mkdir artifacts - mv OpenRCT2*.AppImage artifacts - - uses: actions/upload-artifact@master + shell: bash + run: . scripts/setenv -q && build-appimage + - name: Upload artifacts (CI) + uses: actions/upload-artifact@v1 with: name: OpenRCT2-AppImage - path: bin/artifacts + path: artifacts + linux-clang: + name: Linux (Debug, [http, network, OpenGL] disabled) using clang + runs-on: ubuntu-latest + container: + image: openrct2/openrct2-build:0.2.4-bionic + steps: + - name: Checkout + uses: actions/checkout@v1 + - name: Build OpenRCT2 + shell: bash + run: . scripts/setenv && build -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_BUILD_TYPE=Debug -DDISABLE_NETWORK=ON -DDISABLE_HTTP_TWITCH=ON -DDISABLE_OPENGL=ON diff --git a/.travis.yml b/.travis.yml index 60c326b027..aaa950cfde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,55 +25,6 @@ env: matrix: include: - - os: linux - name: Ubuntu amd64 GCC MinSizeRel - if: type != cron - services: - - docker - env: - - OPENRCT2_CMAKE_OPTS="-G Ninja -DCMAKE_BUILD_TYPE=MinSizeRel -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=OpenRCT2 -DPORTABLE=ON -DCMAKE_CXX_FLAGS=\"-g -gz\"" TARGET=ubuntu_amd64 - - secure: "S3u2VCE2Vy8KNXoeh+DhnzjCmgTX0r95uEZrXDU+IKANOOCKn7Dg4OFDZE3LY/i1y2/EUDpnR5yLC38Ks795EUP/sv/OoMl4tjQ20yERjqWh+gcIRrgx7SdVabuAh3t4aBdaLD4Pfnj5avxeCt6rL7yGnj0wdbrbJSBZPsgSnuQ=" - after_success: - - sudo chown -R $USER build - - cd build - # make install is done inside docker - - mv OpenRCT2/bin/openrct2 OpenRCT2/ && mv OpenRCT2/bin/openrct2-cli OpenRCT2/ && mv OpenRCT2/bin/libopenrct2.so OpenRCT2/ && mv OpenRCT2/share/openrct2 OpenRCT2/data && mv OpenRCT2/share/doc/openrct2 OpenRCT2/doc && mv OpenRCT2/bin/libdiscord-rpc.so OpenRCT2/ - - rm -rf OpenRCT2/bin OpenRCT2/share # remove empty dirs - - tar cvzf openrct2-linux.tar.gz OpenRCT2/ - - ls -lR - - if [[ "z${TRAVIS_TAG}" != "z" ]] ; then - export PUSH_BRANCH=master ; - else export PUSH_BRANCH=$TRAVIS_BRANCH ; export FILENAME_PART=-${TRAVIS_BRANCH}-$(git rev-parse --short HEAD) ; - fi - - curl -m $CURL_MAX_TIME --connect-timeout $CURL_CONNECT_TIMEOUT --upload-file openrct2-linux.tar.gz https://transfer.sh/openrct2-linux-x86_64.tar.gz -o link && cat link && echo || echo "Failed transfer.sh upload" - - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then - curl -m $CURL_MAX_TIME --connect-timeout $CURL_CONNECT_TIMEOUT -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-linux-x86_64.tar.gz" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=9" --form "file=@openrct2-linux.tar.gz" "https://openrct2.org/altapi/?command=push-build"; - fi - - os: linux - name: Ubuntu i686 GCC Debug m32 no-build-shared-libs - if: type != cron - services: - - docker - env: - - OPENRCT2_CMAKE_OPTS="-G Ninja -DFORCE32=ON -DBUILD_SHARED_LIBS=off -DCMAKE_INSTALL_PREFIX=OpenRCT2 -DCMAKE_BUILD_TYPE=debug -DCMAKE_CXX_FLAGS=\"-coverage -m32 -gz\"" TARGET=ubuntu_i686 - - secure: "S3u2VCE2Vy8KNXoeh+DhnzjCmgTX0r95uEZrXDU+IKANOOCKn7Dg4OFDZE3LY/i1y2/EUDpnR5yLC38Ks795EUP/sv/OoMl4tjQ20yERjqWh+gcIRrgx7SdVabuAh3t4aBdaLD4Pfnj5avxeCt6rL7yGnj0wdbrbJSBZPsgSnuQ=" - - secure: "JGMzQHmDgpnVzP2uYP5KL7h6SzzGmL4kH7vJmGQRpudKAEzhzB0n7lzjrJOU82hxwmuQQ+RKlE/uxdI32Xbgl+wzZMdfQoZGMWHZfl8Le0Ft5gfZncPuE3poCbiSyPSXok9zU12JHKpEjV/sgqXv/HwhL3jAC68GPGpmxb6xWj8=" - after_success: - - sudo chown -R $USER build - - cd build - # make install is done inside docker - - mv OpenRCT2/bin/openrct2 OpenRCT2/ && mv OpenRCT2/share/openrct2 OpenRCT2/data && mv OpenRCT2/share/doc/openrct2 OpenRCT2/doc - - rm -rf OpenRCT2/bin OpenRCT2/share # remove empty dirs - - tar cvzf openrct2-linux.tar.gz OpenRCT2/ - - ls -lR - - if [[ "z${TRAVIS_TAG}" != "z" ]] ; then - export PUSH_BRANCH=master ; - else export PUSH_BRANCH=$TRAVIS_BRANCH ; export FILENAME_PART=-${TRAVIS_BRANCH}-$(git rev-parse --short HEAD) ; - fi - - curl -m $CURL_MAX_TIME --connect-timeout $CURL_CONNECT_TIMEOUT --upload-file openrct2-linux.tar.gz https://transfer.sh/openrct2-linux-i686.tar.gz -o link && cat link && echo || echo "Failed transfer.sh upload" - - if [[ "z$OPENRCT2_ORG_TOKEN" != "z" && "$TRAVIS_PULL_REQUEST" == "false" && ("${TRAVIS_BRANCH}" =~ ^(develop|push/) || "z${TRAVIS_TAG}" != "z") ]] ; then - curl -m $CURL_MAX_TIME --connect-timeout $CURL_CONNECT_TIMEOUT -o - -v --form "key=$OPENRCT2_ORG_TOKEN" --form "fileName=OpenRCT2-${OPENRCT2_VERSION}${FILENAME_PART}-linux-i686.tar.gz" --form "version=${OPENRCT2_VERSION}" --form "gitHash=$TRAVIS_COMMIT" --form "gitBranch=$PUSH_BRANCH" --form "flavourId=4" --form "file=@openrct2-linux.tar.gz" "https://openrct2.org/altapi/?command=push-build"; - fi - os: linux name: Ubuntu amd64 Clang if: type != cron diff --git a/scripts/build b/scripts/build index 7c942feb6f..cbba81ae02 100755 --- a/scripts/build +++ b/scripts/build @@ -5,22 +5,33 @@ set -e basedir="$(readlink -f `dirname $0`/..)" cd $basedir -# Patch version.h -if [[ "$OPENRCT2_BUILD" != "" ]]; then - echo -e "\033[0;36mPatching version.h...\033[0m" - fileversion=$OPENRCT2_VERSION.$OPENRCT2_BUILD - productversion="$fileversion-${OPENRCT2_SHA1_SHORT}" - fileversion=${fileversion//./,} - echo "#define OPENRCT2_FILE_VERSION $fileversion" > "resources/version.h" - echo "#define OPENRCT2_PRODUCT_VERSION \"$productversion\"" >> "resources/version.h" - cat "resources/version.h" +if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]]; then + # Patch version.h + if [[ "$OPENRCT2_BUILD" != "" ]]; then + echo -e "\033[0;36mPatching version.h...\033[0m" + fileversion=$OPENRCT2_VERSION.$OPENRCT2_BUILD + productversion="$fileversion-${OPENRCT2_SHA1_SHORT}" + fileversion=${fileversion//./,} + echo "#define OPENRCT2_FILE_VERSION $fileversion" > "resources/version.h" + echo "#define OPENRCT2_PRODUCT_VERSION \"$productversion\"" >> "resources/version.h" + cat "resources/version.h" + fi + + # Build everything + echo -e "\033[0;36mBuilding OpenRCT2 for Windows $CONFIGURATION|$PLATFORM...\033[0m" + vstool msbuild openrct2.proj //t:build + + # Create openrct2.exe and openrct2.com with correct subsystem + cp bin/openrct2.exe bin/openrct2.com + vstool editbin //subsystem:console bin/openrct2.com + vstool editbin //subsystem:windows bin/openrct2.exe +else + echo -e "\033[0;36mBuilding OpenRCT2...\033[0m" + mkdir -p bin && cd bin + export DESTDIR=install + cmake .. -G Ninja -DCMAKE_INSTALL_PREFIX=/usr "$@" + if [[ "$TESTPAINT" == "true" ]]; then + testpaint_target=testpaint + fi + ninja -v $testpaint_target all install fi - -# Build everything -echo -e "\033[0;36mBuilding OpenRCT2 for Windows $CONFIGURATION|$PLATFORM...\033[0m" -vstool msbuild openrct2.proj //t:build - -# Create openrct2.exe and openrct2.com with correct subsystem -cp bin/openrct2.exe bin/openrct2.com -vstool editbin //subsystem:console bin/openrct2.com -vstool editbin //subsystem:windows bin/openrct2.exe diff --git a/scripts/build-appimage b/scripts/build-appimage new file mode 100755 index 0000000000..498706c5ba --- /dev/null +++ b/scripts/build-appimage @@ -0,0 +1,18 @@ +#!/bin/bash +set -e + +echo -e "\033[0;36mBuilding AppImage for OpenRCT2...\033[0m" + +# Ensure we are in root directory +basedir="$(readlink -f `dirname $0`/..)" +cd $basedir + +linuxdeploy=/tmp/linuxdeploy-x86_64.AppImage +curl -Lo $linuxdeploy https://github.com/TheAssassin/linuxdeploy/releases/download/continuous/linuxdeploy-x86_64.AppImage +chmod +x $linuxdeploy +pushd bin + $linuxdeploy --appimage-extract-and-run --appdir install/ --output appimage --desktop-file install/usr/share/applications/openrct2.desktop +popd +mkdir -p artifacts +mv bin/OpenRCT2*.AppImage artifacts +rm $linuxdeploy diff --git a/scripts/build-portable b/scripts/build-portable index b9a1068f5e..fbf3313eac 100755 --- a/scripts/build-portable +++ b/scripts/build-portable @@ -31,14 +31,19 @@ else if [[ "$#" -ne 2 ]]; then echo 'Turn an OpenRCT2 cmake install into a portable tar.gz.' echo '' - echo 'Usage: create-portable-build ' + echo 'Usage: build-portable ' exit 1 fi output=$1 install=$2 - echo -e "\033[0;36mCreating $output..." + echo -e "\033[0;36mCreating $output...\033[0m" + outputdir=$(dirname $output) + if ! [[ -d $outputdir ]]; then + mkdir -p $outputdir + fi + workdir=$output-temp if [[ -d "$workdir" ]] then @@ -47,12 +52,12 @@ else mkdir -p $workdir/OpenRCT2 cp -r $install/bin/* $workdir/OpenRCT2 - cp -r $install/share/doc $workdir/OpenRCT2 + cp -r $install/share/doc/openrct2 $workdir/OpenRCT2/doc cp -r $install/share/openrct2 $workdir/OpenRCT2/data pushd $workdir > /dev/null tar -czf output.tar.gz OpenRCT2 popd > /dev/null mv $workdir/output.tar.gz $output rm -rf $workdir - echo -e "\033[0;32m$output created successfully" + echo -e "\033[0;32m$output created successfully\033[0m" fi diff --git a/scripts/check-code-formatting b/scripts/check-code-formatting new file mode 100755 index 0000000000..491d21742b --- /dev/null +++ b/scripts/check-code-formatting @@ -0,0 +1,8 @@ +#!/bin/sh +set -e + +# Ensure we are in root directory +basedir="$(readlink -f `dirname $0`/..)" +cd $basedir + +scripts/run-clang-format.py -r src test --exclude src/openrct2/thirdparty diff --git a/scripts/get-discord-rpc b/scripts/get-discord-rpc new file mode 100755 index 0000000000..8afc826569 --- /dev/null +++ b/scripts/get-discord-rpc @@ -0,0 +1,8 @@ +#!/bin/bash +set -e + +basedir="$(readlink -f `dirname $0`/..)" +cd $basedir + +git clone https://github.com/discordapp/discord-rpc -b v3.4.0 +git clone https://github.com/janisozaur/rapidjson discord-rpc/thirdparty/rapidjson -b patch-1 diff --git a/scripts/run-testpaint b/scripts/run-testpaint new file mode 100755 index 0000000000..479640a7ad --- /dev/null +++ b/scripts/run-testpaint @@ -0,0 +1,13 @@ +#!/bin/bash +set -e + +# Ensure we are in root directory +basedir="$(readlink -f `dirname $0`/..)" +cd $basedir/bin + +# Scan objects first so that does not happen within a test +echo -e "\033[0;36mBuilding OpenRCT2 repository indexes...\033[0m" +./openrct2 scan-objects + +echo -e "\033[0;36mRunning OpenRCT2 testpaint tests...\033[0m" +./testpaint || true diff --git a/scripts/run-tests b/scripts/run-tests index 15daa8f8d2..821984a066 100755 --- a/scripts/run-tests +++ b/scripts/run-tests @@ -5,13 +5,18 @@ set -e basedir="$(readlink -f `dirname $0`/..)" cd $basedir/bin -# Ensure test data uses LF -dos2unix testdata/keys/* - # Scan objects first so that does not happen within a test echo -e "\033[0;36mBuilding OpenRCT2 repository indexes...\033[0m" ./openrct2 scan-objects -# Now run all the tests -echo -e "\033[0;36mRunning OpenRCT2 tests...\033[0m" -./tests --gtest_output=xml:../artifacts/test-results.xml +if [[ "$OSTYPE" == "cygwin" || "$OSTYPE" == "msys" ]]; then + # Ensure test data uses LF + dos2unix testdata/keys/* + + # Now run all the tests + echo -e "\033[0;36mRunning OpenRCT2 tests...\033[0m" + ./tests --gtest_output=xml:../artifacts/test-results.xml +else + echo -e "\033[0;36mRunning OpenRCT2 tests...\033[0m" + ctest --output-on-failure +fi diff --git a/scripts/setenv b/scripts/setenv index 014d0ab624..fd1ec741e3 100755 --- a/scripts/setenv +++ b/scripts/setenv @@ -50,7 +50,7 @@ fi realpath() { [[ $1 = /* ]] && echo "$1" || echo "$(pwd)/${1#./}" } -scriptsdir="$(realpath `dirname ${BASH_SOURCE[0]}`)" +scriptsdir="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" export PATH="$scriptsdir:$PATH" # Output all the variables