Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
89 changes: 19 additions & 70 deletions .github/actions/paths-filter/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
name: Paths Filter
description: Detect which paths changed between the PR base and HEAD using native git diff. Drop-in replacement for dorny/paths-filter without external dependencies.
description: |
Detect which paths changed between the PR base and HEAD using native git diff.
Drop-in replacement for dorny/paths-filter without external dependencies.

NOTE: For outputs to propagate correctly, prefer calling the script directly
in your workflow step rather than using this as a composite action:

- name: Detect changed paths
id: filter
env:
FILTER_DEFINITIONS: |
src:
- '^src/'
run: bash .github/actions/paths-filter/paths-filter.sh

Each filter key becomes a step output with value 'true' or 'false'.

inputs:
filters:
Expand All @@ -17,79 +32,13 @@ inputs:
required: false
default: ''

outputs:
result:
description: JSON object of all filter results
value: ${{ steps.filter.outputs.result }}

runs:
using: composite
steps:
- name: Compute changed paths
id: filter
shell: bash
env:
INPUT_FILTERS: ${{ inputs.filters }}
INPUT_BASE: ${{ inputs.base }}
run: |
set -euo pipefail

# Determine base commit
if [ -n "$INPUT_BASE" ]; then
BASE="$INPUT_BASE"
elif [ "${{ github.event_name }}" = "pull_request" ]; then
BASE="${{ github.event.pull_request.base.sha }}"
else
BASE="HEAD~1"
fi

# Get list of changed files
CHANGED_FILES=$(git diff --name-only "$BASE"...HEAD 2>/dev/null || git diff --name-only "$BASE" HEAD)

if [ -z "$CHANGED_FILES" ]; then
echo "No changed files detected"
else
echo "Changed files (first 50):"
echo "$CHANGED_FILES" | head -50
fi

# Parse filters and collect results
declare -A RESULTS
CURRENT_KEY=""

while IFS= read -r line; do
[ -z "$(echo "$line" | tr -d '[:space:]')" ] && continue

if echo "$line" | grep -qE '^[a-zA-Z_][a-zA-Z0-9_-]*:'; then
CURRENT_KEY=$(echo "$line" | sed 's/:.*$//' | tr -d '[:space:]')
RESULTS["$CURRENT_KEY"]="false"
continue
fi

if [ -n "$CURRENT_KEY" ] && echo "$line" | grep -qE '^\s*-'; then
PATTERN=$(echo "$line" | sed "s/^[[:space:]]*-[[:space:]]*//;s/^['\"]//;s/['\"]$//")
PATTERN=$(echo "$PATTERN" | tr -d '[:space:]')
[ -z "$PATTERN" ] && continue

if [ -n "$CHANGED_FILES" ] && echo "$CHANGED_FILES" | grep -qE "$PATTERN"; then
RESULTS["$CURRENT_KEY"]="true"
fi
fi
done <<< "$INPUT_FILTERS"

# Write outputs
JSON="{"
FIRST=true
for key in "${!RESULTS[@]}"; do
echo "${key}=${RESULTS[$key]}" >> "$GITHUB_OUTPUT"
if [ "$FIRST" = true ]; then
FIRST=false
else
JSON="$JSON,"
fi
JSON="$JSON\"$key\":\"${RESULTS[$key]}\""
done
JSON="$JSON}"

echo "result=$JSON" >> "$GITHUB_OUTPUT"
echo "Filter results: $JSON"
FILTER_DEFINITIONS: ${{ inputs.filters }}
FILTER_BASE: ${{ inputs.base }}
run: bash ${{ github.action_path }}/paths-filter.sh
82 changes: 82 additions & 0 deletions .github/actions/paths-filter/paths-filter.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/env bash
# Detect which paths changed between a base ref and HEAD.
# Writes each filter key as a GITHUB_OUTPUT with value 'true' or 'false'.
#
# Required env:
# FILTER_DEFINITIONS - YAML-style filter block (key: \n - 'pattern')
# GITHUB_OUTPUT - set by GitHub Actions runner
#
# Optional env:
# FILTER_BASE - explicit base ref to diff against
#
# Usage in a workflow step:
# - name: Detect changes
# id: filter
# env:
# FILTER_DEFINITIONS: |
# android:
# - '^plugins/android/'
# - '^examples/android/'
# ios:
# - '^plugins/ios/'
# run: bash .github/actions/paths-filter/paths-filter.sh
set -euo pipefail

# Determine base commit
if [ -n "${FILTER_BASE:-}" ]; then
BASE="$FILTER_BASE"
elif [ "${GITHUB_EVENT_NAME:-}" = "pull_request" ]; then
BASE=$(jq -r '.pull_request.base.sha' "$GITHUB_EVENT_PATH")
else
BASE="HEAD~1"
fi

# Get list of changed files
CHANGED_FILES=$(git diff --name-only "$BASE"...HEAD 2>/dev/null || git diff --name-only "$BASE" HEAD)

if [ -z "$CHANGED_FILES" ]; then
echo "No changed files detected"
else
echo "Changed files (first 50):"
echo "$CHANGED_FILES" | head -50
fi

# Parse filters and collect results
declare -A RESULTS
CURRENT_KEY=""

while IFS= read -r line; do
[ -z "$(echo "$line" | tr -d '[:space:]')" ] && continue

if echo "$line" | grep -qE '^[a-zA-Z_][a-zA-Z0-9_-]*:'; then
CURRENT_KEY=$(echo "$line" | sed 's/:.*$//' | tr -d '[:space:]')
RESULTS["$CURRENT_KEY"]="false"
continue
fi

if [ -n "$CURRENT_KEY" ] && echo "$line" | grep -qE '^\s*-'; then
PATTERN=$(echo "$line" | sed "s/^[[:space:]]*-[[:space:]]*//;s/^['\"]//;s/['\"]$//")
PATTERN=$(echo "$PATTERN" | tr -d '[:space:]')
[ -z "$PATTERN" ] && continue

if [ -n "$CHANGED_FILES" ] && echo "$CHANGED_FILES" | grep -qE "$PATTERN"; then
RESULTS["$CURRENT_KEY"]="true"
fi
fi
done <<< "$FILTER_DEFINITIONS"

# Write outputs
JSON="{"
FIRST=true
for key in "${!RESULTS[@]}"; do
echo "${key}=${RESULTS[$key]}" >> "$GITHUB_OUTPUT"
if [ "$FIRST" = true ]; then
FIRST=false
else
JSON="$JSON,"
fi
JSON="$JSON\"$key\":\"${RESULTS[$key]}\""
done
JSON="$JSON}"

echo "Filter results: $JSON"
7 changes: 4 additions & 3 deletions .github/workflows/pr-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ jobs:
- uses: actions/checkout@v6
with:
fetch-depth: 0
- uses: ./.github/actions/paths-filter
- name: Detect changed paths
id: filter
with:
filters: |
env:
FILTER_DEFINITIONS: |
segkit:
- '^segkit/'
android:
Expand All @@ -48,6 +48,7 @@ jobs:
- '^plugins/.*/scripts/'
ci:
- '^\.github/'
run: bash .github/actions/paths-filter/paths-filter.sh

# Linting and formatting checks (always runs)
lint:
Expand Down
7 changes: 4 additions & 3 deletions scripts/dev/rewrite-plugin-urls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ case "$mode" in
if [ -f "$plugin_file" ] && grep -q "$segkit_github" "$plugin_file"; then
echo " Rewriting segkit ref in: $plugin_file"
# Replace the github flake ref with a local path ref
# segkit/ is at repo root, plugins are at plugins/<platform>/
jq --arg gh "$segkit_github" '.packages = (.packages | to_entries | map(
if .key == $gh then .key = "path:./segkit" else . end
if .key == $gh then .key = "path:../../segkit" else . end
) | from_entries)' "$plugin_file" > "$plugin_file.tmp" \
&& mv "$plugin_file.tmp" "$plugin_file"
fi
Expand Down Expand Up @@ -133,10 +134,10 @@ case "$mode" in
# Restore segkit package references in plugin.json files
segkit_github="github:segment-integrations/mobile-devtools?dir=segkit&ref=main"
for plugin_file in plugins/android/plugin.json plugins/ios/plugin.json; do
if [ -f "$plugin_file" ] && grep -q "path:./segkit" "$plugin_file"; then
if [ -f "$plugin_file" ] && grep -q "path:../../segkit" "$plugin_file"; then
echo " Restoring segkit ref in: $plugin_file"
jq --arg gh "$segkit_github" '.packages = (.packages | to_entries | map(
if .key == "path:./segkit" then .key = $gh else . end
if .key == "path:../../segkit" then .key = $gh else . end
) | from_entries)' "$plugin_file" > "$plugin_file.tmp" \
&& mv "$plugin_file.tmp" "$plugin_file"
fi
Expand Down
Loading