-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from hydephp/add-warning-if-a-site-url-is-not-set
Add warning if a site URL is not set
- Loading branch information
Showing
4 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
# Function to check if SITE_URL is effectively set | ||
check_site_url() { | ||
# Check if SITE_URL is set in .env file | ||
if grep -q "^SITE_URL=" .env; then | ||
return 0 | ||
fi | ||
|
||
# Check for hyde.yml or hyde.yaml with any url setting | ||
if [ -f "hyde.yml" ] && grep -q "^[[:space:]]*url:" hyde.yml; then | ||
return 0 | ||
fi | ||
|
||
if [ -f "hyde.yaml" ] && grep -q "^[[:space:]]*url:" hyde.yaml; then | ||
return 0 | ||
fi | ||
|
||
# If config/hyde.php exists, check if it has a non-localhost URL | ||
if [ -f "config/hyde.php" ]; then | ||
# Look for url configuration line and exclude localhost | ||
if grep -q "'url' => env('SITE_URL'," config/hyde.php; then | ||
line_number=$(grep -n "'url' => env('SITE_URL'," config/hyde.php | cut -d: -f1) | ||
if ! grep -q "'url' => env('SITE_URL', 'http://localhost')," config/hyde.php; then | ||
return 0 | ||
fi | ||
echo "::warning file=config/hyde.php,line=$line_number,title=Missing Site URL::The site URL is set to localhost in your configuration file. Consider setting a production URL here or in using the 'env' input with 'SITE_URL=https://example.com'" | ||
return 0 | ||
fi | ||
fi | ||
|
||
echo "::warning title=Missing Site URL::No SITE_URL environment variable found. It's recommended to set a production URL for your site. You can set it using the 'env' input with 'SITE_URL=https://example.com'" | ||
return 0 | ||
} | ||
|
||
# Show warning if SITE_URL is not properly set | ||
check_site_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/bin/bash | ||
|
||
test_site_url_warnings() { | ||
base_dir="$(pwd)" | ||
temp_dir=$(mktemp -d) | ||
cd "$temp_dir" | ||
|
||
# Test case 1: No SITE_URL set anywhere | ||
touch .env | ||
output=$(bash "$base_dir/src/check-site-url.sh") | ||
expected="::warning title=Missing Site URL::No SITE_URL environment variable found. It's recommended to set a production URL for your site. You can set it using the 'env' input with 'SITE_URL=https://example.com'" | ||
|
||
if [[ "$output" != "$expected" ]]; then | ||
echo "Test 1 failed: Warning not shown when SITE_URL is missing" | ||
echo "Expected: $expected" | ||
echo "Got: $output" | ||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
exit 1 | ||
fi | ||
|
||
# Test case 2: SITE_URL is set in .env | ||
echo "SITE_URL=https://example.com" > .env | ||
output=$(bash "$base_dir/src/check-site-url.sh") | ||
|
||
if [[ -n "$output" ]]; then | ||
echo "Test 2 failed: Warning shown when SITE_URL is set" | ||
echo "Expected empty output" | ||
echo "Got: $output" | ||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
exit 1 | ||
fi | ||
|
||
# Test case 3: SITE_URL set in config with non-localhost value | ||
rm .env | ||
mkdir -p config | ||
echo "'url' => env('SITE_URL', 'https://example.com')," > config/hyde.php | ||
output=$(bash "$base_dir/src/check-site-url.sh") | ||
|
||
if [[ -n "$output" ]]; then | ||
echo "Test 3 failed: Warning shown when SITE_URL is set in config" | ||
echo "Expected empty output" | ||
echo "Got: $output" | ||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
exit 1 | ||
fi | ||
|
||
# Test case 4: SITE_URL in config but with localhost | ||
echo "'url' => env('SITE_URL', 'http://localhost')," > config/hyde.php | ||
output=$(bash "$base_dir/src/check-site-url.sh") | ||
expected="::warning file=config/hyde.php,line=1,title=Missing Site URL::The site URL is set to localhost in your configuration file. Consider setting a production URL here or in using the 'env' input with 'SITE_URL=https://example.com'" | ||
|
||
if [[ "$output" != "$expected" ]]; then | ||
echo "Test 4 failed: Warning not shown when SITE_URL is localhost" | ||
echo "Expected: $expected" | ||
echo "Got: $output" | ||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
exit 1 | ||
fi | ||
|
||
# Test case 5: URL set in hyde.yml | ||
rm config/hyde.php | ||
echo "url: http://localhost" > hyde.yml | ||
output=$(bash "$base_dir/src/check-site-url.sh") | ||
|
||
if [[ -n "$output" ]]; then | ||
echo "Test 5 failed: Warning shown when URL is set in hyde.yml" | ||
echo "Expected empty output" | ||
echo "Got: $output" | ||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
exit 1 | ||
fi | ||
|
||
# Test case 6: URL set in hyde.yaml with indentation | ||
rm hyde.yml | ||
echo " url: example.com" > hyde.yaml | ||
output=$(bash "$base_dir/src/check-site-url.sh") | ||
|
||
if [[ -n "$output" ]]; then | ||
echo "Test 6 failed: Warning shown when URL is set in hyde.yaml" | ||
echo "Expected empty output" | ||
echo "Got: $output" | ||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
exit 1 | ||
fi | ||
|
||
cd "$base_dir" | ||
rm -rf "$temp_dir" | ||
} | ||
|
||
# Run the tests | ||
test_site_url_warnings |