diff --git a/.gitignore b/.gitignore index bd433b2d73..08b482d839 100644 --- a/.gitignore +++ b/.gitignore @@ -6,7 +6,6 @@ dist/ /.tmp/ tmp/ - # Reports directory reports/ @@ -14,6 +13,9 @@ reports/ logs/ *.log +# Sec +stark-ssh + # Runtime data pids *.pid diff --git a/.travis.yml b/.travis.yml index 8706cecaae..30af1c0966 100644 --- a/.travis.yml +++ b/.travis.yml @@ -46,6 +46,8 @@ cache: script: - npm run lint:all - npm run test:ci:all + - npm run build:showcase + - npm run docs:publish - npm run release:publish - bash ./scripts/ci/print-logs.sh diff --git a/RELEASE.md b/RELEASE.md index c6a7467db8..4a19aa2db2 100644 --- a/RELEASE.md +++ b/RELEASE.md @@ -46,9 +46,58 @@ Refer to the "Adapting tags of published packages" section below. After this, the release is tagged and visible on github -### publish -Once the tag is pushed to GitHub, Travis picks it up and initiates a build. -Travis executes builds, tests, then executes `npm run release:publish`. +### documentation publish + +#### What +Once the tag is pushed to GitHub, Travis picks it up and initiates a build. + +Travis executes builds, tests, then executes `npm run docs:publish`. + +That script makes some checks then, if all succeed it publishes the API docs of the different packages as well as the production build output of the showcase to Github pages. + +#### How +Checks that are performed: +* node version: should be "8" +* TRAVIS_REPO_SLUG should be "NationalBankBelgium/stark" +* TRAVIS_TAG should be defined and not empty (this is the case when Travis builds for a tag) +* TRAVIS_PULL_REQUEST should be false +* TRAVIS_BRANCH should be "master" +* TRAVIS_EVENT_TYPE should be "cron" (i.e., not a nightly build or manual build) +* encrypted_... environment should be available (those have been created by encrypting our SSH key; cfr below!) + +More details here: https://github.com/NationalBankBelgium/stark/issues/282 + +#### Security +The docs publication uses an SSH key that has write access to the Stark repository. +That key is available in the source code in encrypted form in the `stark-ssh` file. +That file actually corresponds to the private key of an SSH key-pair encrypted using the Travis CLI (details below). + +#### Replacing the GitHub credentials (SSH key) +To replace the keys used by the docs publish script: +* create a new SSH key pair: `ssh-keygen -t rsa -b 4096 -C "..."` + * call it `stark-ssh` for safety: that name is in the .gitignore list +* associate the public key with the Stark repository as a "Deploy Key": https://developer.github.com/v3/guides/managing-deploy-keys/ +* encrypt the private key with the Travis CLI: `travis encrypt-file ./stark-ssh -r NationalBankBelgium/stark` + * that command will generate an encrypted version of the key + * make sure you're logged in (see next section) +* save the encrypted file as `stark-ssh.enc` and get rid of the non-encrypted key directly + +The command will also + * store the (randomly generated) encryption key and initialization vector as (secure) Travis environment variables + * provide the openssl command to use in the scripts to decrypt the stark-ssh.enc file; for example: `openssl aes-256-cbc -K $encrypted_e546efaa49e5_key -iv $encrypted_e546efaa49e5_iv -in stark-ssh.enc -out ./stark-ssh -d`. + +The name of those variables will change each time it is used, therefore the `gh-deploy.sh` MUST also be adapted afterwards. + +#### Installing the Travis CLI +Steps: +* Install Ruby to get the `gem` command +* Install Travis CLI with gem install travis +* Login to Travis using GH credentials: travis login --org --github-token foo + * `Successfully logged in as ...` +* Have fun! + +### npm packages publish +Finally, Travis executes `npm run release:publish`. That script makes some checks then, if all succeed it publishes the different packages on npm. Checks that are performed: diff --git a/build-functions.sh b/build-functions.sh index 95e2ea9585..68daf2f433 100644 --- a/build-functions.sh +++ b/build-functions.sh @@ -1,30 +1,5 @@ #!/usr/bin/env bash -####################################### -# Verifies a directory isn't in the ignored list -# Arguments: -# param1 - Source folder -# param2 - Destination folder -# param3 - Options {Array} -####################################### -syncFiles() { - logTrace "${FUNCNAME[0]}" 1 - logDebug "Syncing files from $1 to $2" 1 - cd $1; # we go to the folder to execute it with relative paths - mkdir -p $2 - local REL_PATH_TO_DESTINATION=$(perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' $2 $1) - # local REL_PATH_TO_DESTINATION=$(realpath --relative-to="." "$2"); - shift 2; # those 2 parameters are not needed anymore - - logTrace "Syncing files using: rsync" 2 - if [[ ${TRACE} == true ]]; then - rsync "${@}" ./ $REL_PATH_TO_DESTINATION/ -v - else - rsync "${@}" ./ $REL_PATH_TO_DESTINATION/ - fi - cd - > /dev/null; # go back to the previous folder without any output -} - ####################################### # Verifies a directory isn't in the ignored list # Arguments: diff --git a/gh-deploy.sh b/gh-deploy.sh new file mode 100644 index 0000000000..983bc126aa --- /dev/null +++ b/gh-deploy.sh @@ -0,0 +1,320 @@ +#!/usr/bin/env bash + +# TODO +#=================== +# provide a clean way to define/check the "current" version of node (i.e., the one we should execute the publish under/for) +## ideally we should read it from .nvmrc +# for local deployment, instead of using stark-ssh.enc, we should use the GITHUB_API_KEY key passed via --github-api-key=foo +## if present then we could push directly without handling decryption, etc + +set -u -e -o pipefail + +VERBOSE=false +TRACE=false +DRY_RUN=false +ENFORCE_SHOWCASE_VERSION_CHECK=true +SOURCE_BRANCH="master" +TARGET_BRANCH="gh-pages" +COMMIT_HASH=`git rev-parse --verify HEAD` + +TARGET_REPO="git@github.com:NationalBankBelgium/stark.git" +EXPECTED_REPO_SLUG="NationalBankBelgium/stark" +EXPECTED_NODE_VERSION="8" + +COMMIT_AUTHOR_USERNAME="TravisCI" +COMMIT_AUTHOR_EMAIL="seb@dsebastien.net" + +SSH_KEY_ENCRYPTED="stark-ssh.enc" +SSH_KEY_CLEARTEXT_FILE="stark-ssh" + +STARK_CORE="stark-core" +STARK_UI="stark-ui" +SHOWCASE="showcase" +API_DOCS_DIR_NAME="api-docs" +LATEST_DIR_NAME="latest" + +#---------------------------------------------- +# Uncomment and adapt block below to test locally +#---------------------------------------------- +#LOGS_DIR=./.tmp/stark/logs +#mkdir -p ${LOGS_DIR} +#touch ${LOGS_DIR}/build-perf.log +#DRY_RUN=true +#TRAVIS=1 +#TRAVIS_NODE_VERSION="8" +#TRAVIS_COMMIT=${COMMIT_HASH} +#TRAVIS_REPO_SLUG="NationalBankBelgium/stark" # yes we're always on the correct repo +#TRAVIS_BRANCH=${SOURCE_BRANCH} # yes we're always on the correct branch +#ENFORCE_SHOWCASE_VERSION_CHECK=false # allows not have consistency between tag version and showcase version +#encrypted_e546efaa49e5_iv="foo" # variable needed for the decryption of the SSH private key +#encrypted_e546efaa49e5_key="bar" # variable needed for the decryption of the SSH private key + +# Point to a fork or any other repo +#TARGET_REPO="git@github.com:dsebastien/stark.git" + +# Avoid messing up Git config (even though limited to the current repo) +#COMMIT_AUTHOR_USERNAME="Sebastien Dubois" +#COMMIT_AUTHOR_EMAIL="seb@dsebastien.net" + +# For PRs (NOT accepted) +#TRAVIS_EVENT_TYPE="pull_request" + +# For nightly builds (NOT accepted) +#TRAVIS_PULL_REQUEST="false" +#TRAVIS_EVENT_TYPE="cron" + +# For releases +#TRAVIS_PULL_REQUEST="false" +#TRAVIS_TAG="barFoo" +#TRAVIS_EVENT_TYPE="push" + +#---------------------------------------------- + +readonly currentDir=$(cd $(dirname $0); pwd) + +source ${currentDir}/scripts/ci/_travis-fold.sh +source ${currentDir}/util-functions.sh + +cd ${currentDir} + +logInfo "=============================================" +logInfo "Stark docs publish @ github pages" + +for ARG in "$@"; do + case "$ARG" in + --dry-run) + logInfo "=============================================" + logInfo "Dry run enabled!" + DRY_RUN=true + ;; + --verbose) + logInfo "=============================================" + logInfo "Verbose mode enabled!" + VERBOSE=true + ;; + --trace) + logInfo "=============================================" + logInfo "Trace mode enabled!" + TRACE=true + ;; + --github-api-key=*) + logInfo "=============================================" + logInfo "Github API key provided" + GITHUB_API_KEY=${ARG#--github-api-key=} + ;; + *) + echo "Unknown option $ARG." + exit 1 + ;; + esac +done +logInfo "=============================================" + +PROJECT_ROOT_DIR=`pwd` +logTrace "PROJECT_ROOT_DIR: ${PROJECT_ROOT_DIR}" 1 + +ROOT_PACKAGES_DIR=${PROJECT_ROOT_DIR}/dist/packages-dist +logTrace "ROOT_PACKAGES_DIR: ${ROOT_PACKAGES_DIR}" 1 + +API_DOCS_SOURCE_DIR=${PROJECT_ROOT_DIR}/reports/${API_DOCS_DIR_NAME} +logTrace "API_DOCS_SOURCE_DIR: ${API_DOCS_SOURCE_DIR}" + +SHOWCASE_SOURCE_DIR=${PROJECT_ROOT_DIR}/${SHOWCASE}/dist +logTrace "SHOWCASE_SOURCE_DIR: ${SHOWCASE_SOURCE_DIR}" + +DOCS_WORK_DIR=${PROJECT_ROOT_DIR}/.tmp/ghpages +logTrace "DOCS_WORK_DIR: ${DOCS_WORK_DIR}" 1 + +logTrace "Cleaning the docs work directory..." 2 +rm -rf ${DOCS_WORK_DIR} +mkdir -p ${DOCS_WORK_DIR} + + +travisFoldStart "docs publication checks" "no-xtrace" + +if [[ ${TRAVIS:-} ]]; then + logInfo "Publishing docs to GH pages"; + logInfo "=============================================" + + # Don't even try if not running against the official repo + # We don't want docs publish to run outside of our own little world + if [[ ${TRAVIS_REPO_SLUG} != ${EXPECTED_REPO_SLUG} ]]; then + logInfo "Skipping release because this is not the main repository."; + exit 0; + fi + + # Ensuring that this is the execution for Node x + # Without this check, we would publish a release for each node version we test under! :) + if [[ ${TRAVIS_NODE_VERSION} != ${EXPECTED_NODE_VERSION} ]]; then + logInfo "Skipping release because this is not the expected version of node: ${TRAVIS_NODE_VERSION}" + exit 0; + fi + + logInfo "Verifying if this build has been triggered for a tag" + # Making sure the variables exist.. + if [[ -z ${TRAVIS_TAG+x} ]]; then + TRAVIS_TAG="" + fi + + if [[ -z ${TRAVIS_PULL_REQUEST+x} ]]; then + TRAVIS_PULL_REQUEST="" + fi + + if [[ ${TRAVIS_PULL_REQUEST} != "false" ]]; then + logInfo "Not publishing because this is a build triggered for a pull request" 1 + exit 0; + fi + + if [[ ${TRAVIS_BRANCH} != ${SOURCE_BRANCH} ]]; then + logInfo "Not publishing because this build's branch does not match the expected source branch" 1 + exit 0; + fi + + if [[ ${TRAVIS_EVENT_TYPE} == "cron" ]]; then + logInfo "Not publishing because this is a build triggered for a nightly build" 1 + exit 0; + fi + + if [[ ${TRAVIS_TAG} == "" ]]; then + logInfo "Not publishing because this is not a build triggered for a tag" 1 + exit 0; + else + logInfo "OK, this build has been triggered for a tag" + fi + + # Those keys are needed to decrypt the ${SSH_KEY_ENCRYPTED} file, which contains the SSH private key + # that we'll use to push to GitHub pages! + logInfo "Verifying that the necessary decryption keys are available" + if [[ -z ${encrypted_e546efaa49e5_iv+x} ]]; then + encrypted_e546efaa49e5_iv="" + fi + if [[ -z ${encrypted_e546efaa49e5_key+x} ]]; then + encrypted_e546efaa49e5_key="" + fi + + if [[ ${encrypted_e546efaa49e5_iv} == "" ]]; then + logInfo "Not publishing because the SSH key decryption IV is not available as environment variable" 1 + exit 0; + else + logTrace "SSH key decryption IV is available" 2 + ENCRYPTED_IV=${encrypted_e546efaa49e5_iv} + fi + + if [[ ${encrypted_e546efaa49e5_key} == "" ]]; then + logInfo "Not publishing because the SSH key decryption key is not available as environment variable" 1 + exit 0; + else + logTrace "SSH key decryption key is available" 2 + ENCRYPTED_KEY=${encrypted_e546efaa49e5_key} + fi + + # If any of the previous commands in the `script` section of .travis.yaml failed, then abort. + # The variable is not set in early stages of the build, so we default to 0 there. + # https://docs.travis-ci.com/user/environment-variables/ + if [[ ${TRAVIS_TEST_RESULT=0} == 1 ]]; then + logInfo "Skipping docs publication because a previous script in the Travis build has failed" 1 + exit 0; + fi +else + logInfo "Not publishing because we are not in Travis. Currently that is the only supported option!" + exit 0 +fi + +travisFoldEnd "docs publication checks" + + +travisFoldStart "docs generation" "no-xtrace" + +logInfo "Generating API docs" +npm run docs:all +logTrace "API docs generated successfully" 1 + +travisFoldEnd "docs generation" "no-xtrace" + + + +travisFoldStart "docs publication" "no-xtrace" + +logInfo "Publishing API docs" + +logTrace "Determining target folders for api docs" 1 + +DOCS_VERSION=${TRAVIS_TAG} +SHOWCASE_PACKAGE_VERSION=$(node -p "require('./package.json').version") +#alternative (faster but less safe): SHOWCASE_PACKAGE_VERSION=$(sed -nE 's/^\s*"version": "(.*?)",$/\1/p' package.json) + +if [[ ${ENFORCE_SHOWCASE_VERSION_CHECK} == true ]]; then + logTrace "Checking for version consistency between the tag and the showcase" 1 + if [[ ${DOCS_VERSION} != ${SHOWCASE_PACKAGE_VERSION} ]]; then + logInfo "Cannot publish the documentation because the showcase version does not match the tagged version (tag name). Please update the showcase!" + exit -1; + fi +fi + +logTrace "Version for which we are producing docs: ${DOCS_VERSION}" + +if [[ ${TRAVIS:-} ]]; then + logTrace "Configuring Git for Travis" + git config user.name ${COMMIT_AUTHOR_USERNAME} + git config user.email ${COMMIT_AUTHOR_EMAIL} +fi + +logTrace "Cloning stark's github pages branch to ${DOCS_WORK_DIR}" + +if [[ ${DRY_RUN} == false ]]; then + logTrace "Decrypting the SSH private key" + openssl aes-256-cbc -K ${ENCRYPTED_KEY} -iv ${ENCRYPTED_IV} -in ./${SSH_KEY_ENCRYPTED} -out ./${SSH_KEY_CLEARTEXT_FILE} -d + logTrace "Decrypted the SSH private key" + # we use our decrypted private SSH key + alias git="GIT_SSH_COMMAND='ssh -i ./${SSH_KEY_CLEARTEXT_FILE}' git" +fi + +git clone --quiet --depth=1 --branch=${TARGET_BRANCH} ${TARGET_REPO} ${DOCS_WORK_DIR} + +logTrace "Copying the API docs" +API_DOCS_TARGET_DIR_STARK_CORE=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_CORE}/${DOCS_VERSION} +API_DOCS_TARGET_DIR_STARK_CORE_LATEST=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_CORE}/${LATEST_DIR_NAME} + +API_DOCS_TARGET_DIR_STARK_UI=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_UI}/${DOCS_VERSION} +API_DOCS_TARGET_DIR_STARK_UI_LATEST=${DOCS_WORK_DIR}/${API_DOCS_DIR_NAME}/${STARK_UI}/${LATEST_DIR_NAME} + +SHOWCASE_TARGET_DIR=${DOCS_WORK_DIR}/${SHOWCASE}/${DOCS_VERSION} +SHOWCASE_TARGET_DIR_LATEST=${DOCS_WORK_DIR}/${SHOWCASE}/${LATEST_DIR_NAME} + +syncOptions=(--archive --delete --ignore-errors --quiet --include="**/**") # we overwrite docs if they're present already for this version + +logTrace "Copying ${STARK_CORE} API docs" +syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_CORE} ${API_DOCS_TARGET_DIR_STARK_CORE} "${syncOptions[@]}" +syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_CORE} ${API_DOCS_TARGET_DIR_STARK_CORE_LATEST} "${syncOptions[@]}" + +logTrace "Copying ${STARK_UI} API docs" +syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_UI} ${API_DOCS_TARGET_DIR_STARK_UI} "${syncOptions[@]}" +syncFiles ${API_DOCS_SOURCE_DIR}/${STARK_UI} ${API_DOCS_TARGET_DIR_STARK_UI_LATEST} "${syncOptions[@]}" + +logTrace "Copying ${SHOWCASE}" + +syncFiles ${SHOWCASE_SOURCE_DIR} ${SHOWCASE_TARGET_DIR} "${syncOptions[@]}" +syncFiles ${SHOWCASE_SOURCE_DIR} ${SHOWCASE_TARGET_DIR_LATEST} "${syncOptions[@]}" + +unset syncOptions + +logInfo "Pushing the docs to GitHub pages" + +cd ${DOCS_WORK_DIR} +git add -A &> /dev/null # way too long +git commit --quiet -m "Publishing docs for version: ${DOCS_VERSION}" +git push --quiet --force +cd - > /dev/null + +# TODO: if a GITHUB_API_KEY was passed, then we should use it +#if [[ ${GITHUB_API_KEY} != "" ]]; then +# logTrace "Using the provided GITHUB API KEY to push" 1 +# exit 0; +#fi + +logInfo "Documentation published successfully!" + +travisFoldEnd "docs publication" + +# Print return arrows as a log separator +travisFoldReturnArrows diff --git a/package.json b/package.json index 43a9287b1b..565baa56be 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "build:stark-core": "npm run build -- --packages=stark-core", "build:stark-testing": "npm run build -- --packages=stark-testing", "build:stark-ui": "npm run build -- --packages=stark-ui", + "build:showcase": "cd showcase && npm run build:prod && cd ..", "clean": "npx rimraf ./dist", "clean:all": "npm run clean && npm run clean:stark-build && npm run clean:stark-core && npm run clean:stark-ui && npm run clean:stark-testing && npm run clean:starter && npm run clean:showcase", "clean:stark-build": "cd packages/stark-build && npm run clean && cd ../..", @@ -85,9 +86,10 @@ "commit": "./node_modules/.bin/git-cz", "commitmsg": "commitlint -e $GIT_PARAMS", "docs": "npm run docs:clean && npm run docs:all", - "docs:all": "npm run docs:stark-core && npm run docs:stark-ui", + "docs:all": "npm run docs:stark-core:generate && npm run docs:stark-ui:generate", "docs:clean": "npx rimraf reports/api-docs", "docs:coverage": "npm run docs:stark-core:coverage && npm run docs:stark-ui:coverage && npm run docs:starter:coverage", + "docs:publish": "bash ./gh-deploy.sh --trace", "docs:stark-core:coverage": "cd packages/stark-core && npm run docs:coverage && cd ../..", "docs:stark-core:generate": "cd packages/stark-core && npm run docs && cd ../..", "docs:stark-core:serve": "cd packages/stark-core && npm run docs:serve && cd ../..", diff --git a/release-publish.sh b/release-publish.sh index 44e0c9f3eb..462962ce2b 100644 --- a/release-publish.sh +++ b/release-publish.sh @@ -3,6 +3,7 @@ # TODO #=================== # provide a clean way to define/check the "current" version of node (i.e., the one we should execute the publish under/for) +## ideally we should read it from .nvmrc # provide support for publishing only a subset of the packages (same --packages logic as in build.sh) # provide support for publishing locally in addition to travis @@ -90,7 +91,7 @@ logTrace "ROOT_PACKAGES_DIR: ${ROOT_PACKAGES_DIR}" 1 travisFoldStart "publish checks" "no-xtrace" if [[ ${TRAVIS:-} ]]; then - logInfo "Publishing from Travis"; + logInfo "Publishing to npm"; logInfo "=============================================" # Don't even try if not running against the official repo @@ -114,13 +115,13 @@ if [[ ${TRAVIS:-} ]]; then fi if [[ ${TRAVIS_PULL_REQUEST} != "false" ]]; then - logTrace "Not publishing because this is a build triggered for a pull request" 1 + logInfo "Not publishing because this is a build triggered for a pull request" 1 exit 0; elif [[ ${TRAVIS_EVENT_TYPE} == "cron" ]]; then - logTrace "Nightly build initiated by Travis cron job" 1 + logInfo "Nightly build initiated by Travis cron job" 1 NIGHTLY_BUILD=true elif [[ ${TRAVIS_TAG} == "" ]]; then - logTrace "Not publishing because this is not a build triggered for a tag" 1 + logInfo "Not publishing because this is not a build triggered for a tag" 1 exit 0; else logInfo "This build has been triggered for a tag" @@ -132,7 +133,7 @@ if [[ ${TRAVIS:-} ]]; then fi if [[ ${NPM_TOKEN} == "" ]]; then - logTrace "Not publishing because the NPM_TOKEN environment variable is is not defined correctly" 1 + logInfo "Not publishing because the NPM_TOKEN environment variable is is not defined correctly" 1 exit 0; fi diff --git a/showcase/src/assets/img/tipe.png b/showcase/src/assets/img/tipe.png deleted file mode 100644 index 4939f07061..0000000000 Binary files a/showcase/src/assets/img/tipe.png and /dev/null differ diff --git a/stark-ssh.enc b/stark-ssh.enc new file mode 100644 index 0000000000..746df3cd1f Binary files /dev/null and b/stark-ssh.enc differ diff --git a/stark-ssh.pub b/stark-ssh.pub new file mode 100644 index 0000000000..a25bb568dc --- /dev/null +++ b/stark-ssh.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDDRsiK7omj+DgPa0VEGD/vMxeGz3O6uvXO1DSvDIqvtDwId5w7SEM2iEQQARNbHojbuj9U5mhVF4XWtKn1Qc5FdvKG8mfkJjB9vg9x4fAbD5qe0uZtYMashqhlpxLWMglIBfDMVlyVrxeBXrmOFcjdA5K303mLloF2H/XXoI3Zn+GzCu207ch0VBGYrFZiVAG2xqWJevY3xY5aix4ipQwE9vGp2aPsOuzNWArPG02cTSfB7jc7rzx/mAOd7uonJFiXpwc8hVAmcEa5hW8Cyub+7Th4CZj4YcEyKxjlfhKHla/71s4w1TG10/UcU5SdAjRMhmTpLq1JCYjdcxSyoCA8V8fYkcyJ90txCQRHpwenk8C1cPCgSB316eurdqrPaJWQaPvoQ8jIkaSJtVGigwDJLyVxJ1sfkLPmDyxZWcW5eW92hfP0XwYC5A0EHX4d7ppm25YfLukZQPOW7fvR/KhBM3a5QIIj5TDK04aUJ+NQKlRNnODeYqkV7Uhm57oDcTkhDeED3dgviVvQdJh/2To4zjUWaFRrd/n16FdGFoQCHvczCc0zSaUcKEHwPDFe3g2MrRMptC7xwbKCMclS/+quK1Kdb8zEXHj50w+lGOOeKy63/v/gxQ4FjdObXis34V0vQBTK9nbBi/D83qWXakHqaaouGcFZukh1Rf2SZbd9ow== seb@dsebastien.net diff --git a/util-functions.sh b/util-functions.sh index 04365c6492..1e4acbd34d 100644 --- a/util-functions.sh +++ b/util-functions.sh @@ -47,3 +47,28 @@ logInfo() { printf -v spacing '%*s' "$numSpaces" printf "${spacing}%s\n" "$message" } + +####################################### +# Verifies a directory isn't in the ignored list +# Arguments: +# param1 - Source folder +# param2 - Destination folder +# param3 - Options {Array} +####################################### +syncFiles() { + logTrace "${FUNCNAME[0]}" 1 + logDebug "Syncing files from $1 to $2" 1 + cd $1; # we go to the folder to execute it with relative paths + mkdir -p $2 + local REL_PATH_TO_DESTINATION=$(perl -e 'use File::Spec; print File::Spec->abs2rel(@ARGV) . "\n"' $2 $1) + # local REL_PATH_TO_DESTINATION=$(realpath --relative-to="." "$2"); + shift 2; # those 2 parameters are not needed anymore + + logTrace "Syncing files using: rsync" 2 + if [[ ${TRACE} == true ]]; then + rsync "${@}" ./ $REL_PATH_TO_DESTINATION/ -v + else + rsync "${@}" ./ $REL_PATH_TO_DESTINATION/ + fi + cd - > /dev/null; # go back to the previous folder without any output +}