Skip to content

feat: testing CI improvements #57

feat: testing CI improvements

feat: testing CI improvements #57

Workflow file for this run

name: Charts Validation
on:
pull_request:
paths:
- 'charts/**'
jobs:
lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch history
run: git fetch --prune --unshallow
- name: Run Helm lint
uses: helm/chart-testing-action@v2.6.1
with:
command: lint
config: .github/verify-config.yaml
- name: Set up Node.js (required for readme-generator)
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install readme-generator-for-helm
run: npm install -g @bitnami/readme-generator-for-helm
- name: Check Chart Version and Run README Generator
shell: bash
run: |
errors=false
# Loop through modified chart directories
for dir in $(git diff --name-only origin/main | grep -o 'charts/[^/]*/' | sort -u); do
chart_file="${dir}Chart.yaml"
if [ -f "$chart_file" ]; then
# Fetch current and main branch versions
current_version=$(yq eval '.version' "$chart_file")
main_version=$(git show origin/main:"$chart_file" | yq eval '.version' -)
# Check if the version was incremented correctly
if [ "$current_version" = "$main_version" ]; then
echo "::error::Version in $chart_file needs to be updated. The current version in main is $main_version."
echo "Please increment the version in $chart_file by updating the 'version' field to the next semantic version (e.g., 1.0.1 -> 1.0.2).\n"
errors=true
else
# Extract major, minor, patch for validation
IFS='.' read -r major minor patch <<< "$main_version"
next_patch_version="$major.$minor.$((patch + 1))"
next_minor_version="$major.$((minor + 1)).0"
# Validate the updated version
if [ "$current_version" = "$next_patch_version" ]; then
echo "Version in $chart_file is correctly incremented to $current_version (next patch version).\n"
elif [ "$current_version" = "$next_minor_version" ]; then
echo "Version in $chart_file is correctly incremented to $current_version (next minor version).\n"
else
echo "::error::Version in $chart_file is not a valid next version. The current version in main is $main_version."
echo "Expected the next version to be either $next_patch_version (patch increment) or $next_minor_version (minor increment)."
echo "Please update the version in $chart_file to one of these expected values.\n"
errors=true
fi
fi
fi
# Check and generate README
if [ -f "${dir}values.yaml" ]; then
echo "Generating README for $dir"
if ! readme-generator -v "${dir}values.yaml" -r "${dir}README.md"; then
echo "::error::README.md for $dir is outdated or an error occurred while generating it."
echo "Please update README.md by installing readme-generator-for-helm and running:"
echo "npm install -g @bitnami/readme-generator-for-helm"
echo "readme-generator -v ${dir}values.yaml -r ${dir}README.md"
errors=true
else
echo "README generation for $dir is in order."
fi
fi
done
# Fail the job if any errors were detected
if [ "$errors" = true ]; then
echo "Some checks failed. Please address the issues above."
exit 1
else
echo "All validation checks passed."
fi