forked from vercel/workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresolve-symlinks.sh
More file actions
executable file
·87 lines (71 loc) · 2.45 KB
/
Copy pathresolve-symlinks.sh
File metadata and controls
executable file
·87 lines (71 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash
set -e
# Script to recursively resolve all symlinks in the app directory
# This is needed for CI where Next.js dev mode doesn't work well with symlinks
# Only run in CI
if [ -z "$CI" ]; then
echo "Error: This script should only be run in CI environments"
echo "If you need to resolve symlinks locally, run it manually with CI=true"
exit 1
fi
echo "Resolving symlinked files in workflows directory..."
# Special handling for workflows directory if it's a symlink
if [ -L "workflows" ]; then
workflows_target=$(readlink "workflows")
# Resolve relative path
if [[ "$workflows_target" != /* ]]; then
workflows_target="$PWD/$workflows_target"
fi
echo "Workflows directory is a symlink to: $workflows_target"
# Remove the workflows symlink
rm "workflows"
# Create workflows as a real directory
mkdir -p "workflows"
# Copy all files from the target, resolving any symlinks in the process
if [ -d "$workflows_target" ]; then
for file in "$workflows_target"/*; do
filename=$(basename "$file")
if [ -L "$file" ]; then
# If it's a symlink, resolve it
file_target=$(readlink "$file")
if [[ "$file_target" != /* ]]; then
file_target="$(dirname "$file")/$file_target"
fi
echo " Copying and resolving: $filename -> $file_target"
cp "$file_target" "workflows/$filename"
else
# If it's a regular file, just copy it
echo " Copying: $filename"
cp "$file" "workflows/$filename"
fi
done
fi
fi
echo "Resolving other symlinks..."
# Find all other symlinks (excluding workflows which we already handled)
git ls-files -z --cached --others --exclude-standard | xargs -0 -I {} sh -c 'test -L "{}" && echo "{}"' | while read -r symlink; do
# Skip workflows directory as we already handled it
if [ "$symlink" = "workflows" ]; then
continue
fi
# Get the target of the symlink
target=$(readlink "$symlink")
# Check if target is absolute or relative
if [[ "$target" = /* ]]; then
resolved_target="$target"
else
# Resolve relative symlink path
symlink_dir=$(dirname "$symlink")
resolved_target="$symlink_dir/$target"
fi
echo "Resolving: $symlink -> $resolved_target"
# Remove the symlink
rm "$symlink"
# Copy the target to the symlink location
if [ -d "$resolved_target" ]; then
cp -r "$resolved_target" "$symlink"
else
cp "$resolved_target" "$symlink"
fi
done
echo "All symlinks resolved successfully!"