Skip to content

Commit e19d46c

Browse files
authored
fix(ci): paths-filter outputs not propagating to downstream jobs (#72)
* fix(ci): use direct script invocation for paths-filter Composite actions don't propagate dynamic step outputs to the caller — only explicitly declared outputs are visible. Since filter keys are dynamic, switch to calling paths-filter.sh directly in the workflow step so outputs write to the caller's GITHUB_OUTPUT natively. * fix(ci): correct segkit path in rewrite-plugin-urls.sh The script was rewriting the segkit flake ref to path:./segkit which resolves relative to the plugin directory (plugins/android/). Since segkit/ lives at repo root, the correct relative path is ../../segkit.
1 parent 725aff9 commit e19d46c

4 files changed

Lines changed: 109 additions & 76 deletions

File tree

Lines changed: 19 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
name: Paths Filter
2-
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.
2+
description: |
3+
Detect which paths changed between the PR base and HEAD using native git diff.
4+
Drop-in replacement for dorny/paths-filter without external dependencies.
5+
6+
NOTE: For outputs to propagate correctly, prefer calling the script directly
7+
in your workflow step rather than using this as a composite action:
8+
9+
- name: Detect changed paths
10+
id: filter
11+
env:
12+
FILTER_DEFINITIONS: |
13+
src:
14+
- '^src/'
15+
run: bash .github/actions/paths-filter/paths-filter.sh
16+
17+
Each filter key becomes a step output with value 'true' or 'false'.
318
419
inputs:
520
filters:
@@ -17,79 +32,13 @@ inputs:
1732
required: false
1833
default: ''
1934

20-
outputs:
21-
result:
22-
description: JSON object of all filter results
23-
value: ${{ steps.filter.outputs.result }}
24-
2535
runs:
2636
using: composite
2737
steps:
2838
- name: Compute changed paths
2939
id: filter
3040
shell: bash
3141
env:
32-
INPUT_FILTERS: ${{ inputs.filters }}
33-
INPUT_BASE: ${{ inputs.base }}
34-
run: |
35-
set -euo pipefail
36-
37-
# Determine base commit
38-
if [ -n "$INPUT_BASE" ]; then
39-
BASE="$INPUT_BASE"
40-
elif [ "${{ github.event_name }}" = "pull_request" ]; then
41-
BASE="${{ github.event.pull_request.base.sha }}"
42-
else
43-
BASE="HEAD~1"
44-
fi
45-
46-
# Get list of changed files
47-
CHANGED_FILES=$(git diff --name-only "$BASE"...HEAD 2>/dev/null || git diff --name-only "$BASE" HEAD)
48-
49-
if [ -z "$CHANGED_FILES" ]; then
50-
echo "No changed files detected"
51-
else
52-
echo "Changed files (first 50):"
53-
echo "$CHANGED_FILES" | head -50
54-
fi
55-
56-
# Parse filters and collect results
57-
declare -A RESULTS
58-
CURRENT_KEY=""
59-
60-
while IFS= read -r line; do
61-
[ -z "$(echo "$line" | tr -d '[:space:]')" ] && continue
62-
63-
if echo "$line" | grep -qE '^[a-zA-Z_][a-zA-Z0-9_-]*:'; then
64-
CURRENT_KEY=$(echo "$line" | sed 's/:.*$//' | tr -d '[:space:]')
65-
RESULTS["$CURRENT_KEY"]="false"
66-
continue
67-
fi
68-
69-
if [ -n "$CURRENT_KEY" ] && echo "$line" | grep -qE '^\s*-'; then
70-
PATTERN=$(echo "$line" | sed "s/^[[:space:]]*-[[:space:]]*//;s/^['\"]//;s/['\"]$//")
71-
PATTERN=$(echo "$PATTERN" | tr -d '[:space:]')
72-
[ -z "$PATTERN" ] && continue
73-
74-
if [ -n "$CHANGED_FILES" ] && echo "$CHANGED_FILES" | grep -qE "$PATTERN"; then
75-
RESULTS["$CURRENT_KEY"]="true"
76-
fi
77-
fi
78-
done <<< "$INPUT_FILTERS"
79-
80-
# Write outputs
81-
JSON="{"
82-
FIRST=true
83-
for key in "${!RESULTS[@]}"; do
84-
echo "${key}=${RESULTS[$key]}" >> "$GITHUB_OUTPUT"
85-
if [ "$FIRST" = true ]; then
86-
FIRST=false
87-
else
88-
JSON="$JSON,"
89-
fi
90-
JSON="$JSON\"$key\":\"${RESULTS[$key]}\""
91-
done
92-
JSON="$JSON}"
93-
94-
echo "result=$JSON" >> "$GITHUB_OUTPUT"
95-
echo "Filter results: $JSON"
42+
FILTER_DEFINITIONS: ${{ inputs.filters }}
43+
FILTER_BASE: ${{ inputs.base }}
44+
run: bash ${{ github.action_path }}/paths-filter.sh
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/usr/bin/env bash
2+
# Detect which paths changed between a base ref and HEAD.
3+
# Writes each filter key as a GITHUB_OUTPUT with value 'true' or 'false'.
4+
#
5+
# Required env:
6+
# FILTER_DEFINITIONS - YAML-style filter block (key: \n - 'pattern')
7+
# GITHUB_OUTPUT - set by GitHub Actions runner
8+
#
9+
# Optional env:
10+
# FILTER_BASE - explicit base ref to diff against
11+
#
12+
# Usage in a workflow step:
13+
# - name: Detect changes
14+
# id: filter
15+
# env:
16+
# FILTER_DEFINITIONS: |
17+
# android:
18+
# - '^plugins/android/'
19+
# - '^examples/android/'
20+
# ios:
21+
# - '^plugins/ios/'
22+
# run: bash .github/actions/paths-filter/paths-filter.sh
23+
set -euo pipefail
24+
25+
# Determine base commit
26+
if [ -n "${FILTER_BASE:-}" ]; then
27+
BASE="$FILTER_BASE"
28+
elif [ "${GITHUB_EVENT_NAME:-}" = "pull_request" ]; then
29+
BASE=$(jq -r '.pull_request.base.sha' "$GITHUB_EVENT_PATH")
30+
else
31+
BASE="HEAD~1"
32+
fi
33+
34+
# Get list of changed files
35+
CHANGED_FILES=$(git diff --name-only "$BASE"...HEAD 2>/dev/null || git diff --name-only "$BASE" HEAD)
36+
37+
if [ -z "$CHANGED_FILES" ]; then
38+
echo "No changed files detected"
39+
else
40+
echo "Changed files (first 50):"
41+
echo "$CHANGED_FILES" | head -50
42+
fi
43+
44+
# Parse filters and collect results
45+
declare -A RESULTS
46+
CURRENT_KEY=""
47+
48+
while IFS= read -r line; do
49+
[ -z "$(echo "$line" | tr -d '[:space:]')" ] && continue
50+
51+
if echo "$line" | grep -qE '^[a-zA-Z_][a-zA-Z0-9_-]*:'; then
52+
CURRENT_KEY=$(echo "$line" | sed 's/:.*$//' | tr -d '[:space:]')
53+
RESULTS["$CURRENT_KEY"]="false"
54+
continue
55+
fi
56+
57+
if [ -n "$CURRENT_KEY" ] && echo "$line" | grep -qE '^\s*-'; then
58+
PATTERN=$(echo "$line" | sed "s/^[[:space:]]*-[[:space:]]*//;s/^['\"]//;s/['\"]$//")
59+
PATTERN=$(echo "$PATTERN" | tr -d '[:space:]')
60+
[ -z "$PATTERN" ] && continue
61+
62+
if [ -n "$CHANGED_FILES" ] && echo "$CHANGED_FILES" | grep -qE "$PATTERN"; then
63+
RESULTS["$CURRENT_KEY"]="true"
64+
fi
65+
fi
66+
done <<< "$FILTER_DEFINITIONS"
67+
68+
# Write outputs
69+
JSON="{"
70+
FIRST=true
71+
for key in "${!RESULTS[@]}"; do
72+
echo "${key}=${RESULTS[$key]}" >> "$GITHUB_OUTPUT"
73+
if [ "$FIRST" = true ]; then
74+
FIRST=false
75+
else
76+
JSON="$JSON,"
77+
fi
78+
JSON="$JSON\"$key\":\"${RESULTS[$key]}\""
79+
done
80+
JSON="$JSON}"
81+
82+
echo "Filter results: $JSON"

.github/workflows/pr-checks.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ jobs:
2626
- uses: actions/checkout@v6
2727
with:
2828
fetch-depth: 0
29-
- uses: ./.github/actions/paths-filter
29+
- name: Detect changed paths
3030
id: filter
31-
with:
32-
filters: |
31+
env:
32+
FILTER_DEFINITIONS: |
3333
segkit:
3434
- '^segkit/'
3535
android:
@@ -48,6 +48,7 @@ jobs:
4848
- '^plugins/.*/scripts/'
4949
ci:
5050
- '^\.github/'
51+
run: bash .github/actions/paths-filter/paths-filter.sh
5152

5253
# Linting and formatting checks (always runs)
5354
lint:

scripts/dev/rewrite-plugin-urls.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ case "$mode" in
7171
if [ -f "$plugin_file" ] && grep -q "$segkit_github" "$plugin_file"; then
7272
echo " Rewriting segkit ref in: $plugin_file"
7373
# Replace the github flake ref with a local path ref
74+
# segkit/ is at repo root, plugins are at plugins/<platform>/
7475
jq --arg gh "$segkit_github" '.packages = (.packages | to_entries | map(
75-
if .key == $gh then .key = "path:./segkit" else . end
76+
if .key == $gh then .key = "path:../../segkit" else . end
7677
) | from_entries)' "$plugin_file" > "$plugin_file.tmp" \
7778
&& mv "$plugin_file.tmp" "$plugin_file"
7879
fi
@@ -133,10 +134,10 @@ case "$mode" in
133134
# Restore segkit package references in plugin.json files
134135
segkit_github="github:segment-integrations/mobile-devtools?dir=segkit&ref=main"
135136
for plugin_file in plugins/android/plugin.json plugins/ios/plugin.json; do
136-
if [ -f "$plugin_file" ] && grep -q "path:./segkit" "$plugin_file"; then
137+
if [ -f "$plugin_file" ] && grep -q "path:../../segkit" "$plugin_file"; then
137138
echo " Restoring segkit ref in: $plugin_file"
138139
jq --arg gh "$segkit_github" '.packages = (.packages | to_entries | map(
139-
if .key == "path:./segkit" then .key = $gh else . end
140+
if .key == "path:../../segkit" then .key = $gh else . end
140141
) | from_entries)' "$plugin_file" > "$plugin_file.tmp" \
141142
&& mv "$plugin_file.tmp" "$plugin_file"
142143
fi

0 commit comments

Comments
 (0)