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

@@ -34,13 +34,13 @@ stages:
if: tag IS blank if: tag IS blank
- name: Check bundle - name: Check bundle
if: type = push AND tag IS blank if: type = push AND tag IS blank
- name: Trigger ADF child build
if: (branch = develop AND type = push) OR type = api
- name: Unit test - name: Unit test
if: (branch != master AND type != cron AND tag IS blank) OR type = api if: (branch != master AND type != cron AND tag IS blank) OR type = api
- name: e2e Test - name: e2e Test
if: (branch != master AND type != cron AND tag IS blank) OR type = api if: (branch != master AND type != cron AND tag IS blank) OR type = api
- name: Update Children Projects - name: Trigger Alpha ADF child build
if: (branch = develop AND type = push) OR type = api
- name: Trigger Beta ADF child build
if: tag =~ .*beta.* if: tag =~ .*beta.*
- name: Release tag - name: Release tag
if: type = cron OR branch = master if: type = cron OR branch = master
@@ -84,9 +84,13 @@ jobs:
name: Unit test process-cloud name: Unit test process-cloud
script: ./scripts/travis/unit-test/process-cloud.sh script: ./scripts/travis/unit-test/process-cloud.sh
- stage: Trigger Alpha ADF child build
name: Trigger Alpha ADF child build
script: ./scripts/travis/update/update-project.sh -p $TRAVIS_BUILD_NUMBER -t $GITHUB_TOKEN -v alpha
- stage: Update Children Projects - stage: Trigger Beta ADF child build
script: ./scripts/travis/update/update-children.sh name: Trigger Beta ADF child build
script: ./scripts/travis/update/update-project.sh -p $TRAVIS_BUILD_NUMBER -t $GITHUB_TOKEN -v beta
- stage: Release tag - stage: Release tag
script: ./scripts/travis/release/git-tag.sh script: ./scripts/travis/release/git-tag.sh
@@ -139,11 +143,6 @@ jobs:
- ADF_VERSION=$(npm view @alfresco/adf-core@${TAG_NPM} version) - ADF_VERSION=$(npm view @alfresco/adf-core@${TAG_NPM} version)
- ./scripts/travis/build/npm-check-bundles.sh -v ${ADF_VERSION} - ./scripts/travis/build/npm-check-bundles.sh -v ${ADF_VERSION}
- stage: Trigger ADF child build
name: Trigger ADF child build
script: ./scripts/travis/update/trigger-travis-children.sh --branch $TRAVIS_BRANCH Alfresco $TRAVIS_ACCESS_TOKEN
notifications: notifications:
slack: slack:
on_pull_requests: false on_pull_requests: false

35
package-lock.json generated
View File

@@ -12547,6 +12547,35 @@
"assert-plus": "^1.0.0" "assert-plus": "^1.0.0"
} }
}, },
"github-api": {
"version": "3.4.0",
"resolved": "https://registry.npmjs.org/github-api/-/github-api-3.4.0.tgz",
"integrity": "sha512-2yYqYS6Uy4br1nw0D3VrlYWxtGTkUhIZrumBrcBwKdBOzMT8roAe8IvI6kjIOkxqxapKR5GkEsHtz3Du/voOpA==",
"dev": true,
"requires": {
"axios": "^0.21.1",
"debug": "^2.2.0",
"js-base64": "^2.1.9",
"utf8": "^2.1.1"
},
"dependencies": {
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"dev": true,
"requires": {
"ms": "2.0.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=",
"dev": true
}
}
},
"github-slugger": { "github-slugger": {
"version": "1.3.0", "version": "1.3.0",
"resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-1.3.0.tgz", "resolved": "https://registry.npmjs.org/github-slugger/-/github-slugger-1.3.0.tgz",
@@ -26772,6 +26801,12 @@
"integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==", "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ==",
"dev": true "dev": true
}, },
"utf8": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
"integrity": "sha1-H6DZJw6b6FDZsFAn9jUZv0ZFfZY=",
"dev": true
},
"util": { "util": {
"version": "0.10.3", "version": "0.10.3",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz", "resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz",

View File

@@ -127,6 +127,7 @@
"css-loader": "^4.3.0", "css-loader": "^4.3.0",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"ejs": "^3.1.6", "ejs": "^3.1.6",
"github-api": "^3.4.0",
"graphql": "^15.4.0", "graphql": "^15.4.0",
"graphql-request": "^3.1.0", "graphql-request": "^3.1.0",
"husky": "^4.3.8", "husky": "^4.3.8",

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 #!/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"; TEMP_GENERATOR_DIR=".tmp-generator";
VERSION=$(npm view @alfresco/adf-core@beta version) BRANCH_TO_CREATE="update-alfresco-dependencies"
JS_VERSION=$(npm view @alfresco/js-api@alpha version) TOKEN=""
PR_NUMBER=""
show_help() { show_help() {
echo "Usage: update-project.sh" echo "Usage: create-updatebranch.sh"
echo "" echo ""
echo "-t or --token Github ouath token" echo "-t or --token: Github ouath token"
echo "-n or --name Github name of the project" echo "-p or --pr: Originating jsapi PR number"
echo "-v or --version ADF version if not passed will use the beta" echo "-v or --version version to update"
echo "-vjs or --vjs JS API version if not passed will use the beta"
} }
token() { set_token() {
TOKEN=$1 TOKEN=$1
} }
vjs() { set_pr() {
JS_VERSION=$1 PR_NUMBER=$1
} }
version() { version() {
VERSION=$1 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 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 while [[ $1 == -* ]]; do
case "$1" in case "$1" in
-h|--help|-\?) show_help; exit 0;; -h|--help|-\?) show_help; exit 0;;
-n|--name|-\?) name_repo $2; shift 2;; -t|--token) set_token $2; shift; shift;;
-t|--token) token $2; shift 2;; -p|--pr) set_pr $2; shift; shift;;
-v|--version) version $2; shift 2;; -v|--version) version $2; shift 2;;
-vjs|--vjs) vjs $2; shift 2;;
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;; -*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
esac esac
done done
rm -rf $TEMP_GENERATOR_DIR; cd "$REPO_DIR"
git clone https://$TOKEN@github.com/$NAME_REPO.git $TEMP_GENERATOR_DIR JS_API_INSTALLED=$(npm list @alfresco/js-api --depth=0 --json | jq -r '.dependencies["@alfresco/js-api"].version')
cd $TEMP_GENERATOR_DIR
git checkout develop
BRANCH="ADF-update-$VERSION" echo "Current installed JS-API $JS_API_INSTALLED"
git checkout -b $BRANCH
./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 . rm -rf $TEMP_GENERATOR_DIR
git commit -m "Update ADF packages version $VERSION"
git push -u origin $BRANCH
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 $?