Skip to content

Commit

Permalink
improve pattern matching
Browse files Browse the repository at this point in the history
  • Loading branch information
Sawyer committed Oct 23, 2024
1 parent 4912e0f commit 4790ed7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
23 changes: 20 additions & 3 deletions .github/workflows/dynamic-service-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,20 @@ jobs:
# List of directories to exclude (space-separated)
EXCLUDED_DIRS="deployment resources gef-portal-scraper"
echo "🔍 Changed files in this push/PR:"
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
echo " → $file"
done
# Find all Dockerfiles in service directories
for dockerfile in $(find . -name "Dockerfile" -not -path "*/\.*"); do
# Get service directory (parent of Dockerfile)
service_dir=$(dirname "$dockerfile")
service_name=$(basename "$service_dir")
echo "📦 Checking service: $service_name"
echo " • Directory: $service_dir"
# Skip if directory is in excluded list
skip=false
for excluded in $EXCLUDED_DIRS; do
Expand All @@ -66,18 +74,27 @@ jobs:
# Check for changes in service directory
CHANGED=false
for file in ${{ steps.changed-files.outputs.all_changed_files }}; do
if [[ $file == $service_dir/* ]]; then
# Remove leading ./ from paths for consistent comparison
clean_file=$(echo "$file" | sed 's|^\./||')
clean_dir=$(echo "$service_dir" | sed 's|^\./||')
echo " • Comparing changed file: $clean_file"
echo " • With service dir: $clean_dir"
if [[ "$clean_file" == "$clean_dir"* ]]; then
CHANGED=true
echo "✨ Found changes in service: $service_name"
echo " Changed file: $file"
echo " Changed file: $clean_file"
break
fi
done
# If changes detected, add to build matrix
if [ "$CHANGED" = true ]; then
echo "🔨 Adding $service_name to build matrix"
MATRIX="${MATRIX}${SEPARATOR}{\"service\": \"${service_name}\", \"context\": \"${service_dir#./}\"}"
# Remove leading ./ from context path
context_path=$(echo "$service_dir" | sed 's|^\./||')
MATRIX="${MATRIX}${SEPARATOR}{\"service\": \"${service_name}\", \"context\": \"${context_path}\"}"
SEPARATOR=","
else
echo "⏭️ No changes detected for $service_name - skipping"
Expand Down
2 changes: 1 addition & 1 deletion ml-api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,4 @@ EXPOSE 8000
CMD ["uvicorn", "ml_api.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"]


# test
# test 1

0 comments on commit 4790ed7

Please sign in to comment.