Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-8659] Refine ADF upstream to pick only 'alpha' versions #4049

Merged
merged 7 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/upstream-adf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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' ) {
Expand Down
46 changes: 30 additions & 16 deletions scripts/gh/update/latest-version-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,46 @@ 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');

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
});

const latestPkgToUpdate = availablePackages[0];
let latestPkgToUpdate = availablePackages[0];
const options = {};
let packageDistTag = '';
options.listeners = {
stdout: (data) => {
packageDistTag += data.toString();
}
};
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);
}

if (localVersion === latestPkgToUpdate?.name) {
return { hasNewVersion: 'false' };
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 };
}

}
};
Loading