Update children script (#6650)

* Update children script version 2

* save exact
This commit is contained in:
Eugenio Romano
2021-02-09 12:36:00 +00:00
committed by GitHub
parent 0ba2c7dc45
commit 4313535ee3
7 changed files with 184 additions and 129 deletions

View File

@@ -0,0 +1,55 @@
const GitHub = require('github-api');
let program = require('commander');
const ORGANISATION = 'Alfresco';
class PrCreator {
constructor(githubUser, githubRepo, token) {
this.github = new GitHub({token});
this.repo = this.github.getRepo(githubUser, githubRepo);
}
async create(title, head, base) {
const { data: prs } = await this.repo.listPullRequests({ state: 'open', head: `${ORGANISATION}:${head}`, base });
if (prs.length < 1) {
const { data: pr } = await this.repo.createPullRequest({ title, head, base });
return pr.number;
}
return prs[0].number;
}
}
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('-title, --title [type]', 'title')
.parse(process.argv);
console.log('process.argv ', program);
const { token, title, head, repo } = program,
prCreator = new PrCreator(ORGANISATION, repo, token);
if (!token || !head || !title) {
throw new Error('Each of the parameters have to be provided. --token, --title, --head');
}
return prCreator.create(title, head, 'develop');
}
main()
.then(prNumber => {
console.log(prNumber)
process.exit(0);
})
.catch(error => {
console.error(error);
process.exit(1);
});

View File

@@ -1,68 +0,0 @@
#!/usr/bin/env bash
eval repos=(
"alfresco-apps"
"alfresco-content-app"
"generator-alfresco-adf-app"
"alfresco-process-workspace-app")
if [ "$#" -lt 3 ] || [ "$#" -ge 7 ]; then
echo "Wrong number of arguments $# to trigger-travis.sh; run like:"
echo " trigger-travis.sh [--branch BRANCH] GITHUBPROJECT TRAVIS_ACCESS_TOKEN [MESSAGE]" >&2
exit 1
fi
if [ "$1" = "--branch" ] ; then
shift
BRANCH="$1"
shift
else
BRANCH=master
fi
USER=$1
TOKEN=$2
if [ $# -eq 4 ] ; then
MESSAGE=",\"message\": \"$4\""
elif [ -n "$TRAVIS_REPO_SLUG" ] ; then
MESSAGE=",\"message\": \"Triggered by upstream build of $TRAVIS_REPO_SLUG commit "`git log --oneline -n 1 HEAD`"\""
else
MESSAGE=""
fi
## For debugging:
# echo "USER=$USER"
# echo "REPO=$REPO"
# echo "TOKEN=$TOKEN"
# echo "MESSAGE=$MESSAGE"
body="{
\"request\": {
\"branch\":\"$BRANCH\"
$MESSAGE
}}"
for REPO in ${repos[@]}
do
# "%2F" creates a literal "/" in the URL, that is not interpreted as a
# segment or directory separator.
curl -s -X POST \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Travis-API-Version: 3" \
-H "Authorization: token ${TOKEN}" \
-d "$body" \
https://api.travis-ci.com/repo/${USER}%2F${REPO}/requests \
| tee /tmp/travis-request-output.$$.txt
if grep -q '"@type": "error"' /tmp/travis-request-output.$$.txt; then
exit 1
fi
if grep -q 'access denied' /tmp/travis-request-output.$$.txt; then
exit 1
fi
done

View File

@@ -1,24 +0,0 @@
#!/usr/bin/env bash
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
if ([ "$TRAVIS_BRANCH" = "master" ]); then
VERSION=$(npm view @alfresco/adf-core version)
JS_VERSION=$(npm view @alfresco/js-api version)
else
VERSION=$(npm view @alfresco/adf-core@beta version)
JS_VERSION=$(npm view @alfresco/js-api@alpha version)
fi;
echo "Update Generator"
./scripts/travis/update/update-project.sh -t $GITHUB_TOKEN -n 'Alfresco/generator-alfresco-adf-app' -v $VERSION -vjs $JS_VERSION
echo "Update ACA"
./scripts/travis/update/update-project.sh -t $GITHUB_TOKEN -n 'Alfresco/alfresco-content-app' -v $VERSION -vjs $JS_VERSION
echo "Update AMA"
./scripts/travis/update/update-project.sh -t $GITHUB_ENTERPRISE_TOKEN -n 'Alfresco/alfresco-apps' -v $VERSION -vjs $JS_VERSION
echo "Update Workspace"
./scripts/travis/update/update-project.sh -t $GITHUB_ENTERPRISE_TOKEN -n 'Alfresco/alfresco-process-workspace-app' -v $VERSION -vjs $JS_VERSION
echo "Update Digital Workspace"
./scripts/travis/update/update-project.sh -t $GITHUB_ENTERPRISE_TOKEN -n 'Alfresco/alfresco-digital-workspace-app' -v $VERSION -vjs $JS_VERSION

View File

@@ -1,61 +1,118 @@
#!/usr/bin/env bash
set -e
BUILD_PIPELINE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
REPO_DIR="$BUILD_PIPELINE_DIR/../.."
TEMP_GENERATOR_DIR=".tmp-generator";
VERSION=$(npm view @alfresco/adf-core@beta version)
JS_VERSION=$(npm view @alfresco/js-api@alpha version)
BRANCH_TO_CREATE="update-alfresco-dependencies"
TOKEN=""
PR_NUMBER=""
show_help() {
echo "Usage: update-project.sh"
echo "Usage: create-updatebranch.sh"
echo ""
echo "-t or --token Github ouath token"
echo "-n or --name Github name of the project"
echo "-v or --version ADF version if not passed will use the beta"
echo "-vjs or --vjs JS API version if not passed will use the beta"
echo "-t or --token: Github ouath token"
echo "-p or --pr: Originating jsapi PR number"
echo "-v or --version version to update"
}
token() {
set_token() {
TOKEN=$1
}
vjs() {
JS_VERSION=$1
set_pr() {
PR_NUMBER=$1
}
version() {
VERSION=$1
}
name_repo() {
update_dependency() {
PKG=$1
PKG_VERSION=$(npm view $PKG@$VERSION version)
echo "Update $PKG to $PKG_VERSION in $NAME_REPO"
for i in $(find . ! -path "*/node_modules/*" -name "package-lock.json" | xargs grep -l $PKG); do
directory=$(dirname $i)
echo "Update $PKG in $directory"
( cd $directory ; npm i --ignore-scripts $PKG@$PKG_VERSION --save-exact)
done
git add .
git commit -n -m "[auto-commit] Update $PKG to $PKG_VERSION for branch: $BRANCH_TO_CREATE originated from $PKG PR: $PR_NUMBER"
}
update_js_dependency() {
PKG=$1
PKG_VERSION=$2
echo "Update $PKG to $PKG_VERSION in $NAME_REPO"
for i in $(find . ! -path "*/node_modules/*" -name "package-lock.json" | xargs grep -l $PKG); do
directory=$(dirname $i)
echo "Update $PKG in $directory"
( cd $directory ; npm i --ignore-scripts $PKG@$PKG_VERSION --save-exact)
done
git add .
git commit -n -m "[auto-commit] Update $PKG to $PKG_VERSION for branch: $BRANCH_TO_CREATE originated from $PKG PR: $PR_NUMBER"
}
update() {
NAME_REPO=$1
echo "Update dependencies $NAME_REPO"
git clone https://$TOKEN@github.com/Alfresco/$NAME_REPO.git $TEMP_GENERATOR_DIR
cd $TEMP_GENERATOR_DIR
git fetch
# Checkout branch if exist, otherwise create it
git checkout $BRANCH_TO_CREATE 2>/dev/null || git checkout -b $BRANCH_TO_CREATE origin/develop
update_js_dependency "@alfresco/js-api" $JS_API_INSTALLED
update_dependency "@alfresco/adf-extensions"
update_dependency "@alfresco/adf-core"
update_dependency "@alfresco/adf-content-services"
update_dependency "@alfresco/adf-process-services"
update_dependency "@alfresco/adf-process-services-cloud"
git push origin $BRANCH_TO_CREATE
node $BUILD_PIPELINE_DIR/pr-creator.js --token=$TOKEN --title="Update branch for ADF and JS-API" --head=$BRANCH_TO_CREATE --repo=$NAME_REPO
cd ..
rm -rf $TEMP_GENERATOR_DIR
}
while [[ $1 == -* ]]; do
case "$1" in
-h|--help|-\?) show_help; exit 0;;
-n|--name|-\?) name_repo $2; shift 2;;
-t|--token) token $2; shift 2;;
-t|--token) set_token $2; shift; shift;;
-p|--pr) set_pr $2; shift; shift;;
-v|--version) version $2; shift 2;;
-vjs|--vjs) vjs $2; shift 2;;
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
esac
done
rm -rf $TEMP_GENERATOR_DIR;
cd "$REPO_DIR"
git clone https://$TOKEN@github.com/$NAME_REPO.git $TEMP_GENERATOR_DIR
cd $TEMP_GENERATOR_DIR
git checkout develop
JS_API_INSTALLED=$(npm list @alfresco/js-api --depth=0 --json | jq -r '.dependencies["@alfresco/js-api"].version')
BRANCH="ADF-update-$VERSION"
git checkout -b $BRANCH
echo "Current installed JS-API $JS_API_INSTALLED"
./scripts/update-version.sh -gnu -v $VERSION -vj $JS_VERSION
if [[ (-z "$TOKEN") || (-z "$VERSION") ]]
then
echo "Each of 'branch name' (-b) token (-t) and pr number (-p) have to be set. See -help."
exit 1;
fi
git add .
git commit -m "Update ADF packages version $VERSION"
git push -u origin $BRANCH
rm -rf $TEMP_GENERATOR_DIR
curl -H "Authorization: token $TOKEN" -X POST -d '{"body":"Update ADF packages version '$VERSION'","head":"'$BRANCH'","base":"develop","title":"Update ADF packages version '$VERSION'"}' https://api.github.com/repos/$NAME_REPO/pulls
update "generator-alfresco-adf-app"
update "alfresco-content-app"
update "alfresco-apps"
update "alfresco-digital-workspace-app"
rm -rf $TEMP_GENERATOR_DIR;
exit $?