Skip to content

Commit e50ab70

Browse files
authored
feat: Adds script to check for changes (#467)
* feat: Adds script to check for changes Adds the first version of find-changes.sh, which detects changed or added files in subfolders of samples/; this will allow us to optimize testing and building by operating only on things that have changed. * feat: Update release.yml Adds debug statement to release.yml, but importantly ALSO removes the build-all statement, in anticipation that it's not coming back.
1 parent 2cdd4e1 commit e50ab70

File tree

2 files changed

+85
-1
lines changed

2 files changed

+85
-1
lines changed

.github/workflows/release.yml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,22 @@ jobs:
5454
node-version: '22.x'
5555

5656
- run: npm i
57-
- run: npm run build-all
57+
58+
- name: Get Affected Workspaces
59+
id: get_workspaces
60+
run: bash samples/find-changes.sh origin/main
61+
62+
- name: Build Affected Projects
63+
if: steps.get_workspaces.outputs.changed_workspaces != ''
64+
run: |
65+
IFS=$'\n'
66+
AFFECTED_WORKSPACES_ARRAY=(${{ steps.get_workspaces.outputs.changed_workspaces }})
67+
68+
echo "Building affected workspaces:"
69+
for workspace in "${AFFECTED_WORKSPACES_ARRAY[@]}"; do
70+
echo " - samples/$workspace"
71+
npm run build --workspace=samples/$workspace
72+
done
5873
5974
- uses: google-github-actions/auth@v1
6075
with:

samples/find-changes.sh

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/bin/bash
2+
3+
# This script is intended to be run from the root directory.
4+
5+
# --- Configuration ---
6+
BASE_REF=${1:-"origin/main"}
7+
PROJECTS_ROOT_DIR="samples/"
8+
9+
# --- Script Logic ---
10+
11+
echo "Detecting changed (added or modified) subfolders in '$PROJECTS_ROOT_DIR' since '$BASE_REF'..."
12+
13+
# Get files that were ADDED or MODIFIED in the PROJECTS_ROOT_DIR
14+
CHANGED_FILES=$(git diff --name-only --diff-filter=AM $BASE_REF HEAD -- "$PROJECTS_ROOT_DIR")
15+
16+
# Determine if we are in a GitHub Actions environment
17+
# GITHUB_ACTIONS is a built-in environment variable set to 'true' by GitHub Actions
18+
IS_GH_ACTIONS="${GITHUB_ACTIONS:-false}"
19+
20+
# Function to set GitHub Actions output
21+
set_gh_output() {
22+
local name="$1"
23+
local value="$2"
24+
if [ "$IS_GH_ACTIONS" = "true" ]; then
25+
# Use the proper way to set multi-line output in GitHub Actions
26+
echo "$name<<EOF" >> "$GITHUB_OUTPUT"
27+
echo "$value" >> "$GITHUB_OUTPUT"
28+
echo "EOF" >> "$GITHUB_OUTPUT"
29+
fi
30+
}
31+
32+
if [ -z "$CHANGED_FILES" ]; then
33+
echo "No changes detected in '$PROJECTS_ROOT_DIR'."
34+
set_gh_output "changed_workspaces" "" # Set an empty output for GH Actions
35+
exit 0
36+
fi
37+
38+
echo "All added or modified files detected:"
39+
echo "$CHANGED_FILES"
40+
echo "---"
41+
42+
AFFECTED_SUBFOLDERS=""
43+
for file in $CHANGED_FILES; do
44+
relative_path="${file#$PROJECTS_ROOT_DIR}"
45+
46+
if [[ -n "$relative_path" && "$relative_path" == */* ]]; then
47+
subfolder=$(echo "$relative_path" | cut -d '/' -f 1)
48+
49+
if [ -n "$subfolder" ]; then
50+
AFFECTED_SUBFOLDERS+="$subfolder\n"
51+
fi
52+
else
53+
echo "Ignoring change to file directly in '$PROJECTS_ROOT_DIR': $file"
54+
fi
55+
done
56+
57+
UNIQUE_CHANGED_WORKSPACES=$(echo -e "$AFFECTED_SUBFOLDERS" | sort -u)
58+
59+
if [ -z "$UNIQUE_CHANGED_WORKSPACES" ]; then
60+
echo "No specific project subfolders affected within '$PROJECTS_ROOT_DIR'."
61+
set_gh_output "changed_workspaces" "" # Set an empty output for GH Actions
62+
exit 0
63+
fi
64+
65+
echo "Changed (added or modified) subfolders in '$PROJECTS_ROOT_DIR':"
66+
echo "$UNIQUE_CHANGED_WORKSPACES"
67+
68+
# Set the output variable for GitHub Actions
69+
set_gh_output "changed_workspaces" "$UNIQUE_CHANGED_WORKSPACES"

0 commit comments

Comments
 (0)