diff --git a/.travis/consumer_db/mariadb.json b/.github/helper/consumer_db/mariadb.json similarity index 89% rename from .travis/consumer_db/mariadb.json rename to .github/helper/consumer_db/mariadb.json index fb5b3bc976..2e32157e1a 100644 --- a/.travis/consumer_db/mariadb.json +++ b/.github/helper/consumer_db/mariadb.json @@ -1,5 +1,6 @@ { - "db_host": "localhost", + "db_host": "127.0.0.1", + "db_port": 3306, "db_name": "test_frappe_consumer", "db_password": "test_frappe", "allow_tests": true, diff --git a/.travis/consumer_db/postgres.json b/.github/helper/consumer_db/postgres.json similarity index 90% rename from .travis/consumer_db/postgres.json rename to .github/helper/consumer_db/postgres.json index fed9fdfde2..9532670029 100644 --- a/.travis/consumer_db/postgres.json +++ b/.github/helper/consumer_db/postgres.json @@ -1,5 +1,6 @@ { - "db_host": "localhost", + "db_host": "127.0.0.1", + "db_port": 5432, "db_name": "test_frappe_consumer", "db_password": "test_frappe", "db_type": "postgres", diff --git a/.github/helper/install.sh b/.github/helper/install.sh new file mode 100644 index 0000000000..ee92ddd645 --- /dev/null +++ b/.github/helper/install.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +cd ~ || exit + +# shellcheck disable=SC1091 +source ./.nvm/nvm.sh +nvm install 12 + +pip install frappe-bench + +bench init frappe-bench --skip-assets --python "$(which python)" --frappe-path "${GITHUB_WORKSPACE}" + +mkdir ~/frappe-bench/sites/test_site +cp "${GITHUB_WORKSPACE}/.github/helper/consumer_db/$DB.json" ~/frappe-bench/sites/test_site/site_config.json + +if [ "$TYPE" == "server" ]; then + mkdir ~/frappe-bench/sites/test_site_producer; + cp "${GITHUB_WORKSPACE}/.github/helper/producer_db/$DB.json" ~/frappe-bench/sites/test_site_producer/site_config.json; +fi + +if [ "$DB" == "mariadb" ];then + mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"; + mysql --host 127.0.0.1 --port 3306 -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; + + mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE DATABASE test_frappe_consumer"; + mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE USER 'test_frappe_consumer'@'localhost' IDENTIFIED BY 'test_frappe_consumer'"; + mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe_consumer\`.* TO 'test_frappe_consumer'@'localhost'"; + + mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE DATABASE test_frappe_producer"; + mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE USER 'test_frappe_producer'@'localhost' IDENTIFIED BY 'test_frappe_producer'"; + mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe_producer\`.* TO 'test_frappe_producer'@'localhost'"; + + mysql --host 127.0.0.1 --port 3306 -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"; + mysql --host 127.0.0.1 --port 3306 -u root -e "FLUSH PRIVILEGES"; + fi + +if [ "$DB" == "postgres" ];then + echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE DATABASE test_frappe_consumer" -U postgres; + echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE USER test_frappe_consumer WITH PASSWORD 'test_frappe'" -U postgres; + + echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE DATABASE test_frappe_producer" -U postgres; + echo "travis" | psql -h 127.0.0.1 -p 5432 -c "CREATE USER test_frappe_producer WITH PASSWORD 'test_frappe'" -U postgres; +fi + +cd ./frappe-bench || exit + +sed -i 's/^watch:/# watch:/g' Procfile +sed -i 's/^schedule:/# schedule:/g' Procfile + +if [ "$TYPE" == "server" ]; then sed -i 's/^socketio:/# socketio:/g' Procfile; fi +if [ "$TYPE" == "server" ]; then sed -i 's/^redis_socketio:/# redis_socketio:/g' Procfile; fi + +if [ "$TYPE" == "ui" ]; then bench setup requirements --node; fi + +# install node-sass which is required for website theme test +cd ./apps/frappe || exit +yarn add node-sass@4.13.1 +cd ../.. + +bench start & +bench --site test_site reinstall --yes +if [ "$TYPE" == "server" ]; then bench --site test_site_producer reinstall --yes; fi +bench build --app frappe \ No newline at end of file diff --git a/.github/helper/install_dependencies.sh b/.github/helper/install_dependencies.sh new file mode 100644 index 0000000000..0ca509ef94 --- /dev/null +++ b/.github/helper/install_dependencies.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +python "${GITHUB_WORKSPACE}/.github/helper/roulette.py" +if [[ $? != 2 ]];then + exit; +fi + + # install wkhtmltopdf +wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz +tar -xf /tmp/wkhtmltox.tar.xz -C /tmp +sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf +sudo chmod o+x /usr/local/bin/wkhtmltopdf + +# install cups +sudo apt-get install libcups2-dev + +# install redis +sudo apt-get install redis-server + diff --git a/.travis/producer_db/mariadb.json b/.github/helper/producer_db/mariadb.json similarity index 89% rename from .travis/producer_db/mariadb.json rename to .github/helper/producer_db/mariadb.json index 988282a554..c1db0d765f 100644 --- a/.travis/producer_db/mariadb.json +++ b/.github/helper/producer_db/mariadb.json @@ -1,5 +1,6 @@ { - "db_host": "localhost", + "db_host": "127.0.0.1", + "db_port": 3306, "db_name": "test_frappe_producer", "db_password": "test_frappe", "allow_tests": true, diff --git a/.travis/producer_db/postgres.json b/.github/helper/producer_db/postgres.json similarity index 89% rename from .travis/producer_db/postgres.json rename to .github/helper/producer_db/postgres.json index 6426e99058..8b9d2a20fd 100644 --- a/.travis/producer_db/postgres.json +++ b/.github/helper/producer_db/postgres.json @@ -1,5 +1,6 @@ { - "db_host": "localhost", + "db_host": "127.0.0.1", + "db_port": 5432, "db_name": "test_frappe_producer", "db_password": "test_frappe", "db_type": "postgres", diff --git a/.travis/roulette.py b/.github/helper/roulette.py similarity index 100% rename from .travis/roulette.py rename to .github/helper/roulette.py diff --git a/.github/helper/run_tests.sh b/.github/helper/run_tests.sh new file mode 100644 index 0000000000..d7d50650da --- /dev/null +++ b/.github/helper/run_tests.sh @@ -0,0 +1,20 @@ +#!/bin/bash + +cd ~/frappe-bench/ || exit + +if [ "$TYPE" == "server" ]; then + + if [ "$DB" == "mariadb" ]; then + bench --verbose --site test_site run-tests --coverage + fi + + if [ "$DB" == "postgres" ]; then + bench --verbose --site test_site run-tests --coverage + fi + +fi + +if [ "$TYPE" == "ui" ]; then + bench --site test_site execute frappe.utils.install.complete_setup_wizard + bench --site test_site run-ui-tests frappe --headless +fi \ No newline at end of file diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml new file mode 100644 index 0000000000..83b34ece3a --- /dev/null +++ b/.github/workflows/ci-tests.yml @@ -0,0 +1,129 @@ +name: CI + +on: + pull_request: + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-latest + + strategy: + fail-fast: false + matrix: + include: + - DB: "mariadb" + TYPE: "server" + JOB_NAME: "Python MariaDB" + - DB: "postgres" + TYPE: "server" + JOB_NAME: "Python PostgreSQL" + - DB: "mariadb" + TYPE: "ui" + JOB_NAME: "UI MariaDB" + + name: ${{ matrix.JOB_NAME }} + + services: + mysql: + image: mariadb:10.3 + env: + MYSQL_ALLOW_EMPTY_PASSWORD: YES + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3 + + postgres: + image: postgres:9.5 + env: + POSTGRES_PASSWORD: travis + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + steps: + - name: Clone + uses: actions/checkout@v2 + + - name: Setup Python + uses: actions/setup-python@v2 + with: + python-version: 3.7 + + - name: Add to Hosts + run: | + echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts + echo "127.0.0.1 test_site_producer" | sudo tee -a /etc/hosts + + - name: Cache pip + uses: actions/cache@v2 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + ${{ runner.os }}- + + - name: Cache node modules + uses: actions/cache@v2 + env: + cache-name: cache-node-modules + with: + path: ~/.npm + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - uses: actions/cache@v2 + id: yarn-cache + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Cache cypress binary + uses: actions/cache@v2 + with: + path: ~/.cache + key: ${{ runner.os }}-cypress- + restore-keys: | + ${{ runner.os }}-cypress- + ${{ runner.os }}- + + - name: Install Dependencies + run: bash ${GITHUB_WORKSPACE}/.github/helper/install_dependencies.sh + + - name: Install + run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh + env: + DB: ${{ matrix.DB }} + TYPE: ${{ matrix.TYPE }} + + - name: Run Tests + run: bash ${GITHUB_WORKSPACE}/.github/helper/run_tests.sh + env: + DB: ${{ matrix.DB }} + TYPE: ${{ matrix.TYPE }} + + - name: Coverage + if: matrix.TYPE == 'server' + run: | + cp ~/frappe-bench/sites/.coverage ${GITHUB_WORKSPACE} + cd ${GITHUB_WORKSPACE} + pip install coveralls==2.2.0 + pip install coverage==4.5.4 + coveralls + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_TOKEN }} \ No newline at end of file diff --git a/.mergify.yml b/.mergify.yml index eae959b8a0..143659591f 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -3,7 +3,9 @@ pull_request_rules: conditions: - status-success=Sider - status-success=Semantic Pull Request - - status-success=Travis CI - Pull Request + - status-success=CI / Python MariaDB (pull_request) + - status-success=CI / Python PostgreSQL (pull_request) + - status-success=CI / UI MariaDB (pull_request) - status-success=security/snyk (frappe) - label!=dont-merge - label!=squash @@ -14,7 +16,9 @@ pull_request_rules: - name: Automatic squash on CI success and review conditions: - status-success=Sider - - status-success=Travis CI - Pull Request + - status-success=CI / Python MariaDB (pull_request) + - status-success=CI / Python PostgreSQL (pull_request) + - status-success=CI / UI MariaDB (pull_request) - status-success=security/snyk (frappe) - label!=dont-merge - label=squash diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index ffada0286f..0000000000 --- a/.travis.yml +++ /dev/null @@ -1,129 +0,0 @@ -language: python -dist: bionic - -addons: - hosts: - - test_site - - test_site_producer - mariadb: 10.3 - postgresql: 9.5 - firefox: latest - -services: - - xvfb - - mysql - -git: - depth: 1 - -cache: - pip: true - npm: true - yarn: true - directories: - # we also need to cache folder with Cypress binary - # https://docs.cypress.io/guides/guides/continuous-integration.html#Caching - - ~/.cache - - -matrix: - include: - - name: "Python 3.7 MariaDB" - python: 3.7 - env: DB=mariadb TYPE=server - script: bench --verbose --site test_site run-tests --coverage - - - name: "Python 3.7 PostgreSQL" - python: 3.7 - env: DB=postgres TYPE=server - script: bench --verbose --site test_site run-tests --coverage - - - name: "Cypress" - python: 3.7 - env: DB=mariadb TYPE=ui - before_script: - - bench --site test_site execute frappe.utils.install.complete_setup_wizard - script: bench --site test_site run-ui-tests frappe --headless - -before_install: - # do we really want to run travis? - - | - python ./.travis/roulette.py - if [[ $? != 2 ]];then - exit; - fi - - # install wkhtmltopdf - - wget -O /tmp/wkhtmltox.tar.xz https://github.com/frappe/wkhtmltopdf/raw/master/wkhtmltox-0.12.3_linux-generic-amd64.tar.xz - - tar -xf /tmp/wkhtmltox.tar.xz -C /tmp - - sudo mv /tmp/wkhtmltox/bin/wkhtmltopdf /usr/local/bin/wkhtmltopdf - - sudo chmod o+x /usr/local/bin/wkhtmltopdf - - # install cups - - sudo apt-get install libcups2-dev - -install: - - cd ~ - - source ./.nvm/nvm.sh - - nvm install 12 - - - pip install frappe-bench - - - bench init frappe-bench --skip-assets --python $(which python) --frappe-path $TRAVIS_BUILD_DIR - - - mkdir ~/frappe-bench/sites/test_site - - cp $TRAVIS_BUILD_DIR/.travis/consumer_db/$DB.json ~/frappe-bench/sites/test_site/site_config.json - - - if [ $TYPE == "server" ]; then - mkdir ~/frappe-bench/sites/test_site_producer; - cp $TRAVIS_BUILD_DIR/.travis/producer_db/$DB.json ~/frappe-bench/sites/test_site_producer/site_config.json; - fi - - - if [ $DB == "mariadb" ];then - mysql -u root -e "SET GLOBAL character_set_server = 'utf8mb4'"; - mysql -u root -e "SET GLOBAL collation_server = 'utf8mb4_unicode_ci'"; - - mysql -u root -e "CREATE DATABASE test_frappe_consumer"; - mysql -u root -e "CREATE USER 'test_frappe_consumer'@'localhost' IDENTIFIED BY 'test_frappe_consumer'"; - mysql -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe_consumer\`.* TO 'test_frappe_consumer'@'localhost'"; - - mysql -u root -e "CREATE DATABASE test_frappe_producer"; - mysql -u root -e "CREATE USER 'test_frappe_producer'@'localhost' IDENTIFIED BY 'test_frappe_producer'"; - mysql -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe_producer\`.* TO 'test_frappe_producer'@'localhost'"; - - mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"; - mysql -u root -e "FLUSH PRIVILEGES"; - fi - - - if [ $DB == "postgres" ];then - psql -c "CREATE DATABASE test_frappe_consumer" -U postgres; - psql -c "CREATE USER test_frappe_consumer WITH PASSWORD 'test_frappe'" -U postgres; - - psql -c "CREATE DATABASE test_frappe_producer" -U postgres; - psql -c "CREATE USER test_frappe_producer WITH PASSWORD 'test_frappe'" -U postgres; - fi - - - cd ./frappe-bench - - - sed -i 's/^watch:/# watch:/g' Procfile - - sed -i 's/^schedule:/# schedule:/g' Procfile - - - if [ $TYPE == "server" ]; then sed -i 's/^socketio:/# socketio:/g' Procfile; fi - - if [ $TYPE == "server" ]; then sed -i 's/^redis_socketio:/# redis_socketio:/g' Procfile; fi - - - if [ $TYPE == "ui" ]; then bench setup requirements --node; fi - - # install node-sass which is required for website theme test - - cd ./apps/frappe - - yarn add node-sass@4.13.1 - - cd ../.. - - - bench start & - - bench --site test_site reinstall --yes - - if [ $TYPE == "server" ]; then bench --site test_site_producer reinstall --yes; fi - - bench build --app frappe - -after_script: - - pip install coverage==4.5.4 - - pip install python-coveralls - - coveralls -b apps/frappe -d ../../sites/.coverage