Skip to content

feat: testing CI improvements #54

feat: testing CI improvements

feat: testing CI improvements #54

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
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
errors=false
message="### Validation Results:\n\n"
# 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
if [ "$current_version" = "$main_version" ]; then
message+="❌ Version in $chart_file needs updating. Main version: $main_version.\nPlease increment the version (e.g., 1.0.1 -> 1.0.2).\n\n"
errors=true
else
IFS='.' read -r major minor patch <<< "$main_version"
next_patch="$major.$minor.$((patch + 1))"
next_minor="$major.$((minor + 1)).0"
# Validate updated version
case "$current_version" in
"$next_patch")
message+="✅ $chart_file version correctly incremented to $current_version (next patch).\n\n"
;;
"$next_minor")
message+="✅ $chart_file version correctly incremented to $current_version (next minor).\n\n"
;;
*)
message+="❌ Invalid version in $chart_file. Main version: $main_version.\nExpected: $next_patch (patch) or $next_minor (minor).\n\n"
errors=true
;;
esac
fi
fi
# README generation
if [ -f "${dir}values.yaml" ]; then
if readme-generator -v "${dir}values.yaml" -r "${dir}README.md"; then
message+="✅ README generation for $dir is up-to-date.\n\n"
else
# message+="❌ README for $dir outdated or failed to generate.\nTo update:\n\`\`\`\nnpm install -g @bitnami/readme-generator-for-helm\nreadme-generator -v ${dir}values.yaml -r ${dir}README.md\n\`\`\`\n\n"
errors=true
fi
fi
done
# Final status
if [ "$errors" = true ]; then
message+="Some checks failed. Please address the issues above.\n"
exit_code=1
else
message+="All validation checks passed! 🎉\n"
exit_code=0
fi
# Post comment on PR
pr_number=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH")
curl -s -X POST "https://api.github.com/repos/${{ github.repository }}/issues/$pr_number/comments" \
-H "Authorization: token $GITHUB_TOKEN" \
-H "Content-Type: application/json" \
-d "$(jq -n --arg body "$message" '{body: $body}')"
exit $exit_code