Skip to content

Commit

Permalink
#26386 Loading push command options from .env file.
Browse files Browse the repository at this point in the history
  • Loading branch information
dcolina committed Oct 26, 2023
1 parent 4ced329 commit e63ebd4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 6 deletions.
46 changes: 44 additions & 2 deletions tools/dotcms-cli/action/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ jobs:
with:
fetch-depth: 0

- name: Load .env file
uses: aarcangeli/[email protected]
with:
if-file-not-found: 'warn'

- name: Print env vars
run: |
echo "$GITHUB_ENV"
- name: Get changes
id: changed-files
run: |
Expand Down Expand Up @@ -76,13 +85,46 @@ jobs:
echo "Workspace has been updated."
fi
- name: Options command
id: options
run: |
import os
# Access environment variables
PUSH_OPTIONS = {}
PUSH_OPTIONS["dry-run"] = os.getenv("DOT_CLI_DRY_RUN")
PUSH_OPTIONS["fail-fast"] = os.getenv("DOT_CLI_FAIL_FAST")
PUSH_OPTIONS["forceSiteExecution"] = os.getenv("DOT_CLI_FORCE_SITE_EXECUTION")
PUSH_OPTIONS["removeAssets"] = os.getenv("DOT_CLI_REMOVE_ASSETS")
PUSH_OPTIONS["removeContentTypes"] = os.getenv("DOT_CLI_REMOVE_CONTENT_TYPES")
PUSH_OPTIONS["retry-attempts"] = os.getenv("DOT_CLI_RETRY_ATTEMPS")
PUSH_OPTIONS["removeFolders"] = os.getenv("DOT_CLI_REMOVE_FOLDERS")
PUSH_OPTIONS["removeLanguages"] = os.getenv("DOT_CLI_REMOVE_LANGUAGES")
PUSH_OPTIONS["removeSites"] = os.getenv("DOT_CLI_REMOVE_SITES")
COMMAND_PUSH_OPTS = "";
for key, value in PUSH_OPTIONS.items():
if value != None:
if value.lower() == "true":
COMMAND_PUSH_OPTS=f"{COMMAND_PUSH_OPTS} --{key}"
elif value.lower() != "false":
COMMAND_PUSH_OPTS=f"{COMMAND_PUSH_OPTS} --{key}={value}"
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
print(f 'COMMAND_PUSH_OPTS={COMMAND_PUSH_OPTS}', file=f)
print(COMMAND_PUSH_OPTS)
shell: python

- name: Run dotCMS CLI
id: dot-push
run: |
chmod +x ./.github/workflows/scripts/run-push.sh
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 }}"
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}}" "${{ steps.options.outputs.COMMAND_PUSH_OPTS }}" "${{ secrets.DOT_TOKEN }}"
echo "exit-code=$exit_code" >> "$GITHUB_OUTPUT"
print_log
if [ $exit_code -ne 0 ]; then
Expand Down
10 changes: 6 additions & 4 deletions tools/dotcms-cli/action/.github/workflows/scripts/run-push.sh
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ print_log(){

_run_cli_push(){
workspace_path=$1
token=$2
push_opts=$2
token=$3

#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"
Expand All @@ -95,7 +96,7 @@ _run_cli_push(){
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"
bash /tmp/dot-cli/run-java.sh "push" "$workspace_path" "$push_opts" "--token" "$token" "--errors"
export exit_code=$?
echo $exit_code
}
Expand All @@ -113,7 +114,8 @@ install_cli(){

run_cli_push(){
workspace_path=$1
token=$2
return_code=$(_run_cli_push "$workspace_path" "$token")
opts=$2
token=$3
return_code=$(_run_cli_push "$workspace_path" "$opts" "$token")
echo "$return_code"
}

0 comments on commit e63ebd4

Please sign in to comment.