From 55098fe4a3cc0b336e85840dae6cb46b4227bd4d Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 08:02:40 +0200 Subject: [PATCH 1/7] Investigate GH package versions response --- scripts/gh/update/latest-version-of.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index 96d4cdf608..3667cab3f2 100644 --- a/scripts/gh/update/latest-version-of.js +++ b/scripts/gh/update/latest-version-of.js @@ -15,6 +15,8 @@ module.exports = async ({github, dependencyName}) => { org: organization }); + console.log(availablePackages); + const latestPkgToUpdate = availablePackages[0]; if (localVersion === latestPkgToUpdate?.name) { From 8d5f5db0e24c0ef1bc1adfc5feafcbaee34e5278 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 08:16:09 +0200 Subject: [PATCH 2/7] Retrieve package data --- scripts/gh/update/latest-version-of.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index 3667cab3f2..023289bc02 100644 --- a/scripts/gh/update/latest-version-of.js +++ b/scripts/gh/update/latest-version-of.js @@ -15,9 +15,19 @@ module.exports = async ({github, dependencyName}) => { org: organization }); - console.log(availablePackages); + let i = 0; + let latestPkgToUpdate = null; - const latestPkgToUpdate = availablePackages[0]; + while (latestPkgToUpdate === null && i < availablePackages.length) { + const { data: pkg } = await github.rest.packages.getPackageVersionForOrganization({ + package_type: 'npm', + package_name: dependencyName, + org: organization, + package_version_id: availablePackages[i].id + }); + + console.log(pkg); + } if (localVersion === latestPkgToUpdate?.name) { return { hasNewVersion: 'false' }; From dbb161ca5c911aa9e4c6927dff067fcb3a051e31 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 13:58:58 +0200 Subject: [PATCH 3/7] Get proper package type --- scripts/gh/update/latest-version-of.js | 34 +++++++++++++++----------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index 023289bc02..6aa70df8c6 100644 --- a/scripts/gh/update/latest-version-of.js +++ b/scripts/gh/update/latest-version-of.js @@ -2,7 +2,7 @@ function inDays(d1, d2) { return Math.floor((d2.getTime() - d1.getTime()) / (24 * 3600 * 1000)); } -module.exports = async ({github, dependencyName}) => { +module.exports = async ({exec, github, dependencyName}) => { const organization = 'alfresco'; const dependencyFullName = `@${organization}/${dependencyName}`; const pkg = require('../../../package.json'); @@ -15,22 +15,28 @@ module.exports = async ({github, dependencyName}) => { org: organization }); - let i = 0; - let latestPkgToUpdate = null; - - while (latestPkgToUpdate === null && i < availablePackages.length) { - const { data: pkg } = await github.rest.packages.getPackageVersionForOrganization({ - package_type: 'npm', - package_name: dependencyName, - org: organization, - package_version_id: availablePackages[i].id - }); - - console.log(pkg); + let latestPkgToUpdate = availablePackages[0]; + const options = {}; + let packageDistTag = ''; + options.listeners = { + stdout: (data) => { + packageDistTag += data.toString() + } + }; + await exec.exec(`npm dist-tag ls @alfresco/adf-core`, [], options); + const tagsType = packageDistTag.split('\n'); + console.log(tagsType); + const latestPkgTag = tagsType.find((tag) => tag.includes(latestPkgToUpdate.name))?.split(':')[0]; + console.log(latestPkgTag); + + if (latestPkgTag !== 'alpha') { + const alphaPackageVersion = tagsType.find((tag) => tag.includes('alpha'))?.split(':')[1].trim(); + latestPkgToUpdate = availablePackages.find((item) => item.name === alphaPackageVersion); + console.log(latestPkgToUpdate); } if (localVersion === latestPkgToUpdate?.name) { - return { hasNewVersion: 'false' }; + return { hasNewVersion: 'false' }; } else { const findLocalVersionOnRemote = availablePackages.find((item) => item.name === localVersion); let rangeInDays = 'N/A' From 02a719b9c5e9699d73a7557a76210ba65690cdb9 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 14:03:02 +0200 Subject: [PATCH 4/7] Pass required exec param --- .github/workflows/upstream-adf.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/upstream-adf.yml b/.github/workflows/upstream-adf.yml index de8ebbc041..2b5986c6ce 100644 --- a/.github/workflows/upstream-adf.yml +++ b/.github/workflows/upstream-adf.yml @@ -30,11 +30,11 @@ jobs: github-token: ${{ secrets.BOT_GITHUB_TOKEN }} script: | const getLatestVersionOf = require('./scripts/gh/update/latest-version-of.js'); - const { hasNewVersion: hasNewADFVersion , remoteVersion: latestADFVersion } = await getLatestVersionOf({github, dependencyName: 'adf-core'}); + const { hasNewVersion: hasNewADFVersion , remoteVersion: latestADFVersion } = await getLatestVersionOf({exec, github, dependencyName: 'adf-core'}); console.log('hasNewADFVersion', hasNewADFVersion); console.log('latestADFVersion', latestADFVersion?.name); - const { hasNewVersion: hasNewJSVersion, remoteVersion: latestJSVersion } = await getLatestVersionOf({github, dependencyName: 'js-api'}); + const { hasNewVersion: hasNewJSVersion, remoteVersion: latestJSVersion } = await getLatestVersionOf({exec, github, dependencyName: 'js-api'}); console.log('hasNewJSVersion', hasNewJSVersion); console.log('latestJSVersion', latestJSVersion?.name); if (hasNewADFVersion === 'true' || hasNewJSVersion === 'true' ) { From 9712e8fdb1e65eebf5aa57a66e0f7466b80a7743 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 14:05:56 +0200 Subject: [PATCH 5/7] Use proper dependency name --- scripts/gh/update/latest-version-of.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index 6aa70df8c6..5093b7c0ea 100644 --- a/scripts/gh/update/latest-version-of.js +++ b/scripts/gh/update/latest-version-of.js @@ -23,7 +23,7 @@ module.exports = async ({exec, github, dependencyName}) => { packageDistTag += data.toString() } }; - await exec.exec(`npm dist-tag ls @alfresco/adf-core`, [], options); + await exec.exec(`npm dist-tag ls @alfresco/${dependencyName}`, [], options); const tagsType = packageDistTag.split('\n'); console.log(tagsType); const latestPkgTag = tagsType.find((tag) => tag.includes(latestPkgToUpdate.name))?.split(':')[0]; From 5d7cda53232cf72738399718e3d46313ba78d2a4 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 14:09:35 +0200 Subject: [PATCH 6/7] Code cleanup --- scripts/gh/update/latest-version-of.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index 5093b7c0ea..80112d991f 100644 --- a/scripts/gh/update/latest-version-of.js +++ b/scripts/gh/update/latest-version-of.js @@ -25,14 +25,11 @@ module.exports = async ({exec, github, dependencyName}) => { }; await exec.exec(`npm dist-tag ls @alfresco/${dependencyName}`, [], options); const tagsType = packageDistTag.split('\n'); - console.log(tagsType); const latestPkgTag = tagsType.find((tag) => tag.includes(latestPkgToUpdate.name))?.split(':')[0]; - console.log(latestPkgTag); if (latestPkgTag !== 'alpha') { const alphaPackageVersion = tagsType.find((tag) => tag.includes('alpha'))?.split(':')[1].trim(); latestPkgToUpdate = availablePackages.find((item) => item.name === alphaPackageVersion); - console.log(latestPkgToUpdate); } if (localVersion === latestPkgToUpdate?.name) { From 650720a1c12e6fa8d06481143d4e4aaa86fe17d7 Mon Sep 17 00:00:00 2001 From: MichalKinas Date: Fri, 23 Aug 2024 14:20:25 +0200 Subject: [PATCH 7/7] [ACS-8659] Prettier fixes --- scripts/gh/update/latest-version-of.js | 35 +++++++++++++------------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index 80112d991f..b5fb3d4a8e 100644 --- a/scripts/gh/update/latest-version-of.js +++ b/scripts/gh/update/latest-version-of.js @@ -2,7 +2,7 @@ function inDays(d1, d2) { return Math.floor((d2.getTime() - d1.getTime()) / (24 * 3600 * 1000)); } -module.exports = async ({exec, github, dependencyName}) => { +module.exports = async ({ exec, github, dependencyName }) => { const organization = 'alfresco'; const dependencyFullName = `@${organization}/${dependencyName}`; const pkg = require('../../../package.json'); @@ -10,18 +10,18 @@ module.exports = async ({exec, github, dependencyName}) => { const localVersion = pkg.dependencies[dependencyFullName]; const { data: availablePackages } = await github.rest.packages.getAllPackageVersionsForPackageOwnedByOrg({ - package_type: 'npm', - package_name: dependencyName, - org: organization + package_type: 'npm', + package_name: dependencyName, + org: organization }); - let latestPkgToUpdate = availablePackages[0]; + let latestPkgToUpdate = availablePackages[0]; const options = {}; let packageDistTag = ''; options.listeners = { - stdout: (data) => { - packageDistTag += data.toString() - } + stdout: (data) => { + packageDistTag += data.toString(); + } }; await exec.exec(`npm dist-tag ls @alfresco/${dependencyName}`, [], options); const tagsType = packageDistTag.split('\n'); @@ -35,14 +35,13 @@ module.exports = async ({exec, github, dependencyName}) => { if (localVersion === latestPkgToUpdate?.name) { return { hasNewVersion: 'false' }; } else { - const findLocalVersionOnRemote = availablePackages.find((item) => item.name === localVersion); - let rangeInDays = 'N/A' - if (findLocalVersionOnRemote !== undefined) { - const creationLocal = new Date(findLocalVersionOnRemote.created_at); - const creationLatest = new Date(latestPkgToUpdate.created_at); - rangeInDays = inDays(creationLocal, creationLatest); - } - return { hasNewVersion: 'true', remoteVersion: { name: latestPkgToUpdate?.name, rangeInDays } , localVersion}; + const findLocalVersionOnRemote = availablePackages.find((item) => item.name === localVersion); + let rangeInDays = 'N/A'; + if (findLocalVersionOnRemote !== undefined) { + const creationLocal = new Date(findLocalVersionOnRemote.created_at); + const creationLatest = new Date(latestPkgToUpdate.created_at); + rangeInDays = inDays(creationLocal, creationLatest); + } + return { hasNewVersion: 'true', remoteVersion: { name: latestPkgToUpdate?.name, rangeInDays }, localVersion }; } - -} +};