ci: Port CI test from Travis to Github Actions (#24846)
diff --git a/.github/helper/install.sh b/.github/helper/install.sh
new file mode 100644
index 0000000..8c87f23
--- /dev/null
+++ b/.github/helper/install.sh
@@ -0,0 +1,42 @@
+#!/bin/bash
+
+cd ~ || exit
+
+sudo apt-get install redis-server
+
+nvm install 10
+
+pip install frappe-bench
+
+git clone https://github.com/frappe/frappe --branch "${GITHUB_BASE_REF}" --depth 1
+bench init --skip-assets --frappe-path ~/frappe --python "$(which python)" frappe-bench
+
+mkdir ~/frappe-bench/sites/test_site
+cp -r "${GITHUB_WORKSPACE}/.github/helper/site_config.json" ~/frappe-bench/sites/test_site/
+
+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 USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
+mysql --host 127.0.0.1 --port 3306 -u root -e "CREATE DATABASE test_frappe"
+mysql --host 127.0.0.1 --port 3306 -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'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"
+
+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
+sudo apt-get install libcups2-dev
+
+cd ~/frappe-bench || exit
+
+sed -i 's/watch:/# watch:/g' Procfile
+sed -i 's/schedule:/# schedule:/g' Procfile
+sed -i 's/socketio:/# socketio:/g' Procfile
+sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile
+
+bench get-app erpnext "${GITHUB_WORKSPACE}"
+bench start &
+bench --site test_site reinstall --yes
\ No newline at end of file
diff --git a/.github/helper/run_tests.sh b/.github/helper/run_tests.sh
new file mode 100644
index 0000000..4574ac2
--- /dev/null
+++ b/.github/helper/run_tests.sh
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+cd ~/frappe-bench/ || exit
+
+
+if [ "$TYPE" == "server" ]; then
+ bench --site test_site run-tests --app erpnext --coverage
+fi
+
+if [ "$TYPE" == "patch" ]; then
+ wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz
+ bench --site test_site --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz
+ bench --site test_site migrate
+fi
diff --git a/.travis/site_config.json b/.github/helper/site_config.json
similarity index 89%
rename from .travis/site_config.json
rename to .github/helper/site_config.json
index 572bbd0..60ef80c 100644
--- a/.travis/site_config.json
+++ b/.github/helper/site_config.json
@@ -1,4 +1,6 @@
{
+ "db_host": "127.0.0.1",
+ "db_port": 3306,
"db_name": "test_frappe",
"db_password": "test_frappe",
"auto_email_id": "test@example.com",
diff --git a/.github/workflows/ci-tests.yml b/.github/workflows/ci-tests.yml
new file mode 100644
index 0000000..f2cf423
--- /dev/null
+++ b/.github/workflows/ci-tests.yml
@@ -0,0 +1,94 @@
+name: CI
+
+on:
+ pull_request:
+ workflow_dispatch:
+
+jobs:
+ test:
+ runs-on: ubuntu-latest
+
+ strategy:
+ fail-fast: false
+ matrix:
+ include:
+ - TYPE: "server"
+ JOB_NAME: "Server"
+ - TYPE: "patch"
+ JOB_NAME: "Patch"
+
+ 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
+
+ steps:
+ - name: Clone
+ uses: actions/checkout@v2
+
+ - name: Setup Python
+ uses: actions/setup-python@v2
+ with:
+ python-version: 3.6
+
+ - name: Add to Hosts
+ run: echo "127.0.0.1 test_site" | 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: Install
+ run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
+
+ - name: Run Tests
+ run: bash ${GITHUB_WORKSPACE}/.github/helper/run_tests.sh
+ env:
+ 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 }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 77d427e..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,69 +0,0 @@
-language: python
-dist: trusty
-
-git:
- depth: 1
-
-cache:
- - pip
-
-addons:
- hosts: test_site
- mariadb: 10.3
-
-jobs:
- include:
- - name: "Python 3.6 Server Side Test"
- python: 3.6
- script: bench --site test_site run-tests --app erpnext --coverage
-
- - name: "Python 3.6 Patch Test"
- python: 3.6
- before_script:
- - wget http://build.erpnext.com/20171108_190013_955977f8_database.sql.gz
- - bench --site test_site --force restore ~/frappe-bench/20171108_190013_955977f8_database.sql.gz
- script: bench --site test_site migrate
-
-install:
- - cd ~
- - nvm install 10
-
- - pip install frappe-bench
-
- - git clone https://github.com/frappe/frappe --branch $TRAVIS_BRANCH --depth 1
- - bench init --skip-assets --frappe-path ~/frappe --python $(which python) frappe-bench
-
- - mkdir ~/frappe-bench/sites/test_site
- - cp -r $TRAVIS_BUILD_DIR/.travis/site_config.json ~/frappe-bench/sites/test_site/
-
- - 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"
- - mysql -u root -e "CREATE USER 'test_frappe'@'localhost' IDENTIFIED BY 'test_frappe'"
- - mysql -u root -e "GRANT ALL PRIVILEGES ON \`test_frappe\`.* TO 'test_frappe'@'localhost'"
-
- - mysql -u root -e "UPDATE mysql.user SET Password=PASSWORD('travis') WHERE User='root'"
- - mysql -u root -e "FLUSH PRIVILEGES"
-
- - 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
- - sudo apt-get install libcups2-dev
-
- - cd ~/frappe-bench
-
- - sed -i 's/watch:/# watch:/g' Procfile
- - sed -i 's/schedule:/# schedule:/g' Procfile
- - sed -i 's/socketio:/# socketio:/g' Procfile
- - sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile
-
- - bench get-app erpnext $TRAVIS_BUILD_DIR
- - bench start &
- - bench --site test_site reinstall --yes
-
-after_script:
- - pip install coverage==4.5.4
- - pip install python-coveralls
- - coveralls -b apps/erpnext -d ../../sites/.coverage