From 163a4166ebdf5f2c2dd179e511888a0ac9373e41 Mon Sep 17 00:00:00 2001 From: Jacky Hu Date: Thu, 31 Oct 2024 20:11:55 -0700 Subject: [PATCH] Refactor action to add resuable build workflow --- .github/workflows/build.yml | 76 ++++++++++ .github/workflows/code-quality-checks.yml | 168 +--------------------- 2 files changed, 81 insertions(+), 163 deletions(-) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 00000000..1b4f6a1c --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,76 @@ +name: Build and validate package + +on: + workflow_call: + inputs: + target_path: + description: "The path of the package or service to build" + required: true + type: string + run_test: + description: "Run lint and test" + required: true + type: boolean + +jobs: + build_package: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: [ 3.8, 3.9, "3.10", "3.11" ] + steps: + - name: Set up python ${{ matrix.python-version }} + id: setup-python + uses: actions/setup-python@v2 + with: + python-version: ${{ matrix.python-version }} + #---------------------------------------------- + # ----- install & configure poetry ----- + #---------------------------------------------- + - name: Install Poetry + uses: snok/install-poetry@v1 + with: + virtualenvs-create: true + virtualenvs-in-project: true + installer-parallel: true + + #---------------------------------------------- + # load cached venv if cache exists + #---------------------------------------------- + - name: Load cached venv + id: cached-poetry-dependencies + uses: actions/cache@v2 + with: + path: .venv + key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }} + #---------------------------------------------- + # install dependencies if cache does not exist + #---------------------------------------------- + - name: Install dependencies + if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' + run: poetry install --no-interaction --no-root + working-directory: ${{ github.workspace }}/${{ github.event.inputs.target_path }} + + #---------------------------------------------- + # install your root project, if required + #---------------------------------------------- + - name: Install library + run: poetry install --no-interaction + working-directory: ${{ github.event.inputs.target_path }} + + - name: Check-linting + if: ${{ inputs.run_test }} + run: poetry run black --check src + working-directory: ${{ github.event.inputs.target_path }} + + - name: Run unit test + if: ${{ inputs.run_test }} + run: poetry run python -m pytest tests/unit + working-directory: ${{ github.event.inputs.target_path }} + +# - name: Check types +# if: ${{ inputs.run_test }} +# run: | +# mkdir .mypy_cache # Workaround for bad error message "error: --install-types failed (no mypy cache directory)"; see https://github.com/python/mypy/issues/10768#issuecomment-2178450153 +# poetry run mypy --install-types --non-interactive src +# working-directory: ${{ github.event.inputs.target_path }} \ No newline at end of file diff --git a/.github/workflows/code-quality-checks.yml b/.github/workflows/code-quality-checks.yml index add4479a..36a30682 100644 --- a/.github/workflows/code-quality-checks.yml +++ b/.github/workflows/code-quality-checks.yml @@ -7,173 +7,15 @@ on: branches: - PECO-1803/connector-split jobs: - run-unit-tests: + validate-connector-core: runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8, 3.9, "3.10", "3.11"] - package: ["databricks_sql_connector_core", "databricks_sql_connector"] steps: - #---------------------------------------------- - # check-out repo and set-up python - #---------------------------------------------- - name: Check out repository uses: actions/checkout@v2 - - name: Set up python ${{ matrix.python-version }} - id: setup-python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - #---------------------------------------------- - # ----- install & configure poetry ----- - #---------------------------------------------- - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v2 - with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root - working-directory: ${{ github.workspace }}/${{ matrix.package }} - #---------------------------------------------- - # install your root project, if required - #---------------------------------------------- - - name: Install library - run: poetry install --no-interaction - working-directory: ${{ github.workspace }}/${{ matrix.package }} - #---------------------------------------------- - # run test suite - #---------------------------------------------- - - name: Run tests - if: ${{ maxtrix.package != 'databricks_sql_connector'}} - run: poetry run python -m pytest tests/unit - working-directory: ${{ github.workspace }}/${{ matrix.package }} - check-linting: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8, 3.9, "3.10"] - package: ["databricks_sql_connector_core"] - steps: - #---------------------------------------------- - # check-out repo and set-up python - #---------------------------------------------- - - name: Check out repository - uses: actions/checkout@v2 - - name: Set up python ${{ matrix.python-version }} - id: setup-python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - #---------------------------------------------- - # ----- install & configure poetry ----- - #---------------------------------------------- - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v2 - with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root - working-directory: ${{ github.workspace }}/${{ matrix.package }} - #---------------------------------------------- - # install your root project, if required - #---------------------------------------------- - - name: Install library - run: poetry install --no-interaction - working-directory: ${{ github.workspace }}/${{ matrix.package }} - #---------------------------------------------- - # black the code - #---------------------------------------------- - - name: Black - run: poetry run black --check src - working-directory: ${{ github.workspace }}/${{ matrix.package }} - - check-types: - runs-on: ubuntu-latest - strategy: - matrix: - python-version: [3.8, 3.9, "3.10"] - package: ["databricks_sql_connector_core"] - steps: - #---------------------------------------------- - # check-out repo and set-up python - #---------------------------------------------- - - name: Check out repository - uses: actions/checkout@v2 - - name: Set up python ${{ matrix.python-version }} - id: setup-python - uses: actions/setup-python@v2 - with: - python-version: ${{ matrix.python-version }} - #---------------------------------------------- - # ----- install & configure poetry ----- - #---------------------------------------------- - - name: Install Poetry - uses: snok/install-poetry@v1 - with: - virtualenvs-create: true - virtualenvs-in-project: true - installer-parallel: true - #---------------------------------------------- - # load cached venv if cache exists - #---------------------------------------------- - - name: Load cached venv - id: cached-poetry-dependencies - uses: actions/cache@v2 + - name: Build + uses: ./.github/workflows/build with: - path: .venv - key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ github.event.repository.name }}-${{ hashFiles('**/poetry.lock') }} - #---------------------------------------------- - # install dependencies if cache does not exist - #---------------------------------------------- - - name: Install dependencies - if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' - run: poetry install --no-interaction --no-root - working-directory: ${{ github.workspace }}/${{ matrix.package }} - #---------------------------------------------- - # install your root project, if required - #---------------------------------------------- - - name: Install library - run: poetry install --no-interaction - working-directory: ${{ github.workspace }}/${{ matrix.package }} - #---------------------------------------------- - # mypy the code - #---------------------------------------------- - - name: Mypy - run: | - mkdir .mypy_cache # Workaround for bad error message "error: --install-types failed (no mypy cache directory)"; see https://github.com/python/mypy/issues/10768#issuecomment-2178450153 - poetry run mypy --install-types --non-interactive src - working-directory: ${{ github.workspace }}/${{ matrix.package }} + target_path: "databricks_sql_connector_core" + run_test: true