-
Notifications
You must be signed in to change notification settings - Fork 92
176 lines (159 loc) 路 6.23 KB
/
Copy pathtest-templates.yml
File metadata and controls
176 lines (159 loc) 路 6.23 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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Test Templates
concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
cancel-in-progress: true
on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 0 * * *' # Daily at midnight UTC
permissions:
contents: read
jobs:
setup-templates:
runs-on: ubuntu-latest
outputs:
templates: ${{ steps.set-matrix.outputs.templates }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Get changed files
id: changed-files
if: github.event_name == 'pull_request'
shell: bash
run: |
# Get changed files in the PR
git fetch origin ${{ github.base_ref }}
CHANGED_FILES=$(git diff --name-only origin/${{ github.base_ref }}...HEAD)
echo "Changed files:"
echo "$CHANGED_FILES"
echo "changed_files<<EOF" >> $GITHUB_OUTPUT
echo "$CHANGED_FILES" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- id: set-matrix
shell: bash
run: |
ALL_TEMPLATES=$(cat .github/workflows/templates.json)
# Filter out community templates - they are maintained externally
TESTABLE_TEMPLATES=$(echo $ALL_TEMPLATES | jq -c '[.[] | select(startswith("community/") | not)]')
# For scheduled runs or pushes to main, test all templates (except community)
if [[ "${{ github.event_name }}" == "schedule" ]] || [[ "${{ github.event_name }}" == "push" ]]; then
echo "Running all templates except community (scheduled or push to main)"
echo templates=$(echo $TESTABLE_TEMPLATES | sed 's/ //g') | tee --append $GITHUB_OUTPUT
exit 0
fi
# For PRs, filter templates based on changed files
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
CHANGED_FILES="${{ steps.changed-files.outputs.changed_files }}"
# Check if test-related workflow or action files changed - if so, test all templates (except community)
if echo "$CHANGED_FILES" | grep -q -E '^\.github/(actions/|workflows/test-templates\.yml)'; then
echo "Test workflow or actions changed, testing all templates except community"
echo templates=$(echo $TESTABLE_TEMPLATES | sed 's/ //g') | tee --append $GITHUB_OUTPUT
exit 0
fi
# Extract template paths from changed files (excluding community)
AFFECTED_TEMPLATES=$(echo "$CHANGED_FILES" | grep -E '^(kit|mobile|web3js)/' | cut -d'/' -f1-2 | sort -u || true)
if [[ -z "$AFFECTED_TEMPLATES" ]]; then
echo "No template files changed, skipping template tests"
echo 'templates=[]' | tee --append $GITHUB_OUTPUT
exit 0
fi
echo "Affected templates:"
echo "$AFFECTED_TEMPLATES"
# Filter the templates.json to only include affected templates (excluding community)
FILTERED_TEMPLATES=$(echo "$TESTABLE_TEMPLATES" | jq -c --arg templates "$AFFECTED_TEMPLATES" '
[.[] | select(. as $item | ($templates | split("\n") | map(. == $item) | any))]
')
echo "Filtered templates: $FILTERED_TEMPLATES"
echo templates=$(echo $FILTERED_TEMPLATES | sed 's/ //g') | tee --append $GITHUB_OUTPUT
fi
test-npm:
name: Test (npm)
runs-on: ubuntu-latest
needs: [setup-templates]
if: needs.setup-templates.outputs.templates != '[]'
strategy:
fail-fast: false
matrix:
node: [22, 24]
template: ${{ fromJson(needs.setup-templates.outputs.templates) }}
exclude:
# @solana-program/token >=0.14 requires Node >=24
- node: 22
template: kit/nextjs
# Depends on @solana/kit RPC/wallet stack that requires Node >=24
- node: 22
template: kit/nextjs-hardware-signin
- node: 22
template: kit/nextjs-das-nfts
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create and Build using create-solana-dapp
uses: ./.github/actions/create-solana-dapp
with:
cmd: 'npx -y create-solana-dapp@latest'
node-version: ${{ matrix.node }}
package-manager: 'npm'
template: ${{ matrix.template }}
test-pnpm:
name: Test (pnpm)
runs-on: ubuntu-latest
needs: [setup-templates]
if: needs.setup-templates.outputs.templates != '[]'
strategy:
fail-fast: false
matrix:
node: [22, 24]
template: ${{ fromJson(needs.setup-templates.outputs.templates) }}
exclude:
# @solana-program/token >=0.14 requires Node >=24
- node: 22
template: kit/nextjs
# Depends on @solana/kit RPC/wallet stack that requires Node >=24
- node: 22
template: kit/nextjs-hardware-signin
- node: 22
template: kit/nextjs-das-nfts
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create and Build using create-solana-dapp
uses: ./.github/actions/create-solana-dapp
with:
cmd: 'pnpm create solana-dapp@latest'
node-version: ${{ matrix.node }}
package-manager: 'pnpm'
template: ${{ matrix.template }}
test-yarn:
name: Test (yarn)
runs-on: ubuntu-latest
needs: [setup-templates]
if: needs.setup-templates.outputs.templates != '[]'
strategy:
fail-fast: false
matrix:
node: [22, 24]
template: ${{ fromJson(needs.setup-templates.outputs.templates) }}
exclude:
# @solana-program/token >=0.14 requires Node >=24
- node: 22
template: kit/nextjs
# Depends on @solana/kit RPC/wallet stack that requires Node >=24
- node: 22
template: kit/nextjs-hardware-signin
- node: 22
template: kit/nextjs-das-nfts
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create and Build using create-solana-dapp
uses: ./.github/actions/create-solana-dapp
with:
cmd: 'yarn create solana-dapp'
node-version: ${{ matrix.node }}
package-manager: 'yarn'
template: ${{ matrix.template }}