helm / chart-testing-action

A GitHub Action to lint and test Helm charts
https://github.com/helm/chart-testing
Apache License 2.0
245 stars 71 forks source link

Option to use global Python install #142

Closed AndersBennedsgaard closed 7 months ago

AndersBennedsgaard commented 7 months ago

When using Python for another step than for running ct, you might be surprised that this action activates a Python environment which might mess up your later actions (I know I was).

We use Helm JSON schemas with references to external schemas to validate the user inputs when using our charts, but in order to decrease the amount of network traffic, we have created a Python script which de-references all external schemas and just saves them as one big JSON blob in values.schema.json. Now, when we want to use ct to lint and test changes to our charts, we would use something like:

name: Chart linting

on:
  # Only pull requests, since ct discovers changes by comparing to main branch
  pull_request:
    paths:
      - .github/**
      - charts/**

jobs:
  chart-lint:
    name: Helm chart linting
    runs-on: ubuntu-latest
    steps:
      - name: checkout repo
        uses: actions/checkout@v4
        with:
          fetch-depth: 0

      - name: Install Helm
        uses: Azure/setup-helm@v3
        with:
          version: v3.14.0

      - uses: actions/setup-python@v5
        with:
          cache: "pip"
          python-version: 3.11

      - name: Install chart-testing
        uses: helm/chart-testing-action@v2.6.1

      - name: Install dependencies
        run: pip install -r .github/scripts/requirements.txt

      - name: Dereference JSON Schema
        env:
          PYTHONUNBUFFERED: "1" # Ensure that Python outputs everything to the console
        run: |
          find charts -name "values.schema.json" -exec dirname {} \; | while read -r directory; do
            python .github/scripts/dereference_json_schema.py "./$directory/values.schema.json" "./$directory/values.schema.json";
          done

      - name: Chart linting
        run: ct lint --config .github/ct-config.yaml

However, this fails as chart-testing-action installs a virtual environment using the default Python installed on the runner (3.7 in my case), instead of just installing yamllint and yamale in the new v3.11.

I was able to work around the issue by creating a custom action, which just uses ct.sh where anything referencing venv is removed.

To solve this issue for others, I would suggest adding the option to disable the virtual environment - or even removing the virtual environment completely, as it just leads to confusion amongst users

AndersBennedsgaard commented 7 months ago

Closing this issue. It was apparently just a caching issue with the runner I was using..