JenspederM/kedro-databricks

View on GitHub
.github/workflows/publish.yml

Summary

Maintainability
Test Coverage
# .github/workflows/ci-cd.yml
on:
  push:
    branches:
      - main
      - master

jobs:
  test:
    name: Run tests
    if: ${{ !startsWith(github.event.head_commit.message, 'bump:') }}
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: ["3.9", "3.10", "3.11", "3.12"]
    steps:
      - uses: actions/checkout@v4
      # Download the Databricks CLI.
      # See https://github.com/databricks/setup-cli
      - uses: databricks/setup-cli@main
      - uses: eifinger/setup-rye@v3
        id: setup-rye
        with:
          version: "0.39.0"
      - name: Pin python-version ${{ matrix.python-version }}
        run: rye pin ${{ matrix.python-version }}
      - name: Install dependencies
        run: rye sync --no-lock
      - name: Lint code
        run: rye lint
      - name: Run tests
        run: |
          source .venv/bin/activate
          rye test
        env:
          DATABRICKS_HOST: ${{ secrets.DATABRICKS_HOST }}
          DATABRICKS_CLIENT_ID: ${{ secrets.DATABRICKS_CLIENT_ID }}
          DATABRICKS_CLIENT_SECRET: ${{ secrets.DATABRICKS_CLIENT_SECRET }}
      - name: Upload coverage reports to Codecov
        uses: codecov/codecov-action@v4.0.1
        with:
          token: ${{ secrets.CODECOV_TOKEN }}
  pypi-publish:
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    needs:
      - test
    strategy:
      matrix:
        python-version: ["3.9"]
    environment:
      name: pypi
      url: https://pypi.org/p/kedro-databricks
    permissions:
      id-token: write # IMPORTANT: this permission is mandatory for trusted publishing
    steps:
      - name: Check out
        uses: actions/checkout@v4
        with:
          token: "${{ secrets.PERSONAL_ACCESS_TOKEN }}"
          fetch-depth: 0
      - name: Create bump and changelog
        id: cz
        uses: commitizen-tools/commitizen-action@master
        with:
          github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          push: true
      # Download the Databricks CLI.
      # See https://github.com/databricks/setup-cli
      - uses: databricks/setup-cli@main
      - uses: eifinger/setup-rye@v3
        id: setup-rye
        with:
          version: "0.29.0"
          enable-cache: true
          cache-prefix: ${{ matrix.python-version }}
      - name: Pin python-version ${{ matrix.python-version }}
        if: steps.setup-rye.outputs.cache-hit != 'true'
        run: rye pin ${{ matrix.python-version }}
      - name: Install dependencies
        if: steps.setup-rye.outputs.cache-hit != 'true'
        run: |
          rye sync --no-lock
      - name: Build package
        run: rye build
      - name: Set Name and Version from pyproject.toml to output
        id: project
        run: |
          name=$(grep "^name" pyproject.toml -m 1 | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3 | tr "-" "_")
          version=$(grep "^version" pyproject.toml -m 1 | tr -s ' ' | tr -d '"' | tr -d "'" | cut -d' ' -f3)
          echo "NAME=$name" >> $GITHUB_OUTPUT
          echo "VERSION=$version" >> $GITHUB_OUTPUT
          echo "Releasing $name version $version"
          ls -laR dist
      - name: Publish package distributions to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1
      - name: Upload release to GitHub
        uses: softprops/action-gh-release@v1
        env:
          PACKAGE_NAME: ${{ steps.project.outputs.NAME }}
          VERSION: ${{ steps.project.outputs.VERSION }}
        with:
          tag_name: ${{ steps.cz.outputs.version }}
          token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
          files: |
            dist/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}-py3-none-any.whl
            dist/${{ env.PACKAGE_NAME }}-${{ env.VERSION }}.tar.gz