Skip to content

Commit 5ece1e1

Browse files
committed
ci: build only the templates a push touches
A first job diffs the push against its base (the previous tip on main, the merge-base with main elsewhere) and feeds the affected templates to the build matrix. Shared inputs rebuild everything; Markdown-only changes build nothing.
1 parent 1b1a334 commit 5ece1e1

1 file changed

Lines changed: 63 additions & 23 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 63 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,77 @@ name: '@nativescript/template-* -> test'
33
on: push
44

55
jobs:
6+
# Only templates whose files changed are built; anything they all share
7+
# (shared-mobile, prepareTemplates.js, the root package files, this
8+
# workflow) rebuilds every template. Vision and Solid templates are not
9+
# built here, so the list below is the universe, not the packages dir.
10+
changes:
11+
runs-on: ubuntu-latest
12+
outputs:
13+
templates: ${{ steps.list.outputs.templates }}
14+
steps:
15+
- uses: actions/checkout@v4
16+
with:
17+
fetch-depth: 0
18+
19+
- id: list
20+
env:
21+
BEFORE: ${{ github.event.before }}
22+
ALL: |
23+
template-blank
24+
template-blank-vue-ts
25+
template-hello-world-ng
26+
template-tab-navigation
27+
template-blank-ng
28+
template-drawer-navigation
29+
template-hello-world-ts
30+
template-tab-navigation-ng
31+
template-blank-react
32+
template-drawer-navigation-ng
33+
template-master-detail
34+
template-tab-navigation-ts
35+
template-blank-svelte
36+
template-drawer-navigation-ts
37+
template-master-detail-ng
38+
template-tab-navigation-vue
39+
template-blank-ts
40+
template-drawer-navigation-vue
41+
template-master-detail-ts
42+
template-blank-vue
43+
template-hello-world
44+
template-master-detail-vue
45+
run: |
46+
if [ "$GITHUB_REF_NAME" = "main" ] && git cat-file -e "$BEFORE" 2>/dev/null; then
47+
base=$BEFORE
48+
else
49+
base=$(git merge-base origin/main HEAD)
50+
fi
51+
changed=$(git diff --name-only "$base" HEAD | grep -vE '\.md$' || true)
52+
53+
if [ -z "$changed" ]; then
54+
selected=""
55+
elif echo "$changed" | grep -qvE '^packages/template-[^/]+/'; then
56+
selected=$ALL
57+
else
58+
changedDirs=$(echo "$changed" | grep -oE '^packages/template-[^/]+' | xargs -n1 basename | sort -u)
59+
selected=$(comm -12 <(echo "$ALL" | sort) <(echo "$changedDirs"))
60+
fi
61+
62+
templates=$(printf '%s\n' $selected | grep . | jq -R . | jq -sc .)
63+
echo "templates=$templates" >> "$GITHUB_OUTPUT"
64+
echo "Building: $templates"
65+
666
test:
67+
needs: changes
68+
if: needs.changes.outputs.templates != '[]'
769
runs-on: macos-15
870

971
name: ${{ matrix.template }} (node ${{ matrix.node }})
1072

1173
strategy:
1274
fail-fast: false
1375
matrix:
14-
template:
15-
- template-blank
16-
- template-blank-vue-ts
17-
- template-hello-world-ng
18-
- template-tab-navigation
19-
- template-blank-ng
20-
- template-drawer-navigation
21-
- template-hello-world-ts
22-
- template-tab-navigation-ng
23-
- template-blank-react
24-
- template-drawer-navigation-ng
25-
- template-master-detail
26-
- template-tab-navigation-ts
27-
- template-blank-svelte
28-
- template-drawer-navigation-ts
29-
- template-master-detail-ng
30-
- template-tab-navigation-vue
31-
- template-blank-ts
32-
- template-drawer-navigation-vue
33-
- template-master-detail-ts
34-
- template-blank-vue
35-
- template-hello-world
36-
- template-master-detail-vue
76+
template: ${{ fromJSON(needs.changes.outputs.templates) }}
3777
node: ['lts/*']
3878

3979
steps:

0 commit comments

Comments
 (0)