From a283dbdd1ac92da02046b2d6b2e06c1c9cee4795 Mon Sep 17 00:00:00 2001 From: Marcin Maciaszek Date: Wed, 8 Apr 2020 09:41:19 +0200 Subject: [PATCH] Disable travis and update GitHub Actions (#149) --- .github/workflows/pipeline.yml | 194 ++++++++++++++++-- .github/workflows/rfhub2_push_and_deploy.yml | 67 ++++++ .travis.yml | 43 ---- DEVELOPMENT.md | 4 + build_ui.sh | 7 +- rfhub2/version.py | 2 +- tests/acceptance/conf/default.args | 1 - tests/acceptance/conf/postgres.args | 1 - tests/acceptance/conf/venv_wrapper.args | 1 - .../resources/e2e_keywords.resource | 4 +- tests/acceptance/resources/keywords.resource | 6 +- 11 files changed, 254 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/rfhub2_push_and_deploy.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.yml index 70581285..b517c41c 100644 --- a/.github/workflows/pipeline.yml +++ b/.github/workflows/pipeline.yml @@ -1,33 +1,183 @@ name: rfhub2-pipeline -on: - push: - branches: - - '*' - pull_request: - branches: - - master +on: push jobs: - build: + test: + name: Build and test rfhub2 + runs-on: ubuntu-latest + services: + postgres: + image: postgres + env: + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + + strategy: + matrix: + node-version: [13.x] + python-version: [3.6, 3.7, 3.8] + + steps: + - uses: actions/checkout@v2 + + - name: Run Find changed files. + id: changed_files + uses: tj-actions/verify-changed-files@v2 + with: + files: "rfhub2/version.py" + + - name: Set up Python ${{ matrix.python-version }} + if: steps.changed_files.outputs.files_changed == 'true' + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + # - name: Cache Python packages + # uses: actions/cache@v2 + # id: cache-pip + # with: + # path: ~/.cache/pip + # key: ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt', '**/requirements-postgres.txt') }} + # restore-keys: | + # ${{ runner.os }}-pip-${{ matrix.python-version }}-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt', '**/requirements-postgres.txt') }} + + # - name: Install Python dependencies + # run: | + # pip install -r requirements.txt + # pip install -r requirements-dev.txt + # pip install -r requirements-postgres.txt + + # - name : Unit tests and coverage check + # run: | + # python -m coverage run --source rfhub2 -m unittest tests + # python -m coverage xml + + # - name: Black check + # run: | + # black --check rfhub2 tests + + # - name: Upload coverage to Codecov + # uses: codecov/codecov-action@v1 + # with: + # file: ./coverage.xml + # flags: unittests + # fail_ci_if_error: true + + # - name: Use Node.js ${{ matrix.node-version }} + # uses: actions/setup-node@v1 + # with: + # node-version: ${{ matrix.node-version }} + + # - name: Install yarn dependencies + # uses: bahmutov/npm-install@v1 + # with: + # working-directory: frontend + + # - uses: nanasess/setup-chromedriver@master + # - run: | + # export DISPLAY=:99 + # chromedriver --url-base=/wd/hub & + # sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & + + # - name: Build UI + # run: ./build_ui.sh + # - name: Build rfhub2 python package + # run: python setup.py sdist bdist_wheel + + # - uses: actions/upload-artifact@master + # with: + # name: rfhub2_whl_${{ matrix.python-version }} + # path: /home/runner/work/rfhub2/rfhub2/dist + + # - name: Install rfhub2 in env + # run: pip install $(find dist -type f -iname "rfhub2-*.whl")[postgresql] + + # - name: Run default Robot tests + # run: | + # robot -A tests/acceptance/conf/default.args -d results/ tests/acceptance + + # - name: Upload default tests results + # if: failure() + # uses: actions/upload-artifact@v1 + # with: + # name: Default tests + # path: /home/runner/work/rfhub2/rfhub2/results/ + + # - name: Run postgres Robot Framework tests + # run: | + # robot -A tests/acceptance/conf/postgres.args tests/acceptance + + # - name: Upload postgres tests results + # if: failure() + # uses: actions/upload-artifact@v1 + # with: + # name: Postgres tests + # path: /home/runner/work/rfhub2/rfhub2/log.html + + package_check: + name: Install rfhub2 package in separate env + needs: test + if: github.event_name == 'pull_request' runs-on: ubuntu-latest + strategy: matrix: python-version: [3.6, 3.7, 3.8] - + steps: - - uses: actions/checkout@v2 - - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v1 - with: - python-version: ${{ matrix.python-version }} - - name: Install dependencies - run: | - pip install -r requirements.txt -r requirements-dev.txt -r requirements-postgres.txt - - name: Display Python version - run: python -c "import sys; print(sys.version)" - - name : Tests - run: | - python -m coverage run --source rfhub2 -m unittest tests + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ matrix.python-version }} + + # - uses: actions/download-artifact@master + # with: + # name: rfhub2_whl_${{ matrix.python-version }} + # path: /home/runner/work/rfhub2/rfhub2/dist + + # - name: Install rfhub2 in env + # run: pip install $(find dist -type f -iname "rfhub2-*.whl")[postgresql] + + push_and_deploy: + name: Push and deploy rfhub2 + needs: package_check + if: github.extract_branch.outputs.branch == 'master' + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python 3.6 + uses: actions/setup-python@v1 + with: + python-version: 3.6 + + # - uses: actions/download-artifact@master + # with: + # name: rfhub2_whl_3.6 + # path: /home/runner/work/rfhub2/rfhub2/dist + # - name: Publish a Python distribution to PyPI + # uses: pypa/gh-action-pypi-publish@master + # with: + # user: __token__ + # password: ${{ secrets.pypi_password }} + + # - name: Deploy to Heroku + # uses: Suvink/heroku-static@v0.3 + # with: + # heroku_app_name: rfhub2-demo + # heroku_email: heroku@email.com + # dontuseforce: false + # env: + # HEROKU_TOKEN: '${{ secrets.HEROKU_AUTH_TOKEN }}' + # BOT_TOKEN: '${{ secrets.BOT_TOKEN }}' + # CHAT_ID: '${{ secrets.CHAT_ID }}' \ No newline at end of file diff --git a/.github/workflows/rfhub2_push_and_deploy.yml b/.github/workflows/rfhub2_push_and_deploy.yml new file mode 100644 index 00000000..32725fa1 --- /dev/null +++ b/.github/workflows/rfhub2_push_and_deploy.yml @@ -0,0 +1,67 @@ +name: rfhub2-push-and-deploy + +on: + push: + branches: + - master + paths: + - 'rfhub2/version.py' + +jobs: + push: + name: Push rfhub2 to PyPI + if: steps.extract_branch.outputs.branch == 'master' + needs: test + runs-on: ubuntu-latest + node-version: 13.x + python-version: 3.8 + + steps: + - uses: actions/checkout@v2 + + - name: Set up Python ${{ python-version }} + uses: actions/setup-python@v1 + with: + python-version: ${{ python-version }} + + - name: Cache Python packages + uses: actions/cache@v1 + id: cache-pip + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt', '**/requirements-postgres.txt') }} + restore-keys: | + ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt', '**/requirements-dev.txt', '**/requirements-postgres.txt') }} + + - name: Use Node.js ${{ node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ node-version }} + + - name: Install yarn dependencies + uses: bahmutov/npm-install@v1 + with: + working-directory: frontend + + - name: Build UI + run: ./build_ui.sh + + - name: Build rfhub2 python package + run: python setup.py sdist bdist_wheel + + - name: Publish a Python distribution to PyPI + uses: pypa/gh-action-pypi-publish@master + with: + user: __token__ + password: ${{ secrets.pypi_password }} + + - name: Deploy to Heroku + uses: Suvink/heroku-static@v0.3 + with: + heroku_app_name: rfhub2-demo + heroku_email: heroku@email.com + dontuseforce: false + env: + HEROKU_TOKEN: '${{ secrets.HEROKU_AUTH_TOKEN }}' + BOT_TOKEN: '${{ secrets.BOT_TOKEN }}' + CHAT_ID: '${{ secrets.CHAT_ID }}' diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 9e38fd6a..00000000 --- a/.travis.yml +++ /dev/null @@ -1,43 +0,0 @@ -language: python -python: - - 3.6 -sudo: required -addons: - chrome: stable -services: - - xvfb - - postgresql -cache: - pip: true - yarn: true - directories: - - frontend/node_modules -before_install: - - sudo apt-key adv --fetch-keys http://dl.yarnpkg.com/debian/pubkey.gpg - - echo "deb http://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list - - sudo apt-get update -qq - - sudo apt-get install -y -qq yarn -install: - - pip install -r requirements.txt -r requirements-dev.txt -r requirements-postgres.txt - - pushd frontend; yarn install; popd -before_script: - - wget "https://chromedriver.storage.googleapis.com/80.0.3987.106/chromedriver_linux64.zip" - - unzip chromedriver_linux64.zip - - sudo mv chromedriver /usr/local/bin - - "export DISPLAY=:99.0" -script: - - python -m coverage run --source rfhub2 -m unittest -b tests - - black --check -t py36 rfhub2 tests - - ./build_ui.sh - - python setup.py sdist bdist_wheel - - rm test.db #ensure we start clean slate - - ./scripts/install_package_in_venv.sh - - robot -A tests/acceptance/conf/default.args tests/acceptance - - robot -A tests/acceptance/conf/postgres.args tests/acceptance -after_success: - - codecov - - python publish_pypi.py -deploy: - provider: heroku - app: rfhub2-demo - api_key: $HEROKU_AUTH_TOKEN diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index eea60aef..64b7bbba 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -59,6 +59,10 @@ To create frontend build and add its files to rfhub2 package static files direct ``` ./build_ui.sh ``` +You can specify *clean* parameter, if there is need to clean static files +``` +./build_ui.sh clean +``` ### Populate application with data To populate application running on localhost: diff --git a/build_ui.sh b/build_ui.sh index 3d40b6d9..05c49500 100755 --- a/build_ui.sh +++ b/build_ui.sh @@ -1,8 +1,11 @@ #!/bin/bash +# !!!Please use clean paramater for this bash script if you need to clean static files.!!! pushd frontend yarn build popd -rm -r rfhub2/static/* -rm rfhub2/templates/index.html +if [ "$1" == "clean" ]; then + rm -r rfhub2/static/* + rm rfhub2/templates/index.html +fi cp -r frontend/build/* rfhub2/static mv rfhub2/static/index.html rfhub2/templates/index.html \ No newline at end of file diff --git a/rfhub2/version.py b/rfhub2/version.py index d2687b77..7918a438 100644 --- a/rfhub2/version.py +++ b/rfhub2/version.py @@ -1 +1 @@ -version = "0.18" +version = "0.19" diff --git a/tests/acceptance/conf/default.args b/tests/acceptance/conf/default.args index 2a973869..450b6206 100644 --- a/tests/acceptance/conf/default.args +++ b/tests/acceptance/conf/default.args @@ -1,4 +1,3 @@ # default arguments; any other argument files should include # this file. -C ansi ---variable ACTIVATE_VENV:. atests-venv/bin/activate && diff --git a/tests/acceptance/conf/postgres.args b/tests/acceptance/conf/postgres.args index 7ad87f6e..3487be85 100644 --- a/tests/acceptance/conf/postgres.args +++ b/tests/acceptance/conf/postgres.args @@ -1,5 +1,4 @@ # default arguments; any other argument files should include # this file. -C ansi ---variable ACTIVATE_VENV:. atests-venv/bin/activate && --variable DB_URI:RFHUB_DB_URI=postgresql://postgres:postgres@localhost:5432/postgres diff --git a/tests/acceptance/conf/venv_wrapper.args b/tests/acceptance/conf/venv_wrapper.args index 44305d7f..634ca60d 100644 --- a/tests/acceptance/conf/venv_wrapper.args +++ b/tests/acceptance/conf/venv_wrapper.args @@ -1,4 +1,3 @@ # default arguments; any other argument files should include # this file. -C ansi ---variable ACTIVATE_VENV: diff --git a/tests/acceptance/resources/e2e_keywords.resource b/tests/acceptance/resources/e2e_keywords.resource index a266ce8f..6b41f0bf 100644 --- a/tests/acceptance/resources/e2e_keywords.resource +++ b/tests/acceptance/resources/e2e_keywords.resource @@ -3,11 +3,11 @@ Library SeleniumLibrary *** Keywords *** Open Browser With App On Mainpage - Open Browser url=localhost:8000 browser=gc + Open Browser http://localhost:8000 Headless Chrome Maximize Browser Window Navigate To Main Page - Go To localhost:8000 + Go To http://localhost:8000 Collections Count On Main Page Should Be ${n} Reload Page diff --git a/tests/acceptance/resources/keywords.resource b/tests/acceptance/resources/keywords.resource index 96bd466d..aa8c9bcc 100644 --- a/tests/acceptance/resources/keywords.resource +++ b/tests/acceptance/resources/keywords.resource @@ -13,7 +13,7 @@ Start Rfhub2 ... As a side effect this creates a suite variable named \${rfhub process}, ... which is used by the 'Stop rfhub2' keyword. Remove File ${DB_PATH} - ${rfhub2_process} Start Process ${ACTIVATE_VENV} ${DB_URI} rfhub2 + ${rfhub2_process} Start Process ${DB_URI} rfhub2 ... shell=True stdout=api_logs.log stderr=stderr_logs.log Set Suite Variable ${rfhub2_process} Wait Until Keyword Succeeds 20 seconds 0.5 second @@ -32,7 +32,7 @@ Run Cli Package With Options ... Attempt to run the rfhub2-cli package with the given options ... The stdout of the process will be in a test suite ... variable named \${output} - ${output} Run ${ACTIVATE_VENV} rfhub2-cli ${options} + ${output} Run rfhub2-cli ${options} Set Suite Variable ${output} Run Cli Package @@ -40,7 +40,7 @@ Run Cli Package ... Attempt to run the rfhub2-cli package with the default options ... The stdout of the process will be in a test suite ... variable named \${output} - ${output} Run ${ACTIVATE_VENV} rfhub2-cli + ${output} Run rfhub2-cli Set Suite Variable ${output} Output Should Contain