@@ -48,10 +48,13 @@ async function main() {
48
48
const ciCreateGithubPr = ! env . CI_GIT_LOCAL_BRANCH_ONLY && env . CI_GH_CREATE_PR && ciCreateFeatureBranch
49
49
const dependencyNameFilter = env . CI_HELM_CHART_NAME_FILTER || [ ]
50
50
const baseBranch = env . CI_GIT_BASELINE_BRANCH
51
+
51
52
try {
52
53
// Read the Chart.yaml file
53
54
const chartContent = await fs . readFile ( chartFile , 'utf8' )
54
55
const chart = yaml . load ( chartContent )
56
+ const dependencyErrors = { }
57
+ const fixedChartVersions = { }
55
58
56
59
if ( ! chart . dependencies || ! Array . isArray ( chart . dependencies ) ) {
57
60
console . error ( 'No dependencies found in Chart.yaml' )
@@ -67,6 +70,23 @@ async function main() {
67
70
continue
68
71
}
69
72
73
+ console . log ( `Pre-check for dependency ${ dependency . name } ` )
74
+ try {
75
+ const dependencyFileName = `${ chartsDir } /${ dependency . alias || dependency . name } /Chart.yaml`
76
+ const dependencyFile = await fs . readFile ( dependencyFileName , 'utf8' )
77
+ const dependencyChart = yaml . load ( dependencyFile )
78
+ if ( dependencyChart . version !== currentDependencyVersion ) {
79
+ console . error ( `Skipping update, indexed version of dependency ${ dependency . name } is not consistent with chart version.` )
80
+ dependencyErrors [ dependency . name ] = 'Indexed version of dependency is not consistent with chart version.'
81
+ fixedChartVersions [ dependency . name ] = dependencyChart . version
82
+ continue
83
+ }
84
+ } catch ( error ) {
85
+ console . error ( `Error checking dependency ${ dependency . name } :` , error )
86
+ dependencyErrors [ dependency . name ] = error
87
+ continue
88
+ }
89
+
70
90
console . log ( `Checking updates for dependency: ${ dependency . name } ` )
71
91
try {
72
92
// Add the Helm repository (idempotent)
@@ -80,6 +100,7 @@ async function main() {
80
100
81
101
if ( ! allVersions . length ) {
82
102
console . error ( `No valid versions found for dependency ${ dependency . name } ` )
103
+ dependencyErrors [ dependency . name ] = 'No valid versions found.'
83
104
continue
84
105
}
85
106
@@ -102,14 +123,13 @@ async function main() {
102
123
continue
103
124
}
104
125
const branchName = `ci-update-${ dependency . name } -to-${ latestVersion } `
105
- if ( ciPushtoBranch ) {
106
- const remoteBranch = await $ `git ls-remote --heads origin ${ branchName } `
107
- if ( remoteBranch . stdout !== '' ) {
108
- console . log (
109
- `Skipping updates for dependency: ${ dependency . name } : the remote branch ${ branchName } already exists` ,
110
- )
111
- continue
112
- }
126
+ const checkBranchCmd = ciPushtoBranch ? $ `git ls-remote --heads origin ${ branchName } ` : $ `git branch --list ${ branchName } `
127
+ const existingBranch = await checkBranchCmd
128
+ if ( existingBranch . stdout !== '' ) {
129
+ console . log (
130
+ `Skipping updates for dependency: ${ dependency . name } : the feature branch ${ branchName } already exists` ,
131
+ )
132
+ continue
113
133
}
114
134
115
135
console . log ( `Updating ${ dependency . name } from version ${ currentVersion } to ${ latestVersion } ` )
@@ -119,7 +139,7 @@ async function main() {
119
139
120
140
const commitMessage = `chore(chart-deps): update ${ dependency . name } to version ${ latestVersion } `
121
141
if ( ciCreateFeatureBranch ) {
122
- await $ `git checkout -b ${ branchName } `
142
+ await $ `git -c core.hooksPath=/dev/null checkout -b ${ branchName } `
123
143
}
124
144
125
145
// Write the updated Chart.yaml file
@@ -155,18 +175,37 @@ async function main() {
155
175
}
156
176
} catch ( error ) {
157
177
console . error ( 'Error updating dependencies:' , error )
178
+ dependencyErrors [ dependency . name ] = error
158
179
} finally {
159
180
// restore this version so it does not populate to the next chart update
160
181
dependency . version = currentDependencyVersion
161
182
if ( ciCreateFeatureBranch ) {
162
183
// Reset to the main branch for the next dependency
163
- await $ `git checkout ${ baseBranch } `
164
- await $ `git reset --hard origin/${ baseBranch } `
184
+ await $ `git -c core.hooksPath=/dev/null checkout ${ baseBranch } `
185
+ await $ `git reset --hard ${ ciPushtoBranch ? ' origin/' : '' } ${ baseBranch } `
165
186
}
166
187
}
167
188
}
168
189
169
190
console . log ( 'Dependency updates complete.' )
191
+ if ( Object . keys ( dependencyErrors ) . length > 0 ) {
192
+ console . log ( 'Summary of errors encountered during the update:' )
193
+ Object . entries ( dependencyErrors ) . forEach ( ( [ key , value ] ) => {
194
+ console . log ( `${ key } :` , value )
195
+ } )
196
+ }
197
+ if ( Object . keys ( fixedChartVersions ) . length > 0 && ! ciPushtoBranch ) {
198
+ console . log ( 'Writing mismatching versions to chart index.' )
199
+ for ( const dependency of chart . dependencies ) {
200
+ const fixedVersion = fixedChartVersions [ dependency . name ]
201
+ if ( fixedVersion ) {
202
+ dependency . version = fixedVersion
203
+ }
204
+ }
205
+ // Write the updated Chart.yaml file
206
+ const updatedChart = yaml . dump ( chart )
207
+ await fs . writeFile ( chartFile , updatedChart , 'utf8' )
208
+ }
170
209
} catch ( error ) {
171
210
console . error ( 'Error updating dependencies:' , error )
172
211
process . exit ( 1 )
0 commit comments