Skip to content

Commit e9bb75e

Browse files
committed
update script
1 parent c253ca5 commit e9bb75e

File tree

1 file changed

+61
-44
lines changed

1 file changed

+61
-44
lines changed

update-repositories.sh

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
PROJECTS_DIR="$HOME/projects/liberu"
44
BOILERPLATE_DIR="$PROJECTS_DIR/boilerplate-laravel"
5-
LOG_FILE="$HOME/update-projects.log"
5+
LOG_FILE="$PROJECTS_DIR/update-projects.log"
66
TIMESTAMP=$(date "+%Y-%m-%d %H:%M:%S")
77

88
echo "===== Starting update: $TIMESTAMP =====" | tee -a "$LOG_FILE"
99

10-
# List of repos to update
10+
# List of repositories to update
1111
REPOS=(
1212
"ecommerce-laravel"
1313
"browser-game-laravel"
@@ -29,55 +29,72 @@ REPOS=(
2929
for repo in "${REPOS[@]}"; do
3030
TARGET_DIR="$PROJECTS_DIR/$repo"
3131

32-
if [ -d "$TARGET_DIR/.git" ]; then
33-
echo "----- Processing $repo -----" | tee -a "$LOG_FILE"
34-
cd "$TARGET_DIR" || { echo "Failed to enter $TARGET_DIR" | tee -a "$LOG_FILE"; continue; }
35-
36-
{
37-
echo "Pulling latest changes from origin..."
38-
git pull || { echo "git pull failed in $repo"; continue; }
39-
40-
# --- Composer updates ---
41-
if [ -f composer.json ]; then
42-
echo "Running composer update..."
43-
composer update || { echo "composer update failed in $repo"; continue; }
44-
fi
45-
46-
# --- NPM updates ---
47-
if [ -f package.json ]; then
48-
echo "Running npm install..."
49-
npm install || { echo "npm install failed in $repo"; continue; }
50-
51-
echo "Running npm upgrade..."
52-
npm upgrade || { echo "npm upgrade failed in $repo"; continue; }
53-
54-
echo "Running npm audit fix..."
55-
npm audit fix --force || { echo "npm audit fix failed in $repo"; continue; }
32+
if [ ! -d "$TARGET_DIR/.git" ]; then
33+
echo "Skipping $repo - not a git repo" | tee -a "$LOG_FILE"
34+
continue
35+
fi
5636

57-
echo "Running npm run build..."
58-
npm run build || { echo "npm run build failed in $repo"; continue; }
59-
fi
37+
echo "----- Processing $repo -----" | tee -a "$LOG_FILE"
38+
cd "$TARGET_DIR" || { echo "Failed to enter $TARGET_DIR" | tee -a "$LOG_FILE"; continue; }
6039

61-
# --- Placeholder for custom updates ---
62-
# Example: Copy boilerplate files
63-
# cp -r "$PROJECTS_DIR/boilerplate-laravel/app/." "$TARGET_DIR/app/"
64-
# cp -r "$PROJECTS_DIR/boilerplate-laravel/config/." "$TARGET_DIR/config/"
40+
# Pull latest changes
41+
echo "Pulling latest changes from origin..."
42+
if ! git pull; then
43+
echo "git pull failed in $repo" | tee -a "$LOG_FILE"
44+
continue
45+
fi
6546

66-
# --- Commit any automatic changes ---
67-
if ! git diff --quiet || ! git diff --cached --quiet; then
68-
echo "Committing and pushing changes..."
69-
git add -A
70-
git commit -m "Update dependencies and boilerplate changes" || true
71-
git push || { echo "git push failed in $repo"; continue; }
72-
else
73-
echo "No changes to commit"
74-
fi
47+
# --- Composer updates ---
48+
if [ -f composer.json ]; then
49+
echo "Running composer update..."
50+
if ! composer update; then
51+
echo "composer update failed in $repo" | tee -a "$LOG_FILE"
52+
continue
53+
fi
54+
fi
7555

76-
} 2>&1 | tee -a "$LOG_FILE"
56+
# --- NPM updates ---
57+
if [ -f package.json ]; then
58+
echo "Running npm install..."
59+
if ! npm install; then
60+
echo "npm install failed in $repo" | tee -a "$LOG_FILE"
61+
continue
62+
fi
63+
64+
echo "Running npm upgrade..."
65+
if ! npm upgrade; then
66+
echo "npm upgrade failed in $repo" | tee -a "$LOG_FILE"
67+
continue
68+
fi
69+
70+
echo "Running npm audit fix..."
71+
if ! npm audit fix --force; then
72+
echo "npm audit fix failed in $repo" | tee -a "$LOG_FILE"
73+
continue
74+
fi
75+
76+
echo "Running npm run build..."
77+
if ! npm run build; then
78+
echo "npm run build failed in $repo" | tee -a "$LOG_FILE"
79+
continue
80+
fi
81+
fi
7782

83+
# --- Placeholder for custom updates ---
84+
# Example: Copy selective boilerplate files
85+
# cp -r "$PROJECTS_DIR/boilerplate-laravel/app/." "$TARGET_DIR/app/"
86+
# cp -r "$PROJECTS_DIR/boilerplate-laravel/config/." "$TARGET_DIR/config/"
87+
88+
# Commit & push any changes
89+
if ! git diff --quiet || ! git diff --cached --quiet; then
90+
echo "Committing and pushing changes..."
91+
git add -A
92+
git commit -m "Update dependencies and boilerplate changes" || true
93+
git push || { echo "git push failed in $repo"; continue; }
7894
else
79-
echo "Skipping $repo - not a git repo" | tee -a "$LOG_FILE"
95+
echo "No changes to commit"
8096
fi
97+
8198
done
8299

83100
echo "===== Update completed: $(date "+%Y-%m-%d %H:%M:%S") =====" | tee -a "$LOG_FILE"

0 commit comments

Comments
 (0)