|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Script Name: validateRepoCurrent.sh |
| 4 | +# Purpose: |
| 5 | +# This script ensures the local repository's NetSuite object files are synchronized with the server state. |
| 6 | +# It's designed to prevent conflicts that may arise when changes made directly in the NetSuite server UI |
| 7 | +# have not been incorporated into the repository's main branch. By checking against the server, |
| 8 | +# the script helps avoid overwriting server-side changes that haven't been merged into the repository. |
| 9 | + |
| 10 | +# Usage: ./validateRepoCurrent.sh |
| 11 | + |
| 12 | +# Functionality: |
| 13 | +# - The script reads a list of object files (objectFileList.pipeline-test.txt). |
| 14 | +# - For each object, it checks for a "scriptid" attribute and runs the "update-suitecloud-object" script. |
| 15 | +# This fetches the latest version of each object from the NetSuite server, ensuring synchronization. |
| 16 | +# - The script also checks the Git repository's status for pending changes. |
| 17 | +# - If there are uncommitted changes, the deployment process is halted to prevent overwriting. |
| 18 | +# - If no changes are pending, it confirms the repository is ready for deployment. |
| 19 | + |
| 20 | +# Example usage in package.json: |
| 21 | +# "validate-repo-current": "bash .ci/scripts/validateRepoCurrent.sh" |
| 22 | + |
| 23 | +SCRIPTIDREGEX="scriptid=\"(.*)\"" |
| 24 | +SCRIPTIDSEDREGEX="\(.*\)scriptid=\"\(.*\)\"\(.*\)" |
| 25 | +OBJFILE="./objectFileList.pipeline-test.txt" |
| 26 | +cat "$OBJFILE" |
| 27 | +while read OBJLINE; do |
| 28 | + while read line; do |
| 29 | + SCRIPTID= |
| 30 | + if [[ "$line" =~ $SCRIPTIDREGEX ]]; then |
| 31 | + # ScriptID found on the first line |
| 32 | + SCRIPTID=$(echo "$line" | sed "s:$SCRIPTIDSEDREGEX:\2:g") |
| 33 | + echo "Checking: $SCRIPTID" |
| 34 | + npm run update-suitecloud-object --scriptid=$SCRIPTID |
| 35 | + break |
| 36 | + fi |
| 37 | + |
| 38 | + done < <(cat "$OBJLINE") |
| 39 | + |
| 40 | +done < <(cat "$OBJFILE") |
| 41 | + |
| 42 | +# Checking for uncommitted changes in the Git repository |
| 43 | +git status --porcelain |
| 44 | +if [[ $(git status --porcelain) ]]; then |
| 45 | + # Changes detected |
| 46 | + echo "Repository Changes Pending: ABORT!" |
| 47 | + # Flag to stop the deployment process in case of pending changes |
| 48 | + echo "##vso[task.setvariable variable=sfdxExitCode;]1" # Stops the build event for error checking |
| 49 | +else |
| 50 | + # No changes detected |
| 51 | + echo "Repository Current: Ready for Deployment!" |
| 52 | +fi |
0 commit comments