From 30eb3dda394cd5e52a6c2eacf6cd93188d176e98 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Tue, 15 Nov 2022 18:47:22 +0300 Subject: [PATCH] fix(github-actions): Fix hash extraction (#18927) --- lib/modules/manager/github-actions/extract.spec.ts | 3 ++- lib/modules/manager/github-actions/extract.ts | 6 +++++- lib/modules/versioning/docker/index.spec.ts | 1 + lib/modules/versioning/docker/index.ts | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/modules/manager/github-actions/extract.spec.ts b/lib/modules/manager/github-actions/extract.spec.ts index 10a3e036ba92ba..bdd27790e68cb5 100644 --- a/lib/modules/manager/github-actions/extract.spec.ts +++ b/lib/modules/manager/github-actions/extract.spec.ts @@ -240,13 +240,14 @@ describe('modules/manager/github-actions/extract', () => { 'actions/checkout@1e204e9a9253d643386038d443f96446fa156a97 #v2.1.0', }, { - currentDigest: '1e204e', + currentDigestShort: '1e204e', currentValue: 'v2.1.0', replaceString: 'actions/checkout@1e204e # v2.1.0', }, { currentValue: '01aecc#v2.1.0', replaceString: 'actions/checkout@01aecc#v2.1.0', + skipReason: 'invalid-version', }, { currentDigest: '689fcce700ae7ffc576f2b029b51b2ffb66d3abd', diff --git a/lib/modules/manager/github-actions/extract.ts b/lib/modules/manager/github-actions/extract.ts index 205c61be428388..72d2e13571d5a6 100644 --- a/lib/modules/manager/github-actions/extract.ts +++ b/lib/modules/manager/github-actions/extract.ts @@ -13,7 +13,8 @@ const actionRe = regEx( ); // SHA1 or SHA256, see https://github.blog/2020-10-19-git-2-29-released/ -const shaRe = regEx(/^(?:[a-f0-9]{6,7}|[a-f0-9]{40}|[a-f0-9]{64})$/); +const shaRe = regEx(/^(?:[a-f0-9]{40}|[a-f0-9]{64})$/); +const shaShortRe = regEx(/^[a-f0-9]{6,7}$/); function extractWithRegex(content: string): PackageDependency[] { logger.trace('github-actions.extractWithRegex()'); @@ -60,6 +61,9 @@ function extractWithRegex(content: string): PackageDependency[] { if (shaRe.test(currentValue)) { dep.currentValue = tag; dep.currentDigest = currentValue; + } else if (shaShortRe.test(currentValue)) { + dep.currentValue = tag; + dep.currentDigestShort = currentValue; } else { dep.currentValue = currentValue; if (!dockerVersioning.api.isValid(currentValue)) { diff --git a/lib/modules/versioning/docker/index.spec.ts b/lib/modules/versioning/docker/index.spec.ts index 8f420eb63dfb80..381ed03e0a5d35 100644 --- a/lib/modules/versioning/docker/index.spec.ts +++ b/lib/modules/versioning/docker/index.spec.ts @@ -18,6 +18,7 @@ describe('modules/versioning/docker/index', () => { ${'0z1b2c3'} | ${true} ${'0A1b2c3d4e5f6a7b8c9d0a1b2c3d4e5f6a7b8c9d'} | ${true} ${'123098140293'} | ${true} + ${'01aecc#v2.1.0'} | ${false} `('isValid("$version") === $expected', ({ version, expected }) => { const res = docker.isValid(version); expect(!!res).toBe(expected); diff --git a/lib/modules/versioning/docker/index.ts b/lib/modules/versioning/docker/index.ts index de8d7652dc3a4d..94f5f02cde8291 100644 --- a/lib/modules/versioning/docker/index.ts +++ b/lib/modules/versioning/docker/index.ts @@ -9,7 +9,7 @@ export const urls = [ ]; export const supportsRanges = false; -const versionPattern = regEx(/^(?\d+(?:\.\d+)*)(?.*)$/); +const versionPattern = regEx(/^(?\d+(?:\.\d+)*)(?\w*)$/); const commitHashPattern = regEx(/^[a-f0-9]{7,40}$/); const numericPattern = regEx(/^[0-9]+$/);