Skip to content

Commit

Permalink
chore(manager/terraform): increased lock update logging (#31094)
Browse files Browse the repository at this point in the history
  • Loading branch information
rarkins committed Aug 29, 2024
1 parent 5f7d22e commit 3fe0f78
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
18 changes: 15 additions & 3 deletions lib/modules/manager/terraform/lockfile/hash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,16 @@ export class TerraformProviderHash {
logger.trace(
`Downloading archive and generating hash for ${build.name}-${build.version}...`,
);
const startTime = Date.now();
const readStream = TerraformProviderHash.http.stream(build.url);
const writeStream = fs.createCacheWriteStream(downloadFileName);

try {
await fs.pipeline(readStream, writeStream);

const hash = await this.hashOfZipContent(downloadFileName, extractPath);
logger.trace(
{ hash },
`Generated hash for ${build.name}-${build.version}`,
logger.debug(
`Hash generation for ${build.url} took ${Date.now() - startTime}ms for ${build.name}-${build.version}`,
);
return hash;
} finally {
Expand All @@ -141,6 +141,7 @@ export class TerraformProviderHash {
static async calculateHashScheme1Hashes(
builds: TerraformBuild[],
): Promise<string[]> {
logger.debug(`Calculating hashes for ${builds.length} builds`);
const cacheDir = await ensureCacheDir('./others/terraform');

// for each build download ZIP, extract content and generate hash for all containing files
Expand All @@ -154,6 +155,9 @@ export class TerraformProviderHash {
repository: string,
version: string,
): Promise<string[] | null> {
logger.debug(
`Creating hashes for ${repository}@${version} (${registryURL})`,
);
const builds = await TerraformProviderHash.terraformDatasource.getBuilds(
registryURL,
repository,
Expand All @@ -169,6 +173,10 @@ export class TerraformProviderHash {
builds.map((build) => build.shasums_url).filter(isNotNullOrUndefined),
);

logger.debug(
`Getting zip hashes for ${shaUrls.length} shasum URL(s) for ${repository}@${version}`,
);

const zhHashes: string[] = [];
for (const shaUrl of shaUrls) {
const hashes =
Expand All @@ -177,6 +185,10 @@ export class TerraformProviderHash {
zhHashes.push(...coerceArray(hashes));
}

logger.debug(
`Got ${zhHashes.length} zip hashes for ${repository}@${version}`,
);

const h1Hashes =
await TerraformProviderHash.calculateHashScheme1Hashes(builds);

Expand Down
5 changes: 4 additions & 1 deletion lib/modules/manager/terraform/lockfile/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export async function updateArtifacts({
// TODO #22198
['provider', 'required_provider'].includes(dep.depType!),
);
logger.debug(`Found ${providerDeps.length} provider deps`);
for (const dep of providerDeps) {
massageProviderLookupName(dep);
const { registryUrls, newVersion, packageName } = dep;
Expand All @@ -172,6 +173,7 @@ export async function updateArtifacts({
);
// istanbul ignore if: needs test
if (!updateLock) {
logger.debug(`Skipping. No lock found for "${packageName}"`);
continue;
}
if (dep.isLockfileUpdate) {
Expand Down Expand Up @@ -213,9 +215,10 @@ export async function updateArtifacts({
updates.length === 0 ||
updates.some((value) => !value.newHashes?.length)
) {
logger.debug('No updates found or hash creation failed');
return null;
}

logger.debug(`Writing updates to ${lockFilePath}`);
const res = writeLockUpdates(updates, lockFilePath, lockFileContent);
return [res];
} catch (err) {
Expand Down

0 comments on commit 3fe0f78

Please sign in to comment.