mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
AAE-11918A - remove travis env var (#8312)
* AAE-11918 - travis_branch env removal * AAE-11918 - travis_branch env removal * event_type and travis_pull_request_branch env removal * e travis_build_dir, travis_build_number, travis_commit env removal * rename scripts path * remove .travis file * remove .travis file * remove .travis file * just a commit * trying to fix e2e test * fix e2e issue * remove action load travis env * with action travis env var load * remove action travis load env vars * remove action travis load env vars * remove action travis load env vars * last check * test release flow in dry-run * final check for review * fix env variables * fix env variables * fix env variables * remove devel flag * revert renaming action facade * git mv commit * git mv commit
This commit is contained in:
21
scripts/github/affected-contains.sh
Executable file
21
scripts/github/affected-contains.sh
Executable file
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
verifyLib=$1;
|
||||
cd $DIR/../../
|
||||
|
||||
if [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
|
||||
#echo "Affected not check in case of cron"
|
||||
echo true
|
||||
exit 0
|
||||
fi
|
||||
AFFECTED_LIBS=$(npx nx print-affected --type=lib --select=projects ${NX_CALCULATION_FLAGS} --plain)
|
||||
#echo "Verify if affected build contains $1"
|
||||
#echo "Affected libs:$AFFECTED_LIBS"
|
||||
if [[ $AFFECTED_LIBS =~ $verifyLib ]]; then
|
||||
#echo "Yep project:$verifyLib is affected carry on"
|
||||
echo true
|
||||
else
|
||||
#echo "Nope project NOT affected save time"
|
||||
echo false
|
||||
fi;
|
14
scripts/github/build/bumpversion.sh
Executable file
14
scripts/github/build/bumpversion.sh
Executable file
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
cd $DIR/../../../
|
||||
BRANCH=${GITHUB_REF##*/}
|
||||
if [[ $BRANCH =~ ^develop(-patch.*)?$ ]]
|
||||
then
|
||||
echo "Replace NPM version with new Alpha tag"
|
||||
NEXT_VERSION=-nextalpha
|
||||
./scripts/update-version.sh -gnu $NEXT_VERSION || exit 1;
|
||||
fi
|
||||
|
||||
|
135
scripts/github/build/npm-check-bundles.sh
Executable file
135
scripts/github/build/npm-check-bundles.sh
Executable file
@@ -0,0 +1,135 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
eval VERSION=""
|
||||
|
||||
eval projects=( "adf-core"
|
||||
"adf-insights"
|
||||
"adf-content-services"
|
||||
"adf-extensions"
|
||||
"adf-testing"
|
||||
"adf-process-services"
|
||||
"adf-process-services-cloud" )
|
||||
|
||||
show_help() {
|
||||
echo "Usage: npm-check-bundles.sh"
|
||||
echo "-r or -registry to check -r 'http://npm.local.me:8080/' "
|
||||
echo "-v or -version to check -v 1.4.0 "
|
||||
echo ""
|
||||
}
|
||||
|
||||
change_registry() {
|
||||
echo $1
|
||||
npm set registry $1
|
||||
}
|
||||
|
||||
set_npm_registry() {
|
||||
npm set registry https://registry.npmjs.org/
|
||||
}
|
||||
|
||||
version() {
|
||||
VERSION=$1
|
||||
}
|
||||
|
||||
error_out() {
|
||||
printf '\033[%sm%s\033[m\n' "$@"
|
||||
# usage color "31;5" "string"
|
||||
# 0 default
|
||||
# 5 blink, 1 strong, 4 underlined
|
||||
# fg: 31 red, 32 green, 33 yellow, 34 blue, 35 purple, 36 cyan, 37 white
|
||||
# bg: 40 black, 41 red, 44 blue, 45 purple
|
||||
}
|
||||
|
||||
while [[ $1 == -* ]]; do
|
||||
case "$1" in
|
||||
-h|--help|-\?) show_help; exit 0;;
|
||||
-r) change_registry $2; shift 2;;
|
||||
-v|--version) version $2; shift 2;;
|
||||
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
rm -rf temp
|
||||
mkdir temp
|
||||
cd temp
|
||||
|
||||
for PACKAGE in ${projects[@]}
|
||||
do
|
||||
mkdir $PACKAGE
|
||||
cd $PACKAGE
|
||||
npm pack '@alfresco/'$PACKAGE@$VERSION
|
||||
tar zxf 'alfresco-'$PACKAGE-$VERSION.tgz
|
||||
|
||||
|
||||
if [ $PACKAGE == 'adf-testing' ]; then
|
||||
if [ ! -f package/'main.js' ]; then
|
||||
error_out '31;1' "$PACKAGE testing not ok!" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "testing ok!"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ $PACKAGE == 'adf-core' ]; then
|
||||
if [ ! -f package/lib/prebuilt-themes/'adf-blue-orange.css' ]; then
|
||||
error_out '31;1' "$PACKAGE prebuilt-theme not found!" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "prebuilt-theme ok!"
|
||||
fi
|
||||
|
||||
fi
|
||||
|
||||
if [ $PACKAGE != 'adf-testing' ]; then
|
||||
|
||||
if [ ! -f package/fesm2015/$PACKAGE'.mjs' ]; then
|
||||
error_out '31;1' "fesm2015/$PACKAGE.mjs not found!" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "fesm2015 ok!"
|
||||
fi
|
||||
|
||||
if [ ! -f package/esm2020/$PACKAGE'.mjs' ]; then
|
||||
error_out '31;1' "esm2020/$PACKAGE.mjs not found!" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "esm2020 ok!"
|
||||
fi
|
||||
|
||||
if [ ! -f package/fesm2020/$PACKAGE'.mjs' ]; then
|
||||
error_out '31;1' "fesm2020/$PACKAGE.mjs not found!" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "fesm2020 ok!"
|
||||
fi
|
||||
|
||||
if [ ! -f package/README.md ]; then
|
||||
error_out '31;1' "$PACKAGE readme not found!" >&2
|
||||
exit 1
|
||||
else
|
||||
echo "readme ok!"
|
||||
fi
|
||||
|
||||
if [ ! -f package/bundles/assets/$PACKAGE/i18n/en.json ]; then
|
||||
if [ $PACKAGE == 'adf-extensions' ]; then
|
||||
echo "no i18n needed"
|
||||
elif [ $PACKAGE == 'adf-testing' ]; then
|
||||
echo "no i18n needed"
|
||||
else
|
||||
error_out '31;1' "$PACKAGE i18n not found!" >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "i18n ok!"
|
||||
fi
|
||||
fi
|
||||
|
||||
cd ..
|
||||
done
|
||||
cd ..
|
||||
|
||||
rm -rf temp
|
||||
|
||||
set_npm_registry
|
||||
|
59
scripts/github/e2e/e2e.sh
Executable file
59
scripts/github/e2e/e2e.sh
Executable file
@@ -0,0 +1,59 @@
|
||||
#!/usr/bin/env bash
|
||||
echo "Start e2e"
|
||||
set -e
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
cd $DIR/../../../
|
||||
|
||||
BASE_DIRECTORY=$(echo "$FOLDER" | cut -d "/" -f1)
|
||||
verifyLib=$1;
|
||||
REGEX="(repository|workflow)_dispatch"
|
||||
|
||||
# set test-e2e params
|
||||
if [ -n "$2" ]; then
|
||||
e2eParams="--$2"
|
||||
else
|
||||
e2eParams=""
|
||||
fi
|
||||
|
||||
echo "Step1 - Verify if affected libs contains $verifyLib"
|
||||
|
||||
AFFECTED_LIB=$(./scripts/github/affected-contains.sh $verifyLib )
|
||||
|
||||
if [ ${AFFECTED_LIB} == true ]; then
|
||||
echo "Step2 - $verifyLib affected... will execute e2e"
|
||||
|
||||
if [ "${GITHUB_EVENT_NAME}" == "pull_request" ]; then
|
||||
echo "Calculate affected e2e $BASE_HASH $HEAD_HASH"
|
||||
echo "nx affected:libs --base=$BASE_HASH --head=$HEAD_HASH --plain"
|
||||
AFFECTED_LIBS="$(nx affected:libs --base=$BASE_HASH --head=$HEAD_HASH --plain || exit 1)"
|
||||
echo "Affected libs ${AFFECTED_LIBS}"
|
||||
AFFECTED_E2E="$(./scripts/git-util/affected-folder.sh -b $GITHUB_BASE_REF -f "e2e/$FOLDER")";
|
||||
echo "Affected e2e ${AFFECTED_E2E}"
|
||||
fi;
|
||||
|
||||
if [ "${GITHUB_EVENT_NAME}" == "schedule" ]; then
|
||||
echo "CRON running everything "
|
||||
fi;
|
||||
|
||||
if [[ $AFFECTED_LIBS =~ "testing" || $AFFECTED_LIBS =~ "$BASE_DIRECTORY" || "${GITHUB_EVENT_NAME}" == "push" || "${GITHUB_EVENT_NAME}" == "$REGEX" || "${GITHUB_EVENT_NAME}" == "schedule" ]]; then
|
||||
echo "Run all e2e $FOLDER"
|
||||
./scripts/test-e2e-lib.sh --use-dist $e2eParams
|
||||
else if [[ $AFFECTED_E2E == "e2e/$FOLDER" ]]; then
|
||||
echo "Run affected e2e"
|
||||
|
||||
HEAD_SHA_BRANCH="$(git merge-base origin/$GITHUB_HEAD_REF HEAD)"
|
||||
LIST_SPECS="$(git diff --name-only $HEAD_SHA_BRANCH HEAD | grep "^e2e/$FOLDER" | paste -sd , -)"
|
||||
|
||||
echo "Run $FOLDER e2e based on the sha $HEAD_SHA_BRANCH with the specs: "$LIST_SPECS
|
||||
|
||||
if [[ $LIST_SPECS != "" ]]; then
|
||||
./scripts/test-e2e-lib.sh --use-dist $e2eParams
|
||||
fi
|
||||
fi
|
||||
fi;
|
||||
|
||||
else
|
||||
echo "Step2 - Lib $verifyLib NOT affected. No need to run e2e"
|
||||
exit 0
|
||||
fi
|
68
scripts/github/release/deprecate-develop-build.sh
Executable file
68
scripts/github/release/deprecate-develop-build.sh
Executable file
@@ -0,0 +1,68 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
eval VERSION=""
|
||||
|
||||
eval projects=( "adf-core"
|
||||
"adf-insights"
|
||||
"adf-content-services"
|
||||
"adf-extensions"
|
||||
"adf-testing"
|
||||
"adf-process-services"
|
||||
"adf-process-services-cloud" )
|
||||
|
||||
show_help() {
|
||||
echo "Usage: deprecate-develop-build.sh"
|
||||
echo "-v or -version to check -v 1.4.0 "
|
||||
echo ""
|
||||
}
|
||||
|
||||
set_npm_registry() {
|
||||
npm set registry https://registry.npmjs.org/
|
||||
}
|
||||
|
||||
version() {
|
||||
if [[ $1 == "" ]];
|
||||
then
|
||||
echo "You need to add a version"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
VERSION=$1
|
||||
}
|
||||
|
||||
while [[ $1 == -* ]]; do
|
||||
case "$1" in
|
||||
-h|--help|-\?) show_help; exit 0;;
|
||||
-v|--version) version $2; shift 2;;
|
||||
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
|
||||
if [[ $VERSION == "" ]];
|
||||
then
|
||||
echo "You need to add a version"
|
||||
fi
|
||||
|
||||
for PACKAGE in ${projects[@]}
|
||||
do
|
||||
echo "@alfresco/$PACKAGE"
|
||||
|
||||
for VERSION_TO_DEPRECATE in $(npm view "@alfresco/$PACKAGE" versions --json | jq -r '.[] | select( . | match("-[0-9].*$") ) | select( . | contains("'$VERSION'"))')
|
||||
do
|
||||
deprecated=$(npm view "@alfresco/$PACKAGE@$VERSION_TO_DEPRECATE" -json | jq '.deprecated')
|
||||
|
||||
if [[ $deprecated != null ]];
|
||||
then
|
||||
echo "Already deprecated @alfresco/$PACKAGE@$VERSION_TO_DEPRECATE"
|
||||
else
|
||||
echo "Deprecate alpha/beta version @alfresco/$PACKAGE@$VERSION_TO_DEPRECATE"
|
||||
npm deprecate "@alfresco/$PACKAGE@$VERSION_TO_DEPRECATE" "Upgrade to @latest or $VERSION"
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
done
|
||||
|
20
scripts/github/release/docker-tag.sh
Executable file
20
scripts/github/release/docker-tag.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd $DIR/../../../
|
||||
BRANCH=${GITHUB_REF##*/}
|
||||
if [[ $BRANCH =~ ^master(-patch.*)?$ ]]; then
|
||||
export TAGS=$(grep -m1 version package.json | awk '{ print $2 }' | sed 's/[", ]//g')
|
||||
else
|
||||
if [[ "${GITHUB_BASE_REF}" != "" ]];
|
||||
then
|
||||
export TAGS="${GITHUB_BASE_REF}-$GH_BUILD_NUMBER"
|
||||
else
|
||||
export TAGS="$GITHUB_BASE_REF-$GH_BUILD_NUMBER,$GITHUB_BASE_REF"
|
||||
fi;
|
||||
fi;
|
||||
|
||||
if [[ -n "$GITHUB_ACTIONS" ]]; then
|
||||
echo "TAGS=$TAGS" >> $GITHUB_ENV;
|
||||
fi
|
||||
echo "$TAGS"
|
22
scripts/github/release/git-tag.sh
Executable file
22
scripts/github/release/git-tag.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [[ $BRANCH == "master" ]]; then
|
||||
VERSION=$(grep -m1 version package.json | awk '{ print $2 }' | sed 's/[", ]//g')
|
||||
else
|
||||
VERSION=$(npm view @alfresco/adf-core@beta version)
|
||||
fi;
|
||||
|
||||
echo "git tag -a ${VERSION} -m ${VERSION}"
|
||||
git config --local user.name "alfresco-build"
|
||||
git config --local user.email "build@alfresco.com"
|
||||
git tag -a ${VERSION} -m "${VERSION} [ci skip] "
|
||||
git remote rm origin
|
||||
GITHUB_REPO=https://$GITHUB_TOKEN:x-oauth-basic@github.com/Alfresco/alfresco-ng2-components.git
|
||||
git remote add origin $GITHUB_REPO
|
||||
|
||||
if [[ "$1" == "--dryrun" ]]; then
|
||||
echo "dry run: Pushing new tag ${VERSION}!"
|
||||
else
|
||||
echo "Pushing new tag ${VERSION}!"
|
||||
git push origin --tags
|
||||
fi;
|
20
scripts/github/release/release-demoshell-docker.sh
Executable file
20
scripts/github/release/release-demoshell-docker.sh
Executable file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd $DIR/../../../
|
||||
|
||||
echo "ℹ️ demo-shell: Running the docker with tag" $TAGS
|
||||
|
||||
DOCKER_PROJECT_ARGS="PROJECT_NAME=demo-shell"
|
||||
|
||||
# Publish Image to docker
|
||||
./node_modules/@alfresco/adf-cli/bin/adf-cli docker \
|
||||
--loginCheck \
|
||||
--loginUsername "$DOCKER_REPOSITORY_USER" \
|
||||
--loginPassword "$DOCKER_REPOSITORY_PASSWORD" \
|
||||
--loginRepo "$DOCKER_REPOSITORY_DOMAIN" \
|
||||
--dockerRepo "$DOCKER_REPOSITORY" \
|
||||
--buildArgs "$DOCKER_PROJECT_ARGS" \
|
||||
--dockerTags "$TAGS" \
|
||||
--pathProject "$(pwd)" \
|
||||
"$@"
|
40
scripts/github/release/release-npm.sh
Executable file
40
scripts/github/release/release-npm.sh
Executable file
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
|
||||
cd $DIR/../../../
|
||||
|
||||
VERSION_IN_PACKAGE_JSON=`node -p "require('./package.json')".version;`;
|
||||
BRANCH=${GITHUB_REF##*/}
|
||||
if [[ $BRANCH =~ ^master(-patch.*)?$ ]]
|
||||
then
|
||||
# Pre-release versions
|
||||
if [[ $VERSION_IN_PACKAGE_JSON =~ ^[0-9]*\.[0-9]*\.[0-9]*-A\.[0-9]*$ ]];
|
||||
then
|
||||
TAG_NPM=next
|
||||
# Stable major versions
|
||||
else
|
||||
TAG_NPM=latest
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $BRANCH =~ ^develop(-patch.*)?$ ]]
|
||||
then
|
||||
TAG_NPM=alpha
|
||||
fi
|
||||
|
||||
echo "Publishing on GH PKG registry with tag $TAG_NPM"
|
||||
./node_modules/@alfresco/adf-cli/bin/adf-cli npm-publish \
|
||||
--npmRegistry "npm.pkg.github.com" \
|
||||
--tokenRegistry $github_token \
|
||||
--tag $TAG_NPM \
|
||||
--pathProject "$(pwd)" \
|
||||
"$@"
|
||||
|
||||
echo "Publishing on Public npm registry with tag $TAG_NPM"
|
||||
./node_modules/@alfresco/adf-cli/bin/adf-cli npm-publish \
|
||||
--npmRegistry $NPM_REGISTRY_ADDRESS \
|
||||
--tokenRegistry $NPM_REGISTRY_TOKEN \
|
||||
--tag $TAG_NPM \
|
||||
--pathProject "$(pwd)" \
|
||||
"$@"
|
22
scripts/github/release/release-storybook-docker.sh
Executable file
22
scripts/github/release/release-storybook-docker.sh
Executable file
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
cd $DIR/../../../
|
||||
|
||||
echo "ℹ️ storybook-shell: Running the docker with tag" $TAGS
|
||||
|
||||
DOCKER_PROJECT_ARGS="PROJECT_NAME=storybook/stories"
|
||||
|
||||
echo "{}" > $DIR/../../../dist/storybook/stories/app.config.json
|
||||
|
||||
# Publish Image to docker
|
||||
./node_modules/@alfresco/adf-cli/bin/adf-cli docker \
|
||||
--loginCheck \
|
||||
--loginUsername "$DOCKER_REPOSITORY_USER" \
|
||||
--loginPassword "$DOCKER_REPOSITORY_PASSWORD" \
|
||||
--loginRepo "$DOCKER_REPOSITORY_DOMAIN" \
|
||||
--dockerRepo "$DOCKER_REPOSITORY_STORYBOOK" \
|
||||
--buildArgs "$DOCKER_PROJECT_ARGS" \
|
||||
--dockerTags "$TAGS" \
|
||||
--pathProject "$(pwd)" \
|
||||
"$@"
|
7
scripts/github/storybook-testing/storybook-test.sh
Executable file
7
scripts/github/storybook-testing/storybook-test.sh
Executable file
@@ -0,0 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Increase the max_user_watches
|
||||
sudo sysctl -w fs.inotify.max_user_watches=524288
|
||||
|
||||
# Run Playwright Storybook Tests
|
||||
npx playwright test --config='e2e-playwright/playwright.config.ts' || exit 1
|
71
scripts/github/update/adf-same-commit-verify.js
Normal file
71
scripts/github/update/adf-same-commit-verify.js
Normal 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);
|
||||
});
|
135
scripts/github/update/pr-creator.js
Normal file
135
scripts/github/update/pr-creator.js
Normal file
@@ -0,0 +1,135 @@
|
||||
const GitHub = require('github-api');
|
||||
let program = require('commander');
|
||||
|
||||
const ORGANISATION = 'Alfresco';
|
||||
const ORIGIN_REPO = 'alfresco-ng2-components';
|
||||
const ATTEMPT_MSG = [
|
||||
`Could you check it please? 🤖`,
|
||||
`Emm did you forget? 🤡`,
|
||||
`Where are you? 🤷`,
|
||||
`We are going to die!! 👻`,
|
||||
`I guess the Apocalypse happened and I am alone 👽`
|
||||
];
|
||||
|
||||
GIVE_UP_MSG = `I gave up, it will be fix eventually 🔴`;
|
||||
|
||||
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.issue = this.github.getIssues(githubUser, githubRepo);
|
||||
this.commit = commit;
|
||||
}
|
||||
|
||||
async createOrUpdate(title, head, base, commit) {
|
||||
const { data: prs } = await this.repoDestination.listPullRequests({ state: 'open', head: `${ORGANISATION}:${head}`, base });
|
||||
|
||||
if (prs.length < 1) {
|
||||
const { data: pr } = await this.repoDestination.createPullRequest({ title, head, base, body: `sha:${commit}` });
|
||||
return pr.number;
|
||||
} else {
|
||||
const upstreamPrOpen = prs[0];
|
||||
// override the title to contains the latest adf dep number
|
||||
await this.repoDestination.updatePullRequest(upstreamPrOpen.number, { title, body: `sha:${commit}` });
|
||||
return upstreamPrOpen.number;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
async fetchContributors(shaFrom, shaTo) {
|
||||
const mapAuthors = new Map();
|
||||
let upstreamShaFound = true;
|
||||
const listCommits = await this.repoOrigin.listCommits(({sha: shaFrom}))
|
||||
let index = 0;
|
||||
while(upstreamShaFound) {
|
||||
if (listCommits.data[index].sha === shaTo ) {
|
||||
upstreamShaFound = false;
|
||||
} else {
|
||||
mapAuthors.set(listCommits.data[index].author.login, listCommits.data[index].commit.author.name);
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return mapAuthors;
|
||||
}
|
||||
|
||||
async createComment(issueOrPrNumber, head, base, shaOriginHead ) {
|
||||
const shaTo = await this.getShaTo(head, base);
|
||||
const contributors = await this.fetchContributors(shaOriginHead, shaTo);
|
||||
const attemptCount = await this.getCommentAmount(issueOrPrNumber);
|
||||
const commentMsg = this.createCommentBody(contributors, attemptCount);
|
||||
await this.issue.createIssueComment(issueOrPrNumber, commentMsg);
|
||||
}
|
||||
|
||||
createCommentBody(contributors, attemptCount) {
|
||||
const flattenedContributors = this.flattenContributors(contributors);
|
||||
const attemptMsg = attemptCount <= 5 ? ATTEMPT_MSG[attemptCount] : GIVE_UP_MSG
|
||||
const tmpl = ` Attempt: ${attemptCount+1}
|
||||
you are part of the contributors:
|
||||
${flattenedContributors}
|
||||
${attemptMsg}
|
||||
`;
|
||||
return tmpl;
|
||||
}
|
||||
|
||||
flattenContributors(contributors) {
|
||||
let names = [];
|
||||
for (let key of contributors.keys()) {
|
||||
names.push(`@${key}`)
|
||||
}
|
||||
return names.join(', ');
|
||||
}
|
||||
|
||||
async getShaTo(head, base) {
|
||||
const { data: closedUpstreamPRs } = await this.repoDestination.listPullRequests({ state: 'closed', head: `${ORGANISATION}:${head}`, base });
|
||||
const latestClosedUpstream = closedUpstreamPRs[0];
|
||||
const shaTo = latestClosedUpstream.body.split(':')[1].trim();
|
||||
return shaTo;
|
||||
}
|
||||
|
||||
async getCommentAmount(issueOrPrNumber) {
|
||||
const { data: listComments } = await this.issue.listIssueComments(issueOrPrNumber);
|
||||
return listComments.length;
|
||||
}
|
||||
}
|
||||
|
||||
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')
|
||||
.option('-title, --title [type]', 'title')
|
||||
.parse(process.argv);
|
||||
|
||||
const { token, title, head, repo, commit } = program,
|
||||
prCreator = new PrCreator(ORGANISATION, repo, token, commit);
|
||||
|
||||
if (!token || !head || !title) {
|
||||
throw new Error('Each of the parameters have to be provided. --token, --title, --head');
|
||||
}
|
||||
const baseBranchName = 'develop';
|
||||
|
||||
const prNumber = await prCreator.createOrUpdate(title, head, baseBranchName, commit);
|
||||
await prCreator.createComment(prNumber, head, baseBranchName, commit);
|
||||
|
||||
return prNumber;
|
||||
}
|
||||
|
||||
main()
|
||||
.then(prNumber => {
|
||||
console.log("======= PR Created =========");
|
||||
|
||||
console.log(prNumber)
|
||||
process.exit(0);
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
console.error("======= Impossible create PR =========");
|
||||
console.error(error.response.status);
|
||||
console.error(error.response.statusText);
|
||||
process.exit(1);
|
||||
});
|
172
scripts/github/update/update-project.sh
Executable file
172
scripts/github/update/update-project.sh
Executable file
@@ -0,0 +1,172 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
git config --global user.name "alfresco-build"
|
||||
git config --global user.email "alfresco-build@hyland.com"
|
||||
|
||||
BUILD_PIPELINE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
||||
REPO_DIR="$BUILD_PIPELINE_DIR/../.."
|
||||
|
||||
TEMP_GENERATOR_DIR=".tmp-generator";
|
||||
BRANCH_TO_CREATE="update-alfresco-dependencies"
|
||||
TOKEN=""
|
||||
PR_NUMBER=""
|
||||
DRY_RUN="false"
|
||||
|
||||
show_help() {
|
||||
echo "Usage: create-updatebranch.sh"
|
||||
echo ""
|
||||
echo "-t or --token: Github ouath token"
|
||||
echo "-p or --pr: Originating jsapi PR number"
|
||||
echo "-v or --version version to update"
|
||||
echo "-d or --dry-run: The script won't execute critical operation, just simulate them"
|
||||
echo "-r or --repo: Repository to update"
|
||||
}
|
||||
|
||||
set_token() {
|
||||
TOKEN=$1
|
||||
}
|
||||
|
||||
set_pr() {
|
||||
PR_NUMBER=$1
|
||||
}
|
||||
|
||||
version() {
|
||||
VERSION=$1
|
||||
}
|
||||
|
||||
set_commit() {
|
||||
COMMIT=$1
|
||||
}
|
||||
|
||||
set_dryrun() {
|
||||
|
||||
DRY_RUN="true"
|
||||
|
||||
}
|
||||
|
||||
set_repo() {
|
||||
REPO=$1
|
||||
}
|
||||
|
||||
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 "[ci:force][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 "[ci:force][auto-commit] Update $PKG to $PKG_VERSION for branch: $BRANCH_TO_CREATE originated from $PKG PR: $PR_NUMBER"
|
||||
}
|
||||
|
||||
update() {
|
||||
NAME_REPO=$1
|
||||
PKG_VERSION=$(npm view @alfresco/adf-core@$VERSION version)
|
||||
|
||||
echo "Update dependencies for repo: $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
|
||||
BRANCH_CREATED=false
|
||||
if git checkout $BRANCH_TO_CREATE 2>/dev/null ; then
|
||||
git reset --hard origin/develop
|
||||
else
|
||||
BRANCH_CREATED=true
|
||||
git checkout -b $BRANCH_TO_CREATE origin/develop
|
||||
fi
|
||||
|
||||
update_js_dependency "@alfresco/js-api" $JS_API_INSTALLED
|
||||
|
||||
if [ "$NAME_REPO" = "alfresco-apps" ]; then
|
||||
update_dependency "@alfresco/adf-extensions"
|
||||
update_dependency "@alfresco/adf-core"
|
||||
update_dependency "@alfresco/adf-content-services"
|
||||
update_dependency "@alfresco/adf-process-services-cloud"
|
||||
update_dependency "@alfresco/adf-cli"
|
||||
update_dependency "@alfresco/adf-testing"
|
||||
else
|
||||
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"
|
||||
update_dependency "@alfresco/adf-cli"
|
||||
update_dependency "@alfresco/adf-testing"
|
||||
fi
|
||||
|
||||
|
||||
if [ "$BRANCH_CREATED" = true ]; then
|
||||
git push origin $BRANCH_TO_CREATE
|
||||
else
|
||||
git push --force origin $BRANCH_TO_CREATE
|
||||
fi
|
||||
|
||||
node $BUILD_PIPELINE_DIR/pr-creator.js --token=$TOKEN --title="Update branch for ADF ${PKG_VERSION} and JS-API ${JS_API_INSTALLED} [ci:force]" --head=$BRANCH_TO_CREATE --repo=$NAME_REPO --commit=$COMMIT
|
||||
|
||||
cd ..
|
||||
rm -rf $TEMP_GENERATOR_DIR
|
||||
}
|
||||
|
||||
while [[ $1 == -* ]]; do
|
||||
case "$1" in
|
||||
-h|--help|-\?) show_help; exit 0;;
|
||||
-t|--token) set_token $2; shift; shift;;
|
||||
-p|--pr) set_pr $2; shift; shift;;
|
||||
-v|--version) version $2; shift 2;;
|
||||
-c|--commit) set_commit $2; shift 2;;
|
||||
-d|--dry-run) set_dryrun $2; shift; shift;;
|
||||
-r|--repo) set_repo $2; shift; shift;;
|
||||
-*) echo "invalid option: $1" 1>&2; show_help; exit 1;;
|
||||
esac
|
||||
done
|
||||
|
||||
JS_API_INSTALLED=$(cat package.json | jq -r '.dependencies["@alfresco/js-api"]')
|
||||
echo "Current installed JS-API $JS_API_INSTALLED"
|
||||
|
||||
cd "$REPO_DIR"
|
||||
|
||||
if [[ (-z "$TOKEN") || (-z "$VERSION") ]]
|
||||
then
|
||||
echo "Each of token (-t) pr number (-p) and repo (-r) have to be set. See -help."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
rm -rf $TEMP_GENERATOR_DIR
|
||||
|
||||
|
||||
if [ "$DRY_RUN" = "false" ]; then
|
||||
if [ "$REPO" = "all" ]; then
|
||||
update "generator-alfresco-adf-app"
|
||||
update "alfresco-content-app"
|
||||
update "alfresco-applications"
|
||||
update "alfresco-apps"
|
||||
else
|
||||
update $REPO
|
||||
fi
|
||||
else
|
||||
echo "[dry-run] it would have update repos: $REPO "
|
||||
fi
|
||||
|
||||
exit $?
|
Reference in New Issue
Block a user