-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
202 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
name: PR Check Workflow | ||
|
||
on: | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
check-PR: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout base commit | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.base_ref }} | ||
|
||
- name: Generate routes | ||
run: | | ||
./ci-scripts/gen_routes.sh > routes_to_test.txt | ||
- name: Upload routes file | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: routes-to-test | ||
path: routes_to_test.txt | ||
|
||
- name: Checkout PR's head commit | ||
uses: actions/checkout@v2 | ||
with: | ||
ref: ${{ github.head_ref }} | ||
|
||
- name: Download routes file | ||
uses: actions/download-artifact@v2 | ||
with: | ||
name: routes-to-test | ||
|
||
- name: Run redirect tests | ||
run: | | ||
./ci-scripts/test_redirects.sh routes_to_test.txt |
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,4 @@ | ||
.PHONY: test-redirects | ||
|
||
test-redirects: | ||
@./ci-scripts/test_redirects_local.sh |
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,8 @@ | ||
#!/bin/bash -e | ||
|
||
echo "Generating routes..." >&2 | ||
yarn build >/dev/null | ||
sed 's/xmlns="[^"]*"//g' build/sitemap.xml | xmllint --xpath '//*[local-name()="loc"]/text()' - | while read -r url; do | ||
echo "${url#https://docs.eigenlayer.xyz}" | ||
done | ||
echo "Done" >&2 |
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,89 @@ | ||
#!/bin/bash -e | ||
|
||
# Display usage information | ||
usage() { | ||
echo "Usage: $0 <filename>" | ||
echo | ||
echo "This script tests that each of the old pages redirects properly to a new page." | ||
echo "It requires a file containing URLs to test, one per line." | ||
echo | ||
echo "Usage pattern:" | ||
echo "1. Switch from new branch to old branch" | ||
echo "2. Generate routes get_routes.sh > routes_to_test.txt" | ||
echo "3. Switch from old branch to new branch (bringing routes_to_test.txt over)" | ||
echo "4. Run $0 routes_to_test.txt" | ||
echo "" | ||
echo "This script tests that each of the old pages redirects properly to a new page." | ||
echo "It does not test that this is the correct new page however." | ||
exit 1 | ||
} | ||
|
||
# Ensure server is killed on script exit | ||
cleanup() { | ||
echo "Stopping server..." | ||
if [ ! -z "$SERVER_PID" ]; then | ||
kill $SERVER_PID 2>/dev/null || echo "Server process not found." | ||
else | ||
echo "No server was started." | ||
fi | ||
} | ||
|
||
# Variable to track test failure | ||
any_fail=0 | ||
|
||
# Check for help option or no argument | ||
if [[ "$1" == "--help" ]] || [[ "$1" == "-h" ]] || [ "$#" -ne 1 ]; then | ||
usage | ||
fi | ||
|
||
# Absolute path to the filename | ||
FILENAME=$(realpath "$1") | ||
|
||
# Ensure file exists | ||
if [ ! -f "$FILENAME" ]; then | ||
echo "File not found: $FILENAME" >&2 | ||
exit 1 | ||
fi | ||
|
||
# Build the project and start the server | ||
echo "Building..." | ||
yarn build > /dev/null | ||
echo "Starting server..." | ||
./node_modules/.bin/docusaurus serve --no-open & | ||
SERVER_PID=$! | ||
echo "Server started." | ||
|
||
# Wait a bit for the server to start | ||
sleep 5 | ||
|
||
# Setup trap to clean up on script exit | ||
trap cleanup EXIT | ||
|
||
echo "" | ||
echo "Begining tests..." | ||
echo "" | ||
while IFS= read -r url; do | ||
full_url="http://localhost:3000${url}" | ||
# Perform a curl request and check both for "Page Not Found" and curl's exit status | ||
if ! curl_output=$(curl -fs "$full_url" 2>&1); then | ||
# Curl command failed | ||
printf "\033[31mtest fail\033[0m: %s\n" "$full_url" >&2 | ||
any_fail=1 | ||
else | ||
# If curl succeeded and "Page Not Found" not in output, mark test as passed | ||
printf "\033[32mtest pass\033[0m: %s\n" "$full_url" | ||
fi | ||
done < "$FILENAME" | ||
|
||
# Exit with status code 1 if any test failed | ||
if [ "$any_fail" -eq 1 ]; then | ||
echo "" | ||
printf "\033[31mOne or more tests failed!\033[0m\n" | ||
echo "" | ||
exit 1 | ||
else | ||
echo "" | ||
printf "\033[32mAll tests passed!\033[0m\n" | ||
echo "" | ||
exit 0 | ||
fi |
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,56 @@ | ||
#!/bin/bash -e | ||
|
||
REPO_TOP_LEVEL=$(git rev-parse --show-toplevel) | ||
|
||
# Fetch the latest state of origin/main | ||
git fetch origin main | ||
|
||
# Find the merge-base of the current branch and origin/main | ||
MERGE_BASE=$(git merge-base origin/main @) | ||
|
||
echo "Merge base of origin/main and $CURRENT_BRANCH is $MERGE_BASE" | ||
|
||
# Generate a random worktree path | ||
WORKTREE_PATH="/tmp/pr_worktree_$(date +%Y%m%d%H%M%S)_$RANDOM" | ||
|
||
# Ensure the worktree path is unique and does not already exist | ||
if [ -d "$WORKTREE_PATH" ]; then | ||
echo "Worktree directory already exists. Please try again." | ||
exit 1 | ||
fi | ||
|
||
# Create a new worktree for the merge-base in the temporary directory | ||
git worktree add "$WORKTREE_PATH" $MERGE_BASE | ||
|
||
# Change directory to the worktree | ||
cd "$WORKTREE_PATH" | ||
|
||
yarn | ||
|
||
# Run the script to generate the routes_to_test.txt | ||
./ci-scripts/gen_routes.sh > routes_to_test.txt | ||
|
||
# Move the routes_to_test.txt back to the original repo directory | ||
mv routes_to_test.txt "$REPO_TOP_LEVEL" | ||
|
||
# Clean up the worktree and return to the original repository directory | ||
git worktree remove "$WORKTREE_PATH" | ||
cd - | ||
|
||
# The current repo state is now the target for tests | ||
# Run the tests with the routes file in the current state of the repository | ||
set +e | ||
./ci-scripts/test_redirects.sh routes_to_test.txt | ||
TEST_REDIRECTS_EXIT_CODE=$? | ||
set -e | ||
|
||
rm routes_to_test.txt | ||
|
||
# Check the exit status of the test script and exit accordingly | ||
if [ $TEST_REDIRECTS_EXIT_CODE -ne 0 ]; then | ||
echo "Redirect tests failed." | ||
exit 1 | ||
else | ||
echo "All tests passed successfully." | ||
fi | ||
|