-
-
Notifications
You must be signed in to change notification settings - Fork 98
Expand file tree
/
Copy pathaction.yaml
More file actions
114 lines (99 loc) · 4.3 KB
/
action.yaml
File metadata and controls
114 lines (99 loc) · 4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
name: Detect Workspace Changes
description: Detects which workspace packages have changed using pnpm
outputs:
changed_workspaces:
description: "Space-separated list of changed workspace paths"
value: ${{ steps.detect.outputs.changed_workspaces }}
changed_workspaces_json:
description: "JSON array of changed workspace paths"
value: ${{ steps.detect.outputs.changed_workspaces_json }}
all_workspaces:
description: "JSON array of all workspace paths"
value: ${{ steps.detect.outputs.all_workspaces }}
has_changes:
description: "Whether any workspaces have changes"
value: ${{ steps.detect.outputs.has_changes }}
runs:
using: composite
steps:
- name: Detect changed workspaces
id: detect
shell: bash
run: |
set -e
# Determine base commit for comparison
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
base_ref="${{ github.event.pull_request.base.sha }}"
else
# For push events, compare with previous commit
if git rev-parse HEAD~1 >/dev/null 2>&1; then
base_ref="HEAD~1"
else
# First commit in repository
base_ref=""
fi
fi
echo "Base ref: $base_ref"
echo ""
# Use pnpm to detect changed workspaces
if [[ -n "$base_ref" ]]; then
# Get list of changed workspaces using pnpm --filter
# The [...$base_ref] syntax filters to packages that have changes since base_ref
changed_output=$(pnpm list --recursive --depth -1 --filter "...[${base_ref}]" --json 2>/dev/null || echo "[]")
else
# First commit - all workspaces are considered changed
changed_output=$(pnpm list --recursive --depth -1 --json 2>/dev/null || echo "[]")
fi
echo "Changed packages output:"
echo "$changed_output" | jq .
echo ""
# Extract workspace paths from pnpm output
changed_workspaces=$(echo "$changed_output" | jq -r '.[].path // empty' | sed "s|^$PWD/||" || echo "")
# Convert to array
readarray -t changed_array <<< "$changed_workspaces"
# Filter out empty entries
filtered_changed=()
for ws in "${changed_array[@]}"; do
if [[ -n "$ws" ]]; then
filtered_changed+=("$ws")
echo "✓ Changed: $ws"
fi
done
echo ""
# Get all workspaces for reference
all_output=$(pnpm list --recursive --depth -1 --json 2>/dev/null || echo "[]")
all_workspaces=$(echo "$all_output" | jq -r '.[].path // empty' | sed "s|^$PWD/||" || echo "")
# Output results
if [[ ${#filtered_changed[@]} -eq 0 ]]; then
echo "No workspace changes detected"
echo "changed_workspaces=" >> "$GITHUB_OUTPUT"
echo "changed_workspaces_json=[]" >> "$GITHUB_OUTPUT"
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "Changed workspaces: ${filtered_changed[*]}"
# Output as space-separated string
echo "changed_workspaces=${filtered_changed[*]}" >> "$GITHUB_OUTPUT"
# Output as JSON array (compact format, no newlines)
json_array=$(printf '%s\n' "${filtered_changed[@]}" | jq -R . | jq -s -c .)
echo "changed_workspaces_json=$json_array" >> "$GITHUB_OUTPUT"
echo "has_changes=true" >> "$GITHUB_OUTPUT"
fi
# Output all workspaces for reference (compact format, no newlines)
all_workspaces_json=$(echo "$all_workspaces" | grep -v '^$' | jq -R . | jq -s -c . || echo "[]")
echo "all_workspaces=$all_workspaces_json" >> "$GITHUB_OUTPUT"
- name: Display detection results
shell: bash
run: |
echo "## Workspace Change Detection Results" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
if [[ "${{ steps.detect.outputs.has_changes }}" == "true" ]]; then
echo "### Changed Workspaces" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo '${{ steps.detect.outputs.changed_workspaces_json }}' | jq -r '.[] | "- `" + . + "`"' >> "$GITHUB_STEP_SUMMARY"
else
echo "No workspace changes detected." >> "$GITHUB_STEP_SUMMARY"
fi
echo "" >> "$GITHUB_STEP_SUMMARY"
echo "### All Workspaces" >> "$GITHUB_STEP_SUMMARY"
echo "" >> "$GITHUB_STEP_SUMMARY"
echo '${{ steps.detect.outputs.all_workspaces }}' | jq -r '.[] | "- `" + . + "`"' >> "$GITHUB_STEP_SUMMARY"