Skip to content

Commit e768125

Browse files
mik-tfmik-tf
authored andcommitted
workflow fix for manual
1 parent a90e3c7 commit e768125

1 file changed

Lines changed: 169 additions & 11 deletions

File tree

.github/workflows/manual_update_master.yml

Lines changed: 169 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,66 @@ jobs:
1616
key: ${{ secrets.TF_SECRET }}
1717
port: ${{ secrets.TF_PORT }}
1818
script: |
19-
cd websites/www/info_grid
19+
set -e # Exit on any error
20+
21+
# Define variables
22+
REPO_URL="https://github.com/threefoldtech/info_grid.git" # Update with actual repo URL
23+
PROJECT_DIR="websites/www/info_grid"
24+
BACKUP_DIR="websites/www/info_grid.backup.$(date +%Y%m%d%H%M%S)"
25+
26+
echo "=== Starting deployment process ==="
27+
28+
# Create websites/www directory if it doesn't exist
29+
mkdir -p websites/www
30+
cd websites/www
31+
32+
# Handle existing directory
33+
if [ -d "info_grid" ]; then
34+
echo "Found existing info_grid directory"
35+
36+
# Check if it's a git repository
37+
if [ -d "info_grid/.git" ]; then
38+
echo "Existing directory is a git repository, updating..."
39+
cd info_grid
40+
41+
# Verify we're on the correct remote
42+
CURRENT_REMOTE=$(git remote get-url origin 2>/dev/null || echo "")
43+
if [ "$CURRENT_REMOTE" != "$REPO_URL" ]; then
44+
echo "Warning: Remote URL mismatch. Expected: $REPO_URL, Found: $CURRENT_REMOTE"
45+
echo "Backing up and re-cloning..."
46+
cd ..
47+
mv info_grid "$BACKUP_DIR"
48+
git clone "$REPO_URL" info_grid
49+
cd info_grid
50+
fi
51+
else
52+
echo "Existing directory is not a git repository, backing up and re-cloning..."
53+
mv info_grid "$BACKUP_DIR"
54+
git clone "$REPO_URL" info_grid
55+
cd info_grid
56+
fi
57+
else
58+
echo "Cloning repository for the first time..."
59+
git clone "$REPO_URL" info_grid
60+
cd info_grid
61+
fi
62+
63+
# Ensure we're in the project directory
64+
if [ ! -d ".git" ]; then
65+
echo "Error: Not in a git repository after setup"
66+
exit 1
67+
fi
68+
69+
echo "=== Updating repository ==="
2070
git checkout master
21-
git log -1
22-
git fetch
71+
git log -1 --oneline
72+
git fetch origin
2373
git reset --hard origin/master
74+
75+
echo "=== Setting up Node.js environment ==="
2476
# Install or update Node.js to v20 (required for glob 11.0.1)
2577
echo "Setting up Node.js v20 for Docusaurus and glob..."
78+
2679
# Find nvm and use it if available
2780
if [ -d "$HOME/.nvm" ]; then
2881
export NVM_DIR="$HOME/.nvm"
@@ -32,41 +85,146 @@ jobs:
3285
# Use Node.js 20
3386
nvm use 20
3487
else
35-
# Alternative: Install Node.js directly
36-
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
37-
sudo apt-get install -y nodejs
88+
# Alternative: Install Node.js using NodeSource without sudo
89+
echo "NVM not found, installing Node.js directly..."
90+
91+
# Check if we already have Node.js 20
92+
if command -v node >/dev/null 2>&1; then
93+
CURRENT_NODE_VERSION=$(node -v | sed 's/v//' | cut -d. -f1)
94+
if [ "$CURRENT_NODE_VERSION" -ge 20 ]; then
95+
echo "Node.js $CURRENT_NODE_VERSION already installed, skipping installation"
96+
else
97+
echo "Node.js version too old ($CURRENT_NODE_VERSION), need to install v20"
98+
fi
99+
fi
100+
101+
# If Node.js 20+ is not available, try to install via package manager
102+
# This assumes the user has appropriate permissions or Node.js is already available
103+
if ! command -v node >/dev/null 2>&1 || [ "$CURRENT_NODE_VERSION" -lt 20 ]; then
104+
echo "Attempting to install Node.js 20 via alternative methods..."
105+
106+
# Try to install via snap if available (no sudo required for user)
107+
if command -v snap >/dev/null 2>&1; then
108+
echo "Trying snap installation..."
109+
snap install node --classic --channel=20/stable || echo "Snap installation failed, continuing..."
110+
fi
111+
112+
# Try to download and install Node.js locally
113+
if ! command -v node >/dev/null 2>&1 || [ "$(node -v | sed 's/v//' | cut -d. -f1)" -lt 20 ]; then
114+
echo "Installing Node.js locally in user directory..."
115+
cd $HOME
116+
NODE_VERSION="20.19.4"
117+
NODE_DISTRO="linux-x64"
118+
119+
# Download and extract Node.js
120+
if [ ! -d "node-v$NODE_VERSION-$NODE_DISTRO" ]; then
121+
wget -q "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-$NODE_DISTRO.tar.xz"
122+
tar -xf "node-v$NODE_VERSION-$NODE_DISTRO.tar.xz"
123+
rm "node-v$NODE_VERSION-$NODE_DISTRO.tar.xz"
124+
fi
125+
126+
# Add to PATH for this session
127+
export PATH="$HOME/node-v$NODE_VERSION-$NODE_DISTRO/bin:$PATH"
128+
129+
# Add to .bashrc for future sessions
130+
if ! grep -q "node-v$NODE_VERSION-$NODE_DISTRO/bin" ~/.bashrc 2>/dev/null; then
131+
echo "export PATH=\"\$HOME/node-v$NODE_VERSION-$NODE_DISTRO/bin:\$PATH\"" >> ~/.bashrc
132+
fi
133+
134+
cd - # Return to previous directory
135+
fi
136+
fi
38137
fi
138+
39139
# Verify Node.js version
40-
node -v
140+
NODE_VERSION=$(node -v)
141+
echo "Node.js version: $NODE_VERSION"
142+
41143
# Install Yarn if not available
42144
if ! which yarn > /dev/null; then
43145
echo "Yarn not found, installing..."
44146
npm install -g yarn
45147
fi
148+
149+
YARN_VERSION=$(yarn -v)
150+
echo "Yarn version: $YARN_VERSION"
151+
152+
echo "=== Installing dependencies ==="
46153
# Create a temporary .yarnrc file to use resolutions for glob
47154
echo '{"resolutions": {"glob": "^8.1.0"}}' > .yarnrc.json
48-
# Use the Makefile to build the site (now updated to use Yarn)
49-
make build
50155
156+
# Install dependencies
157+
yarn install --frozen-lockfile || yarn install
158+
159+
echo "=== Building project ==="
160+
# Check if Makefile exists and has build target
161+
if [ -f "Makefile" ]; then
162+
if grep -q "^build:" Makefile; then
163+
echo "Using Makefile to build..."
164+
make build
165+
else
166+
echo "Makefile exists but no 'build' target found. Available targets:"
167+
make -qp | awk -F':' '/^[a-zA-Z0-9][^$#\/\t=]*:([^=]|$)/ {split($1,A,/ /);for(i in A)print A[i]}' | sort -u
168+
echo "Attempting yarn build instead..."
169+
yarn build
170+
fi
171+
elif [ -f "package.json" ]; then
172+
echo "No Makefile found, using yarn build..."
173+
yarn build
174+
else
175+
echo "Error: No Makefile or package.json found"
176+
exit 1
177+
fi
178+
179+
echo "=== Verifying build output ==="
180+
# Check if build directory was created
181+
if [ ! -d "build" ]; then
182+
echo "Error: Build directory was not created"
183+
echo "Checking for alternative build directories..."
184+
ls -la | grep -E "(dist|public|out|_site)" || true
185+
exit 1
186+
fi
187+
188+
if [ ! "$(ls -A build)" ]; then
189+
echo "Error: Build directory is empty"
190+
exit 1
191+
fi
192+
193+
echo "Build successful. Contents of build directory:"
194+
ls -la build/
195+
196+
echo "=== Deploying to web server ==="
51197
# Move the build directory content to docs for web server
52198
echo "Moving build content to docs directory for web server..."
199+
53200
# Backup existing docs if it exists
54201
if [ -d "docs" ]; then
55202
echo "Backing up existing docs directory..."
56-
mv docs docs.bak.$(date +%Y%m%d%H%M%S)
203+
mv docs "docs.bak.$(date +%Y%m%d%H%M%S)"
57204
fi
58205
59206
# Create docs directory and copy build content
60207
mkdir -p docs
61208
cp -r build/* docs/
62209
echo "Content moved from build to docs directory successfully"
63210
211+
# Verify docs directory
212+
if [ ! "$(ls -A docs)" ]; then
213+
echo "Error: Docs directory is empty after copy"
214+
exit 1
215+
fi
216+
217+
echo "Docs directory contents:"
218+
ls -la docs/ | head -10
219+
64220
# Clean up the build directory to save space
65221
echo "Cleaning up build directory..."
66222
rm -rf build
67223
echo "Build directory removed"
68224
225+
echo "=== Deployment completed successfully ==="
69226
echo "Build completed. Web server should serve from the docs directory."
227+
echo "Deployment timestamp: $(date)"
70228
71229
wait:
72230
needs: deploy
@@ -76,7 +234,7 @@ jobs:
76234
- name: Wait Period
77235
id: wait-deploy
78236
run: |
79-
echo "Sleeping for 30"
237+
echo "Sleeping for 30 seconds to allow website update..."
80238
sleep 30
81239
82240
checklinks:

0 commit comments

Comments
 (0)