From 18983f03b84d4d4a4ebbe62a7cf7f22e22807b61 Mon Sep 17 00:00:00 2001 From: Sean Molenaar Date: Mon, 31 Aug 2020 22:19:35 +0200 Subject: Test GH actions flow Signed-off-by: Sean Molenaar --- .github/workflows/integration-tests.yml | 108 ++++++++++++++++++++++++++++++++ .github/workflows/php-tests.yml | 50 +++++++++++++++ .travis.yml | 41 +----------- Makefile | 27 ++++++-- 4 files changed, 180 insertions(+), 46 deletions(-) create mode 100644 .github/workflows/integration-tests.yml create mode 100644 .github/workflows/php-tests.yml diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml new file mode 100644 index 000000000..b48d2ac79 --- /dev/null +++ b/.github/workflows/integration-tests.yml @@ -0,0 +1,108 @@ +name: Integration Tests +on: + pull_request + +env: + POSTGRES_PASSWORD: nc_test_db + MYSQL_USER: nc_test + MYSQL_PASSWORD: nc_test_db + MYSQL_DATABASE: nc_test + MYSQL_PORT: 3800 + +jobs: + integration: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + name: "Integration: Nextcloud ${{ matrix.nextcloud }} - PHP ${{ matrix.php-versions }} - DB ${{ matrix.database }}" + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: ${{ env.POSTGRES_PASSWORD }} + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 # Maps tcp port 5432 on service container to the host + strategy: + matrix: + php-versions: ['7.2', '7.3', '7.4'] + nextcloud: ['17', '18', '19'] + database: ['sqlite', 'pgsql', 'mysql'] + experimental: [false] + include: + - php-versions: 7.4 + nextcloud: pre-release + database: sqlite + experimental: true + exclude: #unsupported combination + - php-versions: 7.4 + nextcloud: 17 + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + + ### MySQL specific setup + - name: Setup mysql + if: matrix.database == 'mysql' + uses: getong/mariadb-action@v1.1 + with: + host port: ${{ env.MYSQL_PORT }} + mysql database: ${{ env.MYSQL_DATABASE }} + mysql root password: ${{ env.MYSQL_PASSWORD }} + mysql user: ${{ env.MYSQL_USER }} + mysql password: ${{ env.MYSQL_PASSWORD }} + + - name: Set up server MySQL + if: matrix.database == 'mysql' + uses: SMillerDev/nextcloud-actions/setup-nextcloud@main + with: + version: ${{ matrix.nextcloud }} + cron: true + database-type: ${{ matrix.database }} + database-host: 127.0.0.1 + database-port: ${{ env.MYSQL_PORT }} + database-name: ${{ env.MYSQL_DATABASE }} + database-user: root + database-password: ${{ env.MYSQL_PASSWORD }} + + ### Back to normal setup + - name: Set up server non MySQL + if: matrix.database != 'mysql' + uses: SMillerDev/nextcloud-actions/setup-nextcloud@main + with: + version: ${{ matrix.nextcloud }} + cron: true + database-type: ${{ matrix.database }} + database-host: localhost + database-port: 5432 + database-name: postgres + database-user: postgres + database-password: ${{ env.POSTGRES_PASSWORD }} + + - name: Prime app build + run: make + + - name: Configure server with app + uses: SMillerDev/nextcloud-actions/setup-nextcloud-app@main + with: + app: 'news' + check-code: true + + - name: Functional tests + run: | + cd ../server + ./occ news:generate-explore --votes 100 "https://nextcloud.com/blog/feed/" + + - name: Prep PHP tests + run: cd ../server/apps/news && make php-test-dependencies + - name: Integration tests + run: cd ../server/apps/news && make integration-test + diff --git a/.github/workflows/php-tests.yml b/.github/workflows/php-tests.yml new file mode 100644 index 000000000..79a26d437 --- /dev/null +++ b/.github/workflows/php-tests.yml @@ -0,0 +1,50 @@ +name: PHP Tests +on: + pull_request + +jobs: + php: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + name: "PHP: Nextcloud ${{ matrix.nextcloud }} - PHP ${{ matrix.php-versions }} - DB ${{ matrix.database }}" + strategy: + matrix: + php-versions: ['7.4'] + nextcloud: ['19'] + database: ['sqlite'] + experimental: [false] + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + + ### Back to normal setup + - name: Set up server non MySQL + if: matrix.database != 'mysql' + uses: SMillerDev/nextcloud-actions/setup-nextcloud@main + with: + cron: true + version: ${{ matrix.nextcloud }} + database-type: ${{ matrix.database }} + + - name: Prime app build + run: make + + - name: Configure server with app + uses: SMillerDev/nextcloud-actions/setup-nextcloud-app@main + with: + app: 'news' + check-code: true + + - name: Prep PHP tests + run: cd ../server/apps/news && make php-test-dependencies + - name: PHPCS + run: cd ../server/apps/news && make phpcs + - name: PHPStan + run: cd ../server/apps/news && make phpstan + - name: Unittests + run: cd ../server/apps/news && make unit-test \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 6275d3eb7..3680e1750 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,36 +3,12 @@ dist: bionic language: php php: - - 7.2 - - 7.3 - 7.4 env: global: - MOZ_HEADLESS=1 - jobs: - - CORE_BRANCH=stable17 DB=mysql - - CORE_BRANCH=stable18 DB=pgsql - - CORE_BRANCH=stable18 DB=mysql - - CORE_BRANCH=stable19 DB=pgsql - - CORE_BRANCH=stable19 DB=mysql - CORE_BRANCH=stable19 DB=sqlite - - CORE_BRANCH=master DB=sqlite - -jobs: - exclude: - - php: 7.4 - env: CORE_BRANCH=stable17 DB=pgsql # not supported by nc - - php: 7.4 - env: CORE_BRANCH=stable17 DB=mysql # not supported by nc - - php: 7.2 - env: CORE_BRANCH=master DB=sqlite # not wanted - - php: 7.3 - env: CORE_BRANCH=master DB=sqlite # not wanted - allow_failures: - - env: - - CORE_BRANCH=master DB=sqlite - fast_finish: true before_install: - make @@ -41,13 +17,6 @@ before_install: - mv news nextcloud/apps/ before_script: - - if [[ "$DB" == 'pgsql' ]]; then psql -c "CREATE ROLE oc_autotest LOGIN PASSWORD 'oc_autotest'" -U postgres; fi - - if [[ "$DB" == 'pgsql' ]]; then psql -c "CREATE DATABASE oc_autotest OWNER oc_autotest;" -U postgres; fi - - if [[ "$DB" == 'mysql' ]]; then sudo mysql -u root -e 'CREATE DATABASE oc_autotest;'; fi - - if [[ "$DB" == 'mysql' ]]; then sudo mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'oc_autotest';"; fi - - if [[ "$DB" == 'mysql' ]]; then sudo mysql -u root -e "GRANT ALL ON oc_autotest.* TO 'oc_autotest'@'localhost';"; fi - - if [[ "$DB" == 'mysql' ]]; then sudo mysql -u root -e "SET GLOBAL sql_mode = 'STRICT_ALL_TABLES,ONLY_FULL_GROUP_BY';"; fi - # fill nextcloud with default configs and enable news - cd nextcloud - mkdir data @@ -59,22 +28,14 @@ before_script: --database-user="oc_autotest" --database-pass="oc_autotest" - ./occ app:enable news - - ./occ app:check-code news - - ./occ background:cron # enable default cron - php -S localhost:8080 & script: - - ./occ news:generate-explore --votes 100 "https://nextcloud.com/blog/feed/" - cd apps/news - - make test + - make js-test after_failure: - cat ../../data/nextcloud.log -after_success: - - bash <(curl -s https://codecov.io/bash) - addons: firefox: "latest-beta" - postgresql: "10" - mariadb: "10.4" diff --git a/Makefile b/Makefile index 6a82237c3..c6194206e 100644 --- a/Makefile +++ b/Makefile @@ -186,16 +186,31 @@ endif tar -czf $(appstore_package_name).tar.gz -C $(appstore_build_directory)/../ $(app_name) +.PHONY: js-test +js-test: + cd js && $(npm) run test + +.PHONY: php-test-dependencies +php-test-dependencies: + $(composer) update --prefer-dist + +.PHONY: unit-test +unit-test: + ./vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-clover build/php-unit.clover + +# \Test\TestCase is only allowed to access the db if TRAVIS environment variable is set +.PHONY: integration-test +integration-test: + env TRAVIS=1 ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml + # Command for running JS and PHP tests. Works for package.json files in the js/ # and root directory. If phpunit is not installed systemwide, a copy is fetched # from the internet .PHONY: test -test: - $(composer) update --prefer-dist - cd js && $(npm) run test - ./vendor/phpunit/phpunit/phpunit -c phpunit.xml --coverage-clover build/php-unit.clover - # \Test\TestCase is only allowed to access the db if TRAVIS environment variable is set - env TRAVIS=1 ./vendor/phpunit/phpunit/phpunit -c phpunit.integration.xml +test: php-test-dependencies + $(MAKE) unit-test + $(MAKE) integration-test $(MAKE) phpcs $(MAKE) phpstan + $(MAKE) js-test ./bin/tools/generate_authors.php -- cgit v1.2.3