From fd1cf1492b6da44a5d1347df70b4a51a45967381 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Mon, 2 Oct 2023 08:08:03 -0600 Subject: [PATCH 1/4] save point --- .../action/.github/workflows/main.yml | 82 +++++++++++ .../.github/workflows/scripts/run-push.sh | 105 ++++++++++++++ .../.github/workflows/scripts/workspace.sh | 132 ++++++++++++++++++ 3 files changed, 319 insertions(+) create mode 100644 tools/dotcms-cli/action/.github/workflows/main.yml create mode 100644 tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh create mode 100644 tools/dotcms-cli/action/.github/workflows/scripts/workspace.sh diff --git a/tools/dotcms-cli/action/.github/workflows/main.yml b/tools/dotcms-cli/action/.github/workflows/main.yml new file mode 100644 index 000000000000..e07bcc76248d --- /dev/null +++ b/tools/dotcms-cli/action/.github/workflows/main.yml @@ -0,0 +1,82 @@ +name: dotCMS sync + +on: [push] + +jobs: + sync-with-dotcms: + runs-on: ubuntu-latest + env: + # Global environment expected by dotCMS CLI + # This is how we instruct the cli the target server + DOT_API_URL: ${{ vars.DOT_API_URL }} + # This is how we instruct the cli the target folder in the repo + # By default it must be the root of the repo this allows setting up a different folder on top of the root + DOT_REPO_BASE_PATH: ${{ vars.DOT_REPO_BASE_PATH }} + # This is how we instruct the cli to create the workspace if it does not exist + DOT_CREATE_WORKSPACE: ${{ vars.DOT_CREATE_WORKSPACE || 'true' }} + steps: + - name: Checkout + uses: actions/checkout@v3 + id: checkout + with: + fetch-depth: 0 + + - name: Get changes + id: changed-files + run: | + echo "changed_files=$(git diff --name-only ${{ github.event.before }} ${{ github.event.after }} | xargs)" >> $GITHUB_OUTPUT + + - name: List changed files + run: | + for file in ${{ steps.changed-files.outputs.changed_files }}; do + echo "$file was changed" + done + + - name: Github Event Context properties + run: | + echo "Event: ${{ github.event }}" + echo "Event Name: ${{ github.event_name }}" + echo "Repository: ${{ github.repository }}" + echo "Commit SHA: ${{ github.sha }}" + echo "Commit Ref: ${{ github.ref }}" + echo "Head Ref: ${{ github.head_ref }}" + echo "Base Ref: ${{ github.base_ref }}" + echo "Triggered by: ${{ github.actor }}" + echo "Workflow: ${{ github.workflow }}" + echo "PR: ${{ github.pull_request }}" + echo "Workspace: ${{ github.workspace }}" + + - name: Create workspace if not exists + id: dot-workspace + run: | + if [ ${{ env.DOT_CREATE_WORKSPACE }} = true ]; then + echo "Creating workspace ::: " + chmod +x ./.github/workflows/scripts/workspace.sh + source ./.github/workflows/scripts/workspace.sh + workspace_updated=$(create_workspace "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" ) + echo "workspace-updated=$workspace_updated" >> "$GITHUB_OUTPUT" + fi + shell: bash + + # This step requires permission to push to the repo + # you need to grant read/write permission for workflows in the repo settings + - name: Persist updated workspace + run: | + saveChanges="${{ steps.dot-workspace.outputs.workspace-updated }}" + if [ -n "${saveChanges}" ]; then + git config user.name "GitHub Actions" + git config user.email "actions@github.com" + git add . + git commit -m "pushing workspace changes" + git push + echo "Workspace has been updated." + fi + + - name: Run dotCMS CLI + id: dot-push + run: | + chmod +x ./.github/workflows/scripts/run-push.sh + source ./.github/workflows/scripts/run-push.sh + run_cli_push "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" "${{env.DOT_API_URL}}" "${{ secrets.DOT_TOKEN }}" + print_log + shell: bash \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh new file mode 100644 index 000000000000..10112f966f9b --- /dev/null +++ b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh @@ -0,0 +1,105 @@ +#!/bin/sh + + ## https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/1.0.0-SNAPSHOT/dotcli-1.0.0-SNAPSHOT.jar + CLI_RELEASE_DOWNLOAD_BASE_URL="https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/" + RUN_JAVA_VERSION=1.3.8 + RUN_DOT_CLI_VERSION='1.0.0-SNAPSHOT' + CLI_RELEASE_DOWNLOAD_URL="${CLI_RELEASE_DOWNLOAD_BASE_URL}${RUN_DOT_CLI_VERSION}/dotcli-${RUN_DOT_CLI_VERSION}.jar" + DOT_CLI_JAR="dot-cli.jar" + DOT_CLI_HOME="/tmp/dot-cli/" + DOT_SERVICE_YML="dot-service.yml" + +SERVICES_FILE_CONTENT=' +- name: "default" + active: true +' + +_make_home(){ + + if [ ! -d "$DOT_CLI_HOME" ]; then + mkdir $DOT_CLI_HOME + fi + echo $DOT_CLI_HOME +} + +_get_CLI(){ + # now lets get curl so we can download the CLI and the run-java.sh script + + echo "downloading dot CLI from ${CLI_RELEASE_DOWNLOAD_URL}" + curl ${CLI_RELEASE_DOWNLOAD_URL} -L -o ${DOT_CLI_HOME}${DOT_CLI_JAR} + chmod 777 "${DOT_CLI_HOME}${DOT_CLI_JAR}" + + #Check the size of the file + file="${DOT_CLI_HOME}${DOT_CLI_JAR}" && \ + actual_size=$(wc -c <"$file"); + + if [ "$actual_size" -lt 1000000 ]; then + echo "The file is too small to be the CLI, please check the version and try again" + exit 1 + fi +} + +_get_run_java_script(){ + echo "downloading run-java.sh" + curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o "${DOT_CLI_HOME}"run-java.sh + chmod 777 ${DOT_CLI_HOME}run-java.sh +} + +_setup_CLI(){ + API_URL=$1 + #Lets create the services file dot-service.yml + #the services yml is used to store the server configurations or profiles if you Will + DOT_SERVICES_HOME=$HOME/.dotcms/ + SERVICE_FILE=$DOT_SERVICES_HOME$DOT_SERVICE_YML + # All we need is a file with an active profile that matches the server we want to connect to in this case we are using default + + if [ ! -d "$DOT_SERVICES_HOME" ]; then + mkdir "$DOT_SERVICES_HOME" + ## echo creating :: "$SERVICE_FILE"; + echo "$SERVICES_FILE_CONTENT" >> "$SERVICE_FILE"; + echo created file :: "$SERVICE_FILE" + cat "$SERVICE_FILE"; + fi + + #Tell the CLI to use the demo server through the profile "default" + #The suffix value used to create the environment value must match the name on dot-service.yml file in this case we are using default + #dotcms.client.servers.default=https://demo.dotcms.com/api + + export DOTCMS_CLIENT_SERVERS_DEFAULT=$API_URL + export QUARKUS_LOG_FILE_PATH=$DOT_CLI_HOME"dotcms-cli.log" + +} + +print_log(){ + echo "Quarkus log file contents:" + cat "$QUARKUS_LOG_FILE_PATH" +} + +_run_cli_push(){ + workspace_path=$1 + token=$2 + + #These environment vars are expected by the start-up script + export JAVA_OPTIONS="-Dquarkus.http.host=0.0.0.0 -Djava.util.logging.manager=org.jboss.logmanager.LogManager" + # This is a relative path to the run-java.sh file, both the jar and script are expected to live in the same folder + export JAVA_APP_JAR="$DOT_CLI_JAR" + # This is the name of the process that will be used to identify the process in the container + export JAVA_APP_NAME="dotcms-cli" + # Log file + export QUARKUS_LOG_FILE_PATH="$DOT_CLI_HOME"dotcms-cli.log + bash /tmp/dot-cli/run-java.sh "push" "$workspace_path" "--removeAssets" "--removeFolders" "--token" "$token" "--errors" + exit_code=$? + echo $exit_code +} + +run_cli_push(){ + workspace_path=$1 + dotApiURL=$2 + token=$3 + _make_home + _get_CLI + _get_run_java_script + _setup_CLI "$dotApiURL" + return_code=$(_run_cli_push "$workspace_path" "$token") + echo "$return_code" +} \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/workflows/scripts/workspace.sh b/tools/dotcms-cli/action/.github/workflows/scripts/workspace.sh new file mode 100644 index 000000000000..54d05f9218ec --- /dev/null +++ b/tools/dotcms-cli/action/.github/workflows/scripts/workspace.sh @@ -0,0 +1,132 @@ +#!/bin/sh + +DOT_WORKSPACE_YML=".dot-workspace.yml" +FILES_NAME_SPACE="/files/" +CONTENT_TYPES_NAME_SPACE="/content-types/" +LANGUAGES_NAME_SPACE="/languages/" +SITES_NAME_SPACE="/sites/" + +## This file forces git to keep empty folders +PLACEHOLDER_FILE=.dot-ignore +## We need an empty file to create the folders cause git does not track empty folders +PLACEHOLDER_FILE_CONTENT='#placeholder file +' +WORKSPACE_FILE_CONTENT='name: default +version: 1.0.0 +description: "DO NOT ERASE ME !!! I am a marker file required by dotCMS CLI."' + +## +## +_normalize() { + in=$1 + normalized=$(echo "$in" | sed -E 's#/+#/#g') + echo "$normalized" +} + +## Creates the .dot_workspace yml file expected by the CLI to be able to work +## expects a base path to work with +_workspace_file(){ + BASE_PATH=$1 + #echo "$BASE_PATH" + WORKSPACE_FILE=$BASE_PATH/$DOT_WORKSPACE_YML + #echo Workspace-file :: "$WORKSPACE_FILE" + WORKSPACE_FILE=$(_normalize "$WORKSPACE_FILE") + #echo normalized :: "$WORKSPACE_FILE" + if [ ! -f "$WORKSPACE_FILE" ]; then + #echo "writing to file ::" + echo "$WORKSPACE_FILE_CONTENT" >> "$WORKSPACE_FILE"; + #echo "writing to file done!" + echo "$WORKSPACE_FILE"; + fi +} + +## Creates the files workspace path including live, working and language directories +## expects a base path to work with +_files_path(){ + BASE_PATH=$1 + FILES_PATH=$BASE_PATH/$FILES_NAME_SPACE + FILES_PATH=$(_normalize "$FILES_PATH") + + #echo "Files path: $FILES_PATH" + if [ ! -d "$FILES_PATH" ]; then + #echo "Creating files path: $FILES_PATH"; + mkdir -p "$FILES_PATH"; + + WORKING_EN=$(_normalize "$FILES_PATH"/working/en-us/ ) + #echo "Working en-us path: $WORKING_EN"; + mkdir -p "$WORKING_EN"; + echo "$PLACEHOLDER_FILE_CONTENT" >> "$WORKING_EN""$PLACEHOLDER_FILE" + + LIVE_EN=$(_normalize "$FILES_PATH"/live/en-us/ ) + #echo "Live en-us path: $LIVE_EN"; + mkdir -p "$LIVE_EN"; + echo "$PLACEHOLDER_FILE_CONTENT" >> "$LIVE_EN""$PLACEHOLDER_FILE" + + echo "$FILES_PATH" + fi +} + +## Creates the content_types workspace path +## expects a base path to work with +_content_types_path(){ + BASE_PATH=$1 + CONTENT_TYPES_PATH=$BASE_PATH/$CONTENT_TYPES_NAME_SPACE + CONTENT_TYPES_PATH=$(_normalize "$CONTENT_TYPES_PATH") + #echo "Content types path: $CONTENT_TYPES_PATH" + if [ ! -d "$CONTENT_TYPES_PATH" ]; then + #echo "Creating content types path: $CONTENT_TYPES_PATH"; + mkdir -p "$CONTENT_TYPES_PATH"; + echo "$PLACEHOLDER_FILE_CONTENT" >> "$CONTENT_TYPES_PATH""$PLACEHOLDER_FILE" + echo "$CONTENT_TYPES_PATH" + fi +} + +## Creates the languages workspace path +## expects a base path to work with +_languages_path(){ + BASE_PATH=$1 + LANGUAGE_PATH=$BASE_PATH/$LANGUAGES_NAME_SPACE + LANGUAGE_PATH=$(_normalize "$LANGUAGE_PATH") + #echo "Languages path: $LANGUAGE_PATH" + if [ ! -d "$LANGUAGE_PATH" ]; then + mkdir -p "$LANGUAGE_PATH"; + echo "$PLACEHOLDER_FILE_CONTENT" >> "$LANGUAGE_PATH""$PLACEHOLDER_FILE" + echo "$LANGUAGE_PATH" + fi +} + +## Creates the sites workspace path +## expects a base path to work with +_sites_path(){ + BASE_PATH=$1 + SITES_PATH=$BASE_PATH/$SITES_NAME_SPACE + SITES_PATH=$(_normalize "$SITES_PATH") + #echo "Sites path: $SITES_PATH" + if [ ! -d "$SITES_PATH" ]; then + #echo "Creating sites path: $SITES_PATH"; + mkdir -p "$SITES_PATH"; + echo "$PLACEHOLDER_FILE_CONTENT" >> "$SITES_PATH""$PLACEHOLDER_FILE" + echo "$SITES_PATH" + fi +} + +## This function serves as the entry point the script +## it expects a base path to work with +create_workspace(){ + basePath="$1" + basePath=$(_normalize "$basePath") + workspace_file=$(_workspace_file "$basePath") + files=$(_files_path "$basePath") + contentTypes=$(_content_types_path "$basePath") + languages=$(_languages_path "$basePath") + sites=$(_sites_path "$basePath") + + if [ -n "$workspace_file" ] || [ -n "$files" ] || [ -n "$contentTypes" ] || [ -n "$languages" ] || [ -n "$sites" ]; then + echo "Workspace updated" + fi + +} + + + + From 6b7bf19315c9907659f6b145db5c0765dc0acf86 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Mon, 2 Oct 2023 22:46:21 -0600 Subject: [PATCH 2/4] save point --- .../action/.github/workflows/main.yml | 3 ++- .../.github/workflows/scripts/run-push.sh | 20 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tools/dotcms-cli/action/.github/workflows/main.yml b/tools/dotcms-cli/action/.github/workflows/main.yml index e07bcc76248d..21e2ce519ae4 100644 --- a/tools/dotcms-cli/action/.github/workflows/main.yml +++ b/tools/dotcms-cli/action/.github/workflows/main.yml @@ -77,6 +77,7 @@ jobs: run: | chmod +x ./.github/workflows/scripts/run-push.sh source ./.github/workflows/scripts/run-push.sh - run_cli_push "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" "${{env.DOT_API_URL}}" "${{ secrets.DOT_TOKEN }}" + run_cli_push "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" "${{env.DOT_API_URL}}" "${{ secrets.DOT_TOKEN }}" + echo "exit-code=$exit_code" >> "$GITHUB_OUTPUT" print_log shell: bash \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh index 10112f966f9b..f855dd61a742 100644 --- a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh +++ b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh @@ -19,13 +19,13 @@ _make_home(){ if [ ! -d "$DOT_CLI_HOME" ]; then mkdir $DOT_CLI_HOME fi - echo $DOT_CLI_HOME + #echo $DOT_CLI_HOME } _get_CLI(){ # now lets get curl so we can download the CLI and the run-java.sh script - echo "downloading dot CLI from ${CLI_RELEASE_DOWNLOAD_URL}" + #echo "downloading dot CLI from ${CLI_RELEASE_DOWNLOAD_URL}" curl ${CLI_RELEASE_DOWNLOAD_URL} -L -o ${DOT_CLI_HOME}${DOT_CLI_JAR} chmod 777 "${DOT_CLI_HOME}${DOT_CLI_JAR}" @@ -39,8 +39,13 @@ _get_CLI(){ fi } +_install_CLI(){ + workspace_path=$1 + cp "$workspace_path"/dotcms-cli-1.0.0-SNAPSHOT-runner.jar ${DOT_CLI_HOME}${DOT_CLI_JAR} +} + _get_run_java_script(){ - echo "downloading run-java.sh" + #echo "downloading run-java.sh" curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o "${DOT_CLI_HOME}"run-java.sh chmod 777 ${DOT_CLI_HOME}run-java.sh } @@ -57,8 +62,8 @@ _setup_CLI(){ mkdir "$DOT_SERVICES_HOME" ## echo creating :: "$SERVICE_FILE"; echo "$SERVICES_FILE_CONTENT" >> "$SERVICE_FILE"; - echo created file :: "$SERVICE_FILE" - cat "$SERVICE_FILE"; + #echo created file :: "$SERVICE_FILE" + #cat "$SERVICE_FILE"; fi #Tell the CLI to use the demo server through the profile "default" @@ -88,7 +93,7 @@ _run_cli_push(){ # Log file export QUARKUS_LOG_FILE_PATH="$DOT_CLI_HOME"dotcms-cli.log bash /tmp/dot-cli/run-java.sh "push" "$workspace_path" "--removeAssets" "--removeFolders" "--token" "$token" "--errors" - exit_code=$? + export exit_code=$? echo $exit_code } @@ -97,7 +102,8 @@ run_cli_push(){ dotApiURL=$2 token=$3 _make_home - _get_CLI + #_get_CLI + _install_CLI "$workspace_path" _get_run_java_script _setup_CLI "$dotApiURL" return_code=$(_run_cli_push "$workspace_path" "$token") From 40a325ede1b022f11bb9844dadb5e2d03aa4c94c Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Tue, 3 Oct 2023 14:40:39 -0600 Subject: [PATCH 3/4] #26300 script improvements --- .../action/.github/workflows/main.yml | 13 +++- .../.github/workflows/scripts/run-push.sh | 65 ++++++++++--------- 2 files changed, 47 insertions(+), 31 deletions(-) diff --git a/tools/dotcms-cli/action/.github/workflows/main.yml b/tools/dotcms-cli/action/.github/workflows/main.yml index 21e2ce519ae4..52be89269ba4 100644 --- a/tools/dotcms-cli/action/.github/workflows/main.yml +++ b/tools/dotcms-cli/action/.github/workflows/main.yml @@ -14,6 +14,10 @@ jobs: DOT_REPO_BASE_PATH: ${{ vars.DOT_REPO_BASE_PATH }} # This is how we instruct the cli to create the workspace if it does not exist DOT_CREATE_WORKSPACE: ${{ vars.DOT_CREATE_WORKSPACE || 'true' }} + # This is the CLI version to use, but we can always override this value + DOT_CLI_JAR_DOWNLOAD_URL: ${{ vars.DOT_CLI_JAR_DOWNLOAD_URL || 'https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/1.0.0-SNAPSHOT/dotcms-cli-1.0.0-20231002.205953-1.jar' }} + # In case we want to force the download of the CLI jar + DOT_FORCE_DOWNLOAD: ${{ vars.DOT_FORCE_DOWNLOAD || 'false' }} steps: - name: Checkout uses: actions/checkout@v3 @@ -76,8 +80,13 @@ jobs: id: dot-push run: | chmod +x ./.github/workflows/scripts/run-push.sh - source ./.github/workflows/scripts/run-push.sh - run_cli_push "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" "${{env.DOT_API_URL}}" "${{ secrets.DOT_TOKEN }}" + source ./.github/workflows/scripts/run-push.sh + install_cli "${{env.DOT_CLI_JAR_DOWNLOAD_URL}}" "${{env.DOT_FORCE_DOWNLOAD}}" "${{env.DOT_API_URL}}" + run_cli_push "${{github.workspace}}${{env.DOT_REPO_BASE_PATH}}" "${{ secrets.DOT_TOKEN }}" echo "exit-code=$exit_code" >> "$GITHUB_OUTPUT" print_log + if [ $exit_code -ne 0 ]; then + echo "Error running dotCMS CLI" + exit 1 + fi shell: bash \ No newline at end of file diff --git a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh index f855dd61a742..5c308a8f371b 100644 --- a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh +++ b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh @@ -1,10 +1,5 @@ #!/bin/sh - ## https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/1.0.0-SNAPSHOT/dotcli-1.0.0-SNAPSHOT.jar - CLI_RELEASE_DOWNLOAD_BASE_URL="https://repo.dotcms.com/artifactory/libs-snapshot-local/com/dotcms/dotcms-cli/" - RUN_JAVA_VERSION=1.3.8 - RUN_DOT_CLI_VERSION='1.0.0-SNAPSHOT' - CLI_RELEASE_DOWNLOAD_URL="${CLI_RELEASE_DOWNLOAD_BASE_URL}${RUN_DOT_CLI_VERSION}/dotcli-${RUN_DOT_CLI_VERSION}.jar" DOT_CLI_JAR="dot-cli.jar" DOT_CLI_HOME="/tmp/dot-cli/" DOT_SERVICE_YML="dot-service.yml" @@ -15,18 +10,23 @@ SERVICES_FILE_CONTENT=' ' _make_home(){ - if [ ! -d "$DOT_CLI_HOME" ]; then mkdir $DOT_CLI_HOME fi - #echo $DOT_CLI_HOME } _get_CLI(){ - # now lets get curl so we can download the CLI and the run-java.sh script - #echo "downloading dot CLI from ${CLI_RELEASE_DOWNLOAD_URL}" - curl ${CLI_RELEASE_DOWNLOAD_URL} -L -o ${DOT_CLI_HOME}${DOT_CLI_JAR} + cli_release_download_url=$1 + force_download=$2 + + cliJar=${DOT_CLI_HOME}${DOT_CLI_JAR} + if [ -f $cliJar ] && ! [ "$force_download" = true ] ; then + echo "dot-CLI already exists, skipping download" + return + fi + + curl "$cli_release_download_url" -L -o ${DOT_CLI_HOME}${DOT_CLI_JAR} chmod 777 "${DOT_CLI_HOME}${DOT_CLI_JAR}" #Check the size of the file @@ -39,14 +39,14 @@ _get_CLI(){ fi } -_install_CLI(){ - workspace_path=$1 - cp "$workspace_path"/dotcms-cli-1.0.0-SNAPSHOT-runner.jar ${DOT_CLI_HOME}${DOT_CLI_JAR} -} - _get_run_java_script(){ - #echo "downloading run-java.sh" - curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o "${DOT_CLI_HOME}"run-java.sh + force_download=$1 + runJava=${DOT_CLI_HOME}run-java.sh + if [ -f "$runJava" ] && ! [ "$force_download" = true ] ; then + echo "run-java.sh already exists, skipping download" + return + fi + curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/"${RUN_JAVA_VERSION}"/run-java-sh-"${RUN_JAVA_VERSION}"-sh.sh -o "${DOT_CLI_HOME}"run-java.sh chmod 777 ${DOT_CLI_HOME}run-java.sh } @@ -57,14 +57,16 @@ _setup_CLI(){ DOT_SERVICES_HOME=$HOME/.dotcms/ SERVICE_FILE=$DOT_SERVICES_HOME$DOT_SERVICE_YML # All we need is a file with an active profile that matches the server we want to connect to in this case we are using default - + # If the directory does not exist we create it if [ ! -d "$DOT_SERVICES_HOME" ]; then mkdir "$DOT_SERVICES_HOME" - ## echo creating :: "$SERVICE_FILE"; - echo "$SERVICES_FILE_CONTENT" >> "$SERVICE_FILE"; - #echo created file :: "$SERVICE_FILE" - #cat "$SERVICE_FILE"; + else + # If the directory exists we remove it as we could be updating the server url + rm -rf "$DOT_SERVICES_HOME" + mkdir "$DOT_SERVICES_HOME" fi + # Now generate the file + echo "$SERVICES_FILE_CONTENT" >> "$SERVICE_FILE"; #Tell the CLI to use the demo server through the profile "default" #The suffix value used to create the environment value must match the name on dot-service.yml file in this case we are using default @@ -97,15 +99,20 @@ _run_cli_push(){ echo $exit_code } -run_cli_push(){ - workspace_path=$1 - dotApiURL=$2 - token=$3 +install_dot_cli(){ + cli_release_download_url=$1 + force_download=$2 + dotApiURL=$3 + _make_home - #_get_CLI - _install_CLI "$workspace_path" - _get_run_java_script + _get_CLI "$cli_release_download_url" "$force_download" + _get_run_java_script "$force_download" _setup_CLI "$dotApiURL" +} + +run_cli_push(){ + workspace_path=$1 + token=$2 return_code=$(_run_cli_push "$workspace_path" "$token") echo "$return_code" } \ No newline at end of file From 9471a39e715934c4ee1814afe866458272e8f852 Mon Sep 17 00:00:00 2001 From: fabrizzio-dotCMS Date: Wed, 4 Oct 2023 10:30:30 -0600 Subject: [PATCH 4/4] #26300 fixes to the script that runs the cli --- tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh index 5c308a8f371b..5129f772110a 100644 --- a/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh +++ b/tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh @@ -3,6 +3,7 @@ DOT_CLI_JAR="dot-cli.jar" DOT_CLI_HOME="/tmp/dot-cli/" DOT_SERVICE_YML="dot-service.yml" + RUN_JAVA_VERSION=1.3.8 SERVICES_FILE_CONTENT=' - name: "default" @@ -99,7 +100,7 @@ _run_cli_push(){ echo $exit_code } -install_dot_cli(){ +install_cli(){ cli_release_download_url=$1 force_download=$2 dotApiURL=$3