[AAE-10077] ADF's cron job, make it smarter by avoiding publishing on NPM and triggering the PR upstream (#7725)

* Avoid the publish on NPM and create useless PR upstream if same ADF sha

* Remove useless file
This commit is contained in:
Maurizio Vitale 2022-07-26 21:24:50 +02:00 committed by GitHub
parent d8f1eda132
commit d3ae78d855
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 88 additions and 6 deletions

View File

@ -13,10 +13,15 @@ then
if [[ $TRAVIS_BRANCH =~ ^develop(-patch.*)?$ ]] || [[ $TRAVIS_EVENT_TYPE == "cron" ]] || [[ $TRAVIS_EVENT_TYPE == "api" ]]
then
isSameADFSha=$(node $BUILD_PIPELINE_DIR/adf-same-commit-verify.js --token=$TOKEN --head=$BRANCH_TO_CREATE --repo=$NAME_REPO --commit=$COMMIT )
if [ "$isSameADFSha" = 'true' ]; then
echo 'ADF sha is the same. No need to publish again on NPM'
else
echo "Replace NPM version with new Alpha tag"
NEXT_VERSION=-nextalpha
./scripts/update-version.sh -gnu $NEXT_VERSION || exit 1;
fi
fi
node ./scripts/pre-publish.js
fi;

View File

@ -0,0 +1,71 @@
#!/usr/bin/env node
const GitHub = require('github-api');
let program = require('commander');
const ORGANISATION = 'Alfresco';
const ORIGIN_REPO = 'alfresco-ng2-components';
class PrCreator {
constructor(githubUser, githubRepo, token, commit) {
this.github = new GitHub({token});
this.repoOrigin = this.github.getRepo(githubUser, ORIGIN_REPO);
this.repoDestination = this.github.getRepo(githubUser, githubRepo);
this.commit = commit;
}
async getShaClosedPr(head, base) {
return this.getShaPr(head, base, 'closed');
}
async getShaOpenPr(head, base) {
return this.getShaPr(head, base, 'open');
}
async getShaPr(head, base, status) {
const { data: closedUpstreamPRs } = await this.repoDestination.listPullRequests({ state: status, head: `${ORGANISATION}:${head}`, base });
if (closedUpstreamPRs.length > 0) {
const latestClosedUpstream = closedUpstreamPRs[0];
return latestClosedUpstream.body.split(':')[1].trim();
}
return '';
}
}
async function main() {
program
.version('0.1.0')
.option('--host [type]', 'Remote environment host adf.lab.com ')
.option('-t, --token [type]', 'token')
.option('-h, --head [type]', 'head')
.option('-r, --repo [type]', 'repo')
.option('-c, --commit [type]', 'commit')
.parse(process.argv);
const { token, head, repo, commit } = program,
prCreator = new PrCreator(ORGANISATION, repo, token, commit);
const baseBranchName = 'develop';
const shaOpen = await prCreator.getShaOpenPr(head, baseBranchName);
const shaClosed = await prCreator.getShaClosedPr(head, baseBranchName);
if (shaOpen === commit || shaClosed === commit) {
console.log('ADF sha already exist');
return 'true';
}
return 'false';
}
main()
.then(result => {
process.stdout.write(result);
process.exit(0);
})
.catch(error => {
console.error(error.response.status);
console.error(error.response.statusText);
process.exit(1);
});

View File

@ -126,8 +126,14 @@ fi
rm -rf $TEMP_GENERATOR_DIR
update "generator-alfresco-adf-app"
update "alfresco-content-app"
update "alfresco-apps"
isSameADFSha=$(node $BUILD_PIPELINE_DIR/adf-same-commit-verify.js --token=$TOKEN --head=$BRANCH_TO_CREATE --repo=$NAME_REPO --commit=$COMMIT )
if [ "$isSameADFSha" = 'true' ]; then
echo 'ADF sha is the same. No need to create another pr'
else
update "generator-alfresco-adf-app"
update "alfresco-content-app"
update "alfresco-apps"
fi
exit $?