Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMS-5287: Add playwright and github action to backend #956

Merged
merged 18 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
78 changes: 78 additions & 0 deletions .github/workflowScripts/getFrontendRepo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
#!/bin/bash

# Check if the search string is provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <search-string>"
exit 1
fi

# Variables
REPO_URL="https://api.github.com/repos/content-services/content-sources-frontend"
GIT_REPO_URL="https://github.com/content-services/content-sources-frontend.git"
CLONE_DIR=content-sources-frontend
TAG_NAME="#testwith"
SEARCH_STRING="$1"

# Check if the folder exists
if [ -d "$CLONE_DIR" ]; then
echo "Folder '$CLONE_DIR' exists. Removing it..."
rm -rf "$CLONE_DIR"

# Check if the removal was successful
if [ ! -d "$CLONE_DIR" ]; then
echo "Successfully removed the folder '$CLONE_DIR'."
else
echo "Failed to remove the folder '$CLONE_DIR'."
exit 1
fi
fi

# Create clone directory if it doesn't exist
mkdir -p $CLONE_DIR

# Fetch the list of open pull requests
prs=$(curl -s "$REPO_URL/pulls")

# Iterate through the list of PRs and clone the first matching PR
found_pr=false

while read -r pr; do
# Extract PR title, body, and branch details
pr_title=$(echo "$pr" | jq -r '.title')
pr_body=$(echo "$pr" | jq -r '.body')
pr_number=$(echo "$pr" | jq -r '.number')
pr_branch=$(echo "$pr" | jq -r '.head.ref')
pr_repo=$(echo "$pr" | jq -r '.head.repo.clone_url')

# Check if PR title or body contains the search string
if [[ "$pr_body" == *"$TAG_NAME"* ]] && [[ "$pr_body" == *"$SEARCH_STRING"* ]]; then
echo "Cloning PR #$pr_number: $pr_title"
git clone --branch $pr_branch $pr_repo $CLONE_DIR

# Check if the clone was successful
if [ $? -eq 0 ]; then
found_pr=true
echo "Successfully cloned PR #$pr_number into $CLONE_DIR"
else
echo "Failed to clone PR #$pr_number"
exit 1
fi

# Exit the loop after cloning the first matching PR
break
fi
done < <(echo "$prs" | jq -c '.[]')

# If no matching PR was found, clone the main branch
if [ "$found_pr" == false ]; then
echo "No PR title or description contains '$TAG_NAME $SEARCH_STRING'. Cloning the main branch."
git clone --branch main $GIT_REPO_URL $CLONE_DIR

# Check if the clone was successful
if [ $? -eq 0 ]; then
echo "Successfully cloned main branch into $CLONE_DIR"
else
echo "Failed to clone the main branch"
exit 1
fi
fi
29 changes: 29 additions & 0 deletions .github/workflowScripts/waitForBackend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

# Function to check if the server is up
is_server_up() {
response=$(curl --write-out '%{http_code}' --silent --output /dev/null http://127.0.0.1:8000/ping)
if [ "$response" -eq 200 ]; then
return 0
else
return 1
fi
}

# Wait for the server to be ready with a timeout
echo "Waiting for backend to be ready..."
timeout=180 # Timeout in seconds
interval=1 # Check interval in seconds
elapsed=0

until is_server_up; do
printf "\r%d/%d seconds have elapsed until timeout..." "$elapsed" "$timeout"
sleep $interval
elapsed=$((elapsed + interval))
if [ $elapsed -ge $timeout ]; then
echo -e "\nError: Timed out waiting for the backend server to be ready."
exit 1
fi
done

echo -e "\nBackend server is up and running after $elapsed seconds"
37 changes: 23 additions & 14 deletions .github/workflows/content-sources-actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,22 @@ on:
branches:
- main
paths-ignore:
- '**.md'
- "**.md"
pull_request:
paths-ignore:
- '**.md'
- "**.md"

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
openapidiff:
name: Openapi diff
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.23"
- run: |
Expand All @@ -28,7 +33,7 @@ jobs:
name: openapi validate
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: openapi-generators/openapitools-generator-action@v1
with:
generator: python
Expand All @@ -38,22 +43,23 @@ jobs:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3

- uses: actions/setup-go@v5
with:
go-version: "1.23"

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.61.0
skip-go-installation: true
args: --timeout=5m

checkmigrations:
name: Check db migrations
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- uses: tj-actions/changed-files@v41
id: files
- run: |
Expand All @@ -62,12 +68,12 @@ jobs:
migrations_latest=$(cat db/migrations.latest)
num_files_added=${{ steps.files.outputs.added_files_count }}
if [ "$num_files_added" -gt 0 ]; then
if [ "$num_files_added" -gt 0 ]; then
new_migrations_added=$(echo "${{ steps.files.outputs.added_files }}" | grep 'db/migrations' || true)
if [ -n "$new_migrations_added" ]; then
if echo "$new_migrations_added" | grep -q "$migrations_latest"; then
echo "OK: Latest migration content (db/migrations.latest) reflects the timestamp of the latest migrations added."
else
else
echo "Error: Latest migration content (db/migrations.latest) does NOT reflect the timestamp of the latest migrations added."
echo "New migration files added: $new_migrations_added"
echo "In db/migration.latest: $migrations_latest"
Expand Down Expand Up @@ -96,8 +102,8 @@ jobs:
ports:
- 5433:5432
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version: "1.23"
- name: unit tests
Expand All @@ -116,10 +122,12 @@ jobs:
CLIENTS_CANDLEPIN_USERNAME: admin
CLIENTS_CANDLEPIN_PASSWORD: admin
CLIENTS_CANDLEPIN_DEVEL_ORG: true

- name: Add hosts to /etc/hosts
run: |
# allows pulp container to talk to the host at this hostname
sudo echo "172.17.0.1 pulp.content" | sudo tee -a /etc/hosts
- name: start pulp
uses: isbang/[email protected]
with:
Expand Down Expand Up @@ -166,6 +174,7 @@ jobs:
CLIENTS_CANDLEPIN_USERNAME: admin
CLIENTS_CANDLEPIN_PASSWORD: admin
CLIENTS_CANDLEPIN_DEVEL_ORG: true

- name: db migration tests
run: |
make test-db-migrations
Expand Down
Loading