Last active 1735980077

anduin's Avatar anduin revised this gist 1735980077. Go to revision

1 file changed, 3 insertions, 2 deletions

build.sh

@@ -1,3 +1,4 @@
1 + anduin@builder:~$ cat ./daily_build_v2.sh
1 2 #!/bin/bash
2 3
3 4 # daily_build_v2.sh (refactored without tmux)
@@ -22,7 +23,7 @@ BUILD_SCRIPT="$SRC_DIR/build_all_langs.sh"
22 23 BASE_BUILT_DIR="$HOME/built"
23 24
24 25 # Branch list (example: 1.1 & 1.2)
25 - BRANCHES=("1.1" "1.2")
26 + BRANCHES=("1.0" "1.1" "1.2")
26 27
27 28 # Print an error message and exit
28 29 error_exit() {
@@ -86,7 +87,7 @@ check_and_build_branch() {
86 87 # If build is required, proceed
87 88 if [ "$BUILD_REQUIRED" = true ]; then
88 89 echo "[$(date)] INFO: Build is required for branch $branch_name"
89 - (cd "$SRC_DIR" && bash "$BUILD_SCRIPT")
90 + (cd "$SRC_DIR" && bash "$BUILD_SCRIPT" --langs fast)
90 91 if [ $? -eq 0 ]; then
91 92 echo "[$(date)] INFO: Build script completed successfully"
92 93

anduin's Avatar anduin revised this gist 1735899359. Go to revision

1 file changed, 1 insertion, 1 deletion

build.sh

@@ -96,7 +96,7 @@ check_and_build_branch() {
96 96
97 97 # Copy artifacts
98 98 echo "[$(date)] INFO: Moving build artifacts from $SRC_DIR/dists to $BASE_BUILT_DIR/$branch_name"
99 - mv "$SRC_DIR/dists/"* "$BASE_BUILT_DIR/$branch_name"/
99 + mv "$SRC_DIR/dist/"* "$BASE_BUILT_DIR/$branch_name"/
100 100
101 101 # Update last build date
102 102 date +"%Y-%m-%d" > "$last_build_file"

anduin's Avatar anduin revised this gist 1735882853. Go to revision

1 file changed, 2 insertions, 2 deletions

build.sh

@@ -95,8 +95,8 @@ check_and_build_branch() {
95 95 mkdir -p "$BASE_BUILT_DIR/$branch_name"
96 96
97 97 # Copy artifacts
98 - echo "[$(date)] INFO: Copying build artifacts from $SRC_DIR/dists to $BASE_BUILT_DIR/$branch_name"
99 - cp -rf "$SRC_DIR/dists/"* "$BASE_BUILT_DIR/$branch_name"/
98 + echo "[$(date)] INFO: Moving build artifacts from $SRC_DIR/dists to $BASE_BUILT_DIR/$branch_name"
99 + mv "$SRC_DIR/dists/"* "$BASE_BUILT_DIR/$branch_name"/
100 100
101 101 # Update last build date
102 102 date +"%Y-%m-%d" > "$last_build_file"

anduin's Avatar anduin revised this gist 1735842145. Go to revision

1 file changed, 7 insertions, 8 deletions

build.sh

@@ -27,7 +27,9 @@ BRANCHES=("1.1" "1.2")
27 27 # Print an error message and exit
28 28 error_exit() {
29 29 echo "[$(date)] ERROR: $1" >&2
30 - exit 1
30 +
31 + # Infinite sleep to keep the container running for debugging
32 + sleep 99999999
31 33 }
32 34
33 35 # Function to check and build a specific branch
@@ -84,17 +86,14 @@ check_and_build_branch() {
84 86 # If build is required, proceed
85 87 if [ "$BUILD_REQUIRED" = true ]; then
86 88 echo "[$(date)] INFO: Build is required for branch $branch_name"
87 -
88 - # Optional: Clean up the old artifacts only when we are about to build
89 - echo "[$(date)] INFO: Removing old artifacts under $BASE_BUILT_DIR/$branch_name"
90 - rm -rf "$BASE_BUILT_DIR/$branch_name"
91 - mkdir -p "$BASE_BUILT_DIR/$branch_name"
92 -
93 - echo "[$(date)] INFO: Running build script for branch $branch_name"
94 89 (cd "$SRC_DIR" && bash "$BUILD_SCRIPT")
95 90 if [ $? -eq 0 ]; then
96 91 echo "[$(date)] INFO: Build script completed successfully"
97 92
93 + echo "[$(date)] INFO: Removing old artifacts under $BASE_BUILT_DIR/$branch_name"
94 + rm -rf "$BASE_BUILT_DIR/$branch_name"
95 + mkdir -p "$BASE_BUILT_DIR/$branch_name"
96 +
98 97 # Copy artifacts
99 98 echo "[$(date)] INFO: Copying build artifacts from $SRC_DIR/dists to $BASE_BUILT_DIR/$branch_name"
100 99 cp -rf "$SRC_DIR/dists/"* "$BASE_BUILT_DIR/$branch_name"/

anduin's Avatar anduin revised this gist 1735826581. Go to revision

1 file changed, 13 insertions, 40 deletions

build.sh

@@ -1,26 +1,24 @@
1 1 #!/bin/bash
2 2
3 - # daily_build_v2.sh
3 + # daily_build_v2.sh (refactored without tmux)
4 4 # Script Purpose:
5 - # This script is scheduled to run daily at 21:00 UTC to:
6 - # 1) For each branch (e.g. 1.1, 1.2):
5 + # 1) For each branch in the list:
7 6 # a) Switch to the branch, ensure local code is up-to-date (clean -fdx, reset --hard, pull)
8 7 # b) Check if there are new commits in the past 24 hours
9 8 # - If yes, a build is required
10 9 # - If no but the last build was more than a week ago, a forced build is required
11 10 # - Otherwise, skip
12 - # c) If a build is required, run build_all_langs.sh in a specific tmux session,
11 + # c) If a build is required, run build_all_langs.sh in the current session,
13 12 # then copy build artifacts from ./src/dists/* to ~/built/<branch>/
14 13 #
15 - # Additional requirements for this version:
16 - # - Do NOT build 1.1 and 1.2 at the same time. Must wait for 1.1 to finish before building 1.2.
14 + # Additional requirements:
15 + # - Do NOT build branches in parallel. Must finish one before moving to the next.
17 16 # - If no build is needed, do NOT remove any existing build artifacts.
18 17 # - Provide more logs rather than comments.
19 18
20 19 REPO_DIR="$HOME/anduinos"
21 20 SRC_DIR="$REPO_DIR/src"
22 21 BUILD_SCRIPT="$SRC_DIR/build_all_langs.sh"
23 - SESSION_NAME_PREFIX="build_session"
24 22 BASE_BUILT_DIR="$HOME/built"
25 23
26 24 # Branch list (example: 1.1 & 1.2)
@@ -35,12 +33,8 @@ error_exit() {
35 33 # Function to check and build a specific branch
36 34 check_and_build_branch() {
37 35 local branch_name=$1
38 -
39 - local sanitized_branch_name="${branch_name//./_}"
40 - local session_name="${SESSION_NAME_PREFIX}_${sanitized_branch_name}"
41 -
36 +
42 37 echo "[$(date)] INFO: Start checking branch: $branch_name"
43 - echo "[$(date)] INFO: The tmux session name will be: $session_name"
44 38
45 39 local last_build_file="$HOME/.last_build_date_${branch_name}"
46 40
@@ -68,6 +62,7 @@ check_and_build_branch() {
68 62 if [ -f "$last_build_file" ]; then
69 63 local last_build_date
70 64 last_build_date=$(cat "$last_build_file")
65 +
71 66 local last_build_epoch
72 67 last_build_epoch=$(date -d "$last_build_date" +%s)
73 68 local current_epoch
@@ -81,7 +76,6 @@ check_and_build_branch() {
81 76 echo "[$(date)] INFO: No new commits for branch $branch_name, and last build is within a week. Skipping build."
82 77 fi
83 78 else
84 - # If there's no record file, we consider it as needing a build
85 79 BUILD_REQUIRED=true
86 80 echo "[$(date)] INFO: No last_build_date record found. Forcing a build."
87 81 fi
@@ -94,35 +88,14 @@ check_and_build_branch() {
94 88 # Optional: Clean up the old artifacts only when we are about to build
95 89 echo "[$(date)] INFO: Removing old artifacts under $BASE_BUILT_DIR/$branch_name"
96 90 rm -rf "$BASE_BUILT_DIR/$branch_name"
97 -
98 - # Ensure the build output directory exists
99 91 mkdir -p "$BASE_BUILT_DIR/$branch_name"
100 92
101 - # Kill any old tmux session for this branch
102 - local session_name="${SESSION_NAME_PREFIX}_${branch_name}"
103 - echo "[$(date)] INFO: Checking and killing any existing tmux session named $session_name"
104 - if tmux has-session -t "$session_name" 2>/dev/null; then
105 - tmux kill-session -t "$session_name"
106 - echo "[$(date)] INFO: Killed existing tmux session: $session_name"
107 - fi
108 -
109 - # Start a new tmux session for build
110 - echo "[$(date)] INFO: Creating a new tmux session for building branch $branch_name"
111 - tmux new-session -d -s "$session_name" "cd '$SRC_DIR' && bash '$BUILD_SCRIPT'"
112 -
93 + echo "[$(date)] INFO: Running build script for branch $branch_name"
94 + (cd "$SRC_DIR" && bash "$BUILD_SCRIPT")
113 95 if [ $? -eq 0 ]; then
114 - echo "[$(date)] INFO: Build script launched in tmux session: $session_name"
115 -
116 - # Wait until the build script finishes inside tmux
117 - # Option 1: Polling approach until session not found
118 - echo "[$(date)] INFO: Waiting for the tmux session ($session_name) to finish..."
119 - while tmux has-session -t "$session_name" 2>/dev/null; do
120 - sleep 5
121 - done
122 -
123 - echo "[$(date)] INFO: Tmux session ($session_name) finished building"
96 + echo "[$(date)] INFO: Build script completed successfully"
124 97
125 - # After build completes, copy artifacts
98 + # Copy artifacts
126 99 echo "[$(date)] INFO: Copying build artifacts from $SRC_DIR/dists to $BASE_BUILT_DIR/$branch_name"
127 100 cp -rf "$SRC_DIR/dists/"* "$BASE_BUILT_DIR/$branch_name"/
128 101
@@ -130,7 +103,7 @@ check_and_build_branch() {
130 103 date +"%Y-%m-%d" > "$last_build_file"
131 104 echo "[$(date)] INFO: Updated last build date record for branch $branch_name"
132 105 else
133 - error_exit "[$(date)] ERROR: Failed to start build script in tmux session for branch $branch_name"
106 + error_exit "Build script failed for branch $branch_name"
134 107 fi
135 108 else
136 109 echo "[$(date)] INFO: No build needed for branch $branch_name. Keeping existing artifacts."
@@ -138,7 +111,7 @@ check_and_build_branch() {
138 111 }
139 112
140 113 # MAIN FLOW
141 - # Process each branch in sequence. We do NOT parallel-build branches.
114 + # Process each branch in sequence to avoid parallel builds.
142 115 for branch in "${BRANCHES[@]}"; do
143 116 check_and_build_branch "$branch"
144 117 done

anduin's Avatar anduin revised this gist 1735826565. Go to revision

1 file changed, 146 insertions

build.sh(file created)

@@ -0,0 +1,146 @@
1 + #!/bin/bash
2 +
3 + # daily_build_v2.sh
4 + # Script Purpose:
5 + # This script is scheduled to run daily at 21:00 UTC to:
6 + # 1) For each branch (e.g. 1.1, 1.2):
7 + # a) Switch to the branch, ensure local code is up-to-date (clean -fdx, reset --hard, pull)
8 + # b) Check if there are new commits in the past 24 hours
9 + # - If yes, a build is required
10 + # - If no but the last build was more than a week ago, a forced build is required
11 + # - Otherwise, skip
12 + # c) If a build is required, run build_all_langs.sh in a specific tmux session,
13 + # then copy build artifacts from ./src/dists/* to ~/built/<branch>/
14 + #
15 + # Additional requirements for this version:
16 + # - Do NOT build 1.1 and 1.2 at the same time. Must wait for 1.1 to finish before building 1.2.
17 + # - If no build is needed, do NOT remove any existing build artifacts.
18 + # - Provide more logs rather than comments.
19 +
20 + REPO_DIR="$HOME/anduinos"
21 + SRC_DIR="$REPO_DIR/src"
22 + BUILD_SCRIPT="$SRC_DIR/build_all_langs.sh"
23 + SESSION_NAME_PREFIX="build_session"
24 + BASE_BUILT_DIR="$HOME/built"
25 +
26 + # Branch list (example: 1.1 & 1.2)
27 + BRANCHES=("1.1" "1.2")
28 +
29 + # Print an error message and exit
30 + error_exit() {
31 + echo "[$(date)] ERROR: $1" >&2
32 + exit 1
33 + }
34 +
35 + # Function to check and build a specific branch
36 + check_and_build_branch() {
37 + local branch_name=$1
38 +
39 + local sanitized_branch_name="${branch_name//./_}"
40 + local session_name="${SESSION_NAME_PREFIX}_${sanitized_branch_name}"
41 +
42 + echo "[$(date)] INFO: Start checking branch: $branch_name"
43 + echo "[$(date)] INFO: The tmux session name will be: $session_name"
44 +
45 + local last_build_file="$HOME/.last_build_date_${branch_name}"
46 +
47 + # Switch to the repository directory
48 + echo "[$(date)] INFO: Changing directory to $REPO_DIR"
49 + cd "$REPO_DIR" || error_exit "Cannot change directory to $REPO_DIR"
50 +
51 + echo "[$(date)] INFO: Reset and fetch latest code from remote"
52 + git reset --hard HEAD
53 + git fetch
54 +
55 + echo "[$(date)] INFO: Switching to branch $branch_name"
56 + git switch "$branch_name" || error_exit "Failed to switch to branch $branch_name"
57 +
58 + echo "[$(date)] INFO: Pulling latest code"
59 + git pull || error_exit "Failed to pull latest code on branch $branch_name"
60 +
61 + # Check if new commit exists in the past 24 hours
62 + local BUILD_REQUIRED=false
63 + if git log -1 --since="24 hours ago" "$branch_name" > /dev/null 2>&1; then
64 + BUILD_REQUIRED=true
65 + echo "[$(date)] INFO: Found new commits in the past 24 hours for branch $branch_name"
66 + else
67 + # Check last build time
68 + if [ -f "$last_build_file" ]; then
69 + local last_build_date
70 + last_build_date=$(cat "$last_build_file")
71 + local last_build_epoch
72 + last_build_epoch=$(date -d "$last_build_date" +%s)
73 + local current_epoch
74 + current_epoch=$(date +%s)
75 + local seven_days_ago=$(( current_epoch - 7*86400 ))
76 +
77 + if [ "$last_build_epoch" -lt "$seven_days_ago" ]; then
78 + BUILD_REQUIRED=true
79 + echo "[$(date)] INFO: No recent commits, but last build on $last_build_date is older than 7 days; forcing a build."
80 + else
81 + echo "[$(date)] INFO: No new commits for branch $branch_name, and last build is within a week. Skipping build."
82 + fi
83 + else
84 + # If there's no record file, we consider it as needing a build
85 + BUILD_REQUIRED=true
86 + echo "[$(date)] INFO: No last_build_date record found. Forcing a build."
87 + fi
88 + fi
89 +
90 + # If build is required, proceed
91 + if [ "$BUILD_REQUIRED" = true ]; then
92 + echo "[$(date)] INFO: Build is required for branch $branch_name"
93 +
94 + # Optional: Clean up the old artifacts only when we are about to build
95 + echo "[$(date)] INFO: Removing old artifacts under $BASE_BUILT_DIR/$branch_name"
96 + rm -rf "$BASE_BUILT_DIR/$branch_name"
97 +
98 + # Ensure the build output directory exists
99 + mkdir -p "$BASE_BUILT_DIR/$branch_name"
100 +
101 + # Kill any old tmux session for this branch
102 + local session_name="${SESSION_NAME_PREFIX}_${branch_name}"
103 + echo "[$(date)] INFO: Checking and killing any existing tmux session named $session_name"
104 + if tmux has-session -t "$session_name" 2>/dev/null; then
105 + tmux kill-session -t "$session_name"
106 + echo "[$(date)] INFO: Killed existing tmux session: $session_name"
107 + fi
108 +
109 + # Start a new tmux session for build
110 + echo "[$(date)] INFO: Creating a new tmux session for building branch $branch_name"
111 + tmux new-session -d -s "$session_name" "cd '$SRC_DIR' && bash '$BUILD_SCRIPT'"
112 +
113 + if [ $? -eq 0 ]; then
114 + echo "[$(date)] INFO: Build script launched in tmux session: $session_name"
115 +
116 + # Wait until the build script finishes inside tmux
117 + # Option 1: Polling approach until session not found
118 + echo "[$(date)] INFO: Waiting for the tmux session ($session_name) to finish..."
119 + while tmux has-session -t "$session_name" 2>/dev/null; do
120 + sleep 5
121 + done
122 +
123 + echo "[$(date)] INFO: Tmux session ($session_name) finished building"
124 +
125 + # After build completes, copy artifacts
126 + echo "[$(date)] INFO: Copying build artifacts from $SRC_DIR/dists to $BASE_BUILT_DIR/$branch_name"
127 + cp -rf "$SRC_DIR/dists/"* "$BASE_BUILT_DIR/$branch_name"/
128 +
129 + # Update last build date
130 + date +"%Y-%m-%d" > "$last_build_file"
131 + echo "[$(date)] INFO: Updated last build date record for branch $branch_name"
132 + else
133 + error_exit "[$(date)] ERROR: Failed to start build script in tmux session for branch $branch_name"
134 + fi
135 + else
136 + echo "[$(date)] INFO: No build needed for branch $branch_name. Keeping existing artifacts."
137 + fi
138 + }
139 +
140 + # MAIN FLOW
141 + # Process each branch in sequence. We do NOT parallel-build branches.
142 + for branch in "${BRANCHES[@]}"; do
143 + check_and_build_branch "$branch"
144 + done
145 +
146 + echo "[$(date)] INFO: All branches processed. Script completed."
Newer Older