diff --git a/.github/workflows/upstream-adf.yml b/.github/workflows/upstream-adf.yml index 2b5986c6ce..1131f60469 100644 --- a/.github/workflows/upstream-adf.yml +++ b/.github/workflows/upstream-adf.yml @@ -3,6 +3,12 @@ on: schedule: - cron: '0 */3 * * *' # “At minute 0 past every 3rd hour.” workflow_dispatch: + inputs: + tag: + description: 'Type of the tag the latest version should be fetched with' + required: false + type: string + default: 'alpha' env: GH_TOKEN: ${{ secrets.BOT_GITHUB_TOKEN }} @@ -30,11 +36,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({exec, github, dependencyName: 'adf-core'}); + const { hasNewVersion: hasNewADFVersion , remoteVersion: latestADFVersion } = await getLatestVersionOf({exec, github, dependencyName: 'adf-core', tag: '${{ inputs.tag }}'}); console.log('hasNewADFVersion', hasNewADFVersion); console.log('latestADFVersion', latestADFVersion?.name); - const { hasNewVersion: hasNewJSVersion, remoteVersion: latestJSVersion } = await getLatestVersionOf({exec, github, dependencyName: 'js-api'}); + const { hasNewVersion: hasNewJSVersion, remoteVersion: latestJSVersion } = await getLatestVersionOf({exec, github, dependencyName: 'js-api', tag: '${{ inputs.tag }}'}); console.log('hasNewJSVersion', hasNewJSVersion); console.log('latestJSVersion', latestJSVersion?.name); if (hasNewADFVersion === 'true' || hasNewJSVersion === 'true' ) { diff --git a/scripts/gh/update/latest-version-of.js b/scripts/gh/update/latest-version-of.js index b5fb3d4a8e..2c3b23053b 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, tag }) => { const organization = 'alfresco'; const dependencyFullName = `@${organization}/${dependencyName}`; const pkg = require('../../../package.json'); @@ -15,7 +15,6 @@ module.exports = async ({ exec, github, dependencyName }) => { org: organization }); - let latestPkgToUpdate = availablePackages[0]; const options = {}; let packageDistTag = ''; options.listeners = { @@ -25,17 +24,13 @@ module.exports = async ({ exec, github, dependencyName }) => { }; await exec.exec(`npm dist-tag ls @alfresco/${dependencyName}`, [], options); const tagsType = packageDistTag.split('\n'); - const latestPkgTag = tagsType.find((tag) => tag.includes(latestPkgToUpdate.name))?.split(':')[0]; - - if (latestPkgTag !== 'alpha') { - const alphaPackageVersion = tagsType.find((tag) => tag.includes('alpha'))?.split(':')[1].trim(); - latestPkgToUpdate = availablePackages.find((item) => item.name === alphaPackageVersion); - } + const matchedPkgVersion = tagsType.find((tagType) => tagType.includes(tag))?.split(':')[1].trim(); + const latestPkgToUpdate = availablePackages.find((package) => package.name === matchedPkgVersion); if (localVersion === latestPkgToUpdate?.name) { return { hasNewVersion: 'false' }; } else { - const findLocalVersionOnRemote = availablePackages.find((item) => item.name === localVersion); + const findLocalVersionOnRemote = availablePackages.find((package) => package.name === localVersion); let rangeInDays = 'N/A'; if (findLocalVersionOnRemote !== undefined) { const creationLocal = new Date(findLocalVersionOnRemote.created_at);