diff --git a/.github/workflows/branch-name-check.yml b/.github/workflows/branch-name-check.yml new file mode 100644 index 00000000000..fcefb238790 --- /dev/null +++ b/.github/workflows/branch-name-check.yml @@ -0,0 +1,55 @@ +name: Branch Name Check +# Description: Checks that the source branch name is valid for the target branch. This is used to ensure that PRs are only allowed to merge into the develop branch if they are from a feature, hotfix or release branch. Similarly, PRs are only allowed to merge into the main branch if they are from a hotfix or release branch. + +on: + pull_request: + branches: + - develop + - main + types: [opened, synchronize] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + check-branch-name: + runs-on: ubuntu-latest + outputs: + source-branch: ${{ steps.branch-name-check.outputs.source-branch }} + target-branch: ${{ steps.branch-name-check.outputs.target-branch }} + steps: + # Extract the source and target branches for the PR + - name: Extract branch names + id: branch-name-check + run: | + source_branch=$(jq -r .pull_request.head.ref "$GITHUB_EVENT_PATH") + target_branch=$(jq -r .pull_request.base.ref "$GITHUB_EVENT_PATH") + + echo "Source-branch=$source_branch" >> $GITHUB_OUTPUT + echo "target-branch=$target_branch" >> $GITHUB_OUTPUT + + - name: Show Output result for source-branch and target-branch + run: | + echo "source-branch=${{ steps.branch-name-check.outputs.source-branch }}" + echo "target-branch=${{ steps.branch-name-check.outputs.target-branch }}" + + - name: Check branch name for develop PRs + if: ${{ steps.branch-name-check.outputs.target-branch == 'develop' }} + run: | + if [[ "${{ steps.branch-name-check.outputs.source-branch }}" =~ ^(main|feature/.*|hotfix/.*|release/[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?)$ ]]; then + echo "Branch name is valid" + else + echo "Invalid branch name. Branches must follow the GitFlow naming convention to be allowed to merge into the develop branch." + exit 1 + fi + + - name: Check branch name for main PRs + if: ${{ steps.branch-name-check.outputs.target-branch == 'main' }} + run: | + if [[ "${{ steps.branch-name-check.outputs.source-branch }}" =~ ^(hotfix/.*|release/[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?)$ ]]; then + echo "PR is from a hotfix or release branch and targets the main branch" + else + echo "PR is not from a hotfix or release branch. Pull requests must be from a hotfix or release branch and target the main branch" + exit 1 + fi \ No newline at end of file diff --git a/.github/workflows/linting.yml b/.github/workflows/linting.yml new file mode 100644 index 00000000000..bba6d0a6834 --- /dev/null +++ b/.github/workflows/linting.yml @@ -0,0 +1,63 @@ +name: General Linting + +env: + OPENBB_ENABLE_QUICK_EXIT: true + OPENBB_LOG_COLLECT: false + OPENBB_USE_ION: false + OPENBB_USE_PROMPT_TOOLKIT: false + PIP_DEFAULT_TIMEOUT: 100 + +on: + push: + branches: + - 'feature/*' + - 'hotfix/*' + - 'release/[0-9]+\.[0-9]+\.[0-9]+(rc[0-9]+)?' + +# Cancel previous runs that are not yet completed. +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + code-linting: + name: Running General Linting Tools + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@2541b1294d2704b0964813337f33b291d3f8596b # actions/checkout v3.0.2 + + - name: Setup Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + architecture: x64 + + - uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-linting-${{ hashFiles('**/poetry.lock') }} + restore-keys: ${{ runner.os }}-linting-${{ hashFiles('**/poetry.lock') }} + + - run: pip install bandit black codespell mypy==0.982 pyupgrade safety pylint==2.15.2 packaging==22 ruff + - run: pip install types-pytz types-requests types-termcolor types-tabulate types-PyYAML types-python-dateutil types-setuptools types-six + - run: bandit -x ./tests -r . || true + - run: black --diff --check . + - run: codespell --ignore-words-list=commun,statics,ro,zar,zlot,jewl,ba,buil,coo,ether,hist,hsi,mape,navagation,operatio,pres,ser,yeld,shold,ist,varian,datas,ake,creat,vie,hel,ket,toke,certi,buidl,ot,te --quiet-level=2 --skip=./tests,.git,*.css,*.csv,*.html,*.ini,*.ipynb,*.js,*.json,*.lock,*.scss,*.txt,*.yaml,./build/pyinstaller,./website/config.toml + - run: ruff . + - run: mypy --ignore-missing-imports openbb_terminal + - run: shopt -s globstar && pyupgrade --py38-plus **/*.py + - run: safety check + - run: | + pylint terminal.py openbb_terminal tests + + markdown-link-check: + name: Markdown Linting + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + name: Check out the code + - name: Lint Code Base + uses: docker://avtodev/markdown-lint:v1 + with: + args: "./*.md ./changelogs/*.md ./openbb_terminal/**/*.md ./discordbot/**/*.md" \ No newline at end of file diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml new file mode 100644 index 00000000000..d58a70199da --- /dev/null +++ b/.github/workflows/unit-test.yml @@ -0,0 +1,320 @@ +name: Unit Test + +env: + OPENBB_ENABLE_QUICK_EXIT: true + OPENBB_LOG_COLLECT: false + OPENBB_USE_ION: false + OPENBB_USE_PROMPT_TOOLKIT: false + PIP_DEFAULT_TIMEOUT: 100 + +on: + pull_request: + branches: + - develop + - main + types: [opened, synchronize] + + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + # Check for changes to Python code + python-changes: + name: Check for changes to Python code + runs-on: ubuntu-latest + outputs: + python-changes: ${{ steps.python-changes.outputs.python-changes }} + steps: + - name: Checkout Code + uses: actions/checkout@v1 + + # Check for changes to Python code to avoid running tests unnecessarily + - name: Check for changes to Python code + id: python-changes + run: | + # Extract the source and target branches for the PR + source_branch=$(jq -r .pull_request.head.ref "$GITHUB_EVENT_PATH") + target_branch=$(jq -r .pull_request.base.ref "$GITHUB_EVENT_PATH") + + # Check for changes to Python code to avoid running tests unnecessarily + if git diff --name-only origin/$target_branch HEAD | grep -E '\.py$'; then + echo "python-changes=true" >> $GITHUB_OUTPUT + else + echo "python-changes=false" >> $GITHUB_OUTPUT + fi + + + - name: Show Output result for python-changes + run: | + echo "python-changes=${{ steps.python-changes.outputs.python-changes }}" + + base-test: + name: Base Tests - Ubuntu-latest - Python 3.9 + needs: [python-changes] + runs-on: ubuntu-latest + if: needs.python-changes.outputs.python-changes == 'true' + steps: + - name: Show Output result for python-changes + run: echo "python-changes=${{ needs.python-changes.outputs.python-changes }}" + + - name: Setup Python 3.9 + uses: actions/setup-python@v4 + with: + python-version: "3.9" + architecture: x64 + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.1.13 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-v1-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction -E optimization + + - name: Run tests + env: + MPLBACKEND: Agg + run: | + source $VENV + pytest tests/ --optimization + + - name: Start Terminal and exit + run: | + source $VENV + python terminal.py + + tests-python: + name: Vanilla Python Tests - ${{ matrix.python-version }} + needs: [python-changes, base-test] + runs-on: ${{ matrix.os }} + if: needs.python-changes.outputs.python-changes == 'true' && github.event.pull_request.base.ref == 'develop' + strategy: + fail-fast: true + matrix: + python-version: ["3.8", "3.9", "3.10"] + os: [ubuntu-latest] + exclude: + - os: ubuntu-latest + python-version: "3.9" + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.1.13 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-v1-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction -E optimization + + - name: List installed packages + shell: bash -l {0} + run: | + source $VENV + pip list + + - name: Run tests + env: + MPLBACKEND: Agg + run: | + source $VENV + pytest tests/ --optimization + + - name: Start Terminal and exit + run: | + source $VENV + python terminal.py + + full-test: + name: Full Test Suite - (${{ matrix.python-version }}, ${{ matrix.os }}) + needs: [base-test] + runs-on: ${{ matrix.os }} + if: github.event.pull_request.merged == true + strategy: + fail-fast: true + matrix: + python-version: ["3.8", "3.9", "3.10"] + os: [ubuntu-latest, macos-latest] + exclude: + - os: ubuntu-latest + python-version: "3.9" + steps: + - name: Checkout Code + uses: actions/checkout@v3 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + architecture: x64 + + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + version: 1.1.13 + virtualenvs-create: true + virtualenvs-in-project: true + + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v3 + with: + path: .venv + key: venv-${{ runner.os }}-v1-${{ hashFiles('**/poetry.lock') }} + + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction -E optimization + + - name: List installed packages + shell: bash -l {0} + run: | + source $VENV + pip list + + - name: Run tests + env: + MPLBACKEND: Agg + run: | + source $VENV + pytest tests/ --optimization + + - name: Start Terminal and exit + run: | + source $VENV + python terminal.py + + tests-conda: + name: Anaconda Python Tests - (${{ matrix.python-version }}, ${{ matrix.os }}) + needs: [base-test] + runs-on: ${{ matrix.os }}-latest + if: github.event.pull_request.merged == true + strategy: + fail-fast: false + matrix: + os: ["ubuntu", "windows"] + python-version: ["3.9"] + dependencies: [""] + include: + - os: ubuntu + python: 3.9 + - os: windows + python: 3.9 + env: + OS: ${{ matrix.os }} + PYTHON: ${{ matrix.python }} + PYTHONNOUSERSITE: 1 + + steps: + - name: Set git to use LF + if: runner.os == 'Windows' + run: | + git config --global core.autocrlf false + git config --global core.eol lf + + - name: Checkout + uses: actions/checkout@v3 + with: + # Need to fetch more than the last commit so that setuptools-scm can + # create the correct version string. If the number of commits since + # the last release is greater than this, the version still be wrong. + # Increase if necessary. + fetch-depth: 100 + # The GitHub token is preserved by default but this job doesn't need + # to be able to push to GitHub. + persist-credentials: false + + - name: Setup caching for conda packages + uses: actions/cache@v3 + with: + path: ~/conda_pkgs_dir + key: conda-${{ runner.os }}-v1-${{ matrix.python }}-${{ hashFiles('build/conda/conda-3-9-env-full.yaml') }} + + - name: Setup Miniconda + uses: conda-incubator/setup-miniconda@v2 + with: + python-version: ${{ matrix.python }} + miniconda-version: "latest" + auto-update-conda: true + channels: conda-forge,defaults + show-channel-urls: true + channel-priority: flexible + environment-file: build/conda/conda-3-9-env.yaml + activate-environment: testing + # Needed for caching + use-only-tar-bz2: true + + - name: Update Temp permissions on windows + if: runner.os == 'Windows' + shell: cmd /C CALL {0} + run: >- + c:\windows\system32\icacls C:\Users\runneradmin\AppData\Local\Temp /grant "everyone":F /t + + - name: Get pip cache dir + shell: bash -l {0} + id: pip-cache + run: | + echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT + + - name: pip cache + uses: actions/cache@v3 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-v1-3-9-pip-${{ hashFiles('requirements-full.txt') }} + restore-keys: | + ${{ runner.os }}-v1-pip- + + - name: Uninstall Brotlipy + shell: bash -l {0} + run: | + conda remove brotlipy -y + + - name: Install dependencies (Bash) + shell: bash -l {0} + run: | + pip install --requirement requirements-full.txt + + - name: List installed packages (Bash) + shell: bash -l {0} + run: | + conda list + pip list + + - name: Run tests (Bash) + env: + MPLBACKEND: Agg + shell: bash -l {0} + run: pytest tests/ -m "not linux" --optimization + + - name: Start Terminal and exit + shell: bash -l {0} + run: python terminal.py \ No newline at end of file