-
Notifications
You must be signed in to change notification settings - Fork 16
92 lines (79 loc) · 3.76 KB
/
verify.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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