-
Notifications
You must be signed in to change notification settings - Fork 307
234 lines (225 loc) · 8.62 KB
/
anchor.yml
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
name: Anchor
on:
schedule:
- cron: "0 0 * * *"
push:
branches:
- main
pull_request:
types: [opened, synchronize, reopened]
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
permissions:
pull-requests: read
strategy:
matrix:
node-version: [20.x]
solana-version: [1.18.17, stable]
anchor-version: [0.30.1]
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
if: github.event_name == 'pull_request'
id: changes
with:
list-files: shell
filters: |
anchor:
- added|modified: '**/anchor/**'
anchor_action:
- added|modified: '**/workflows/anchor.yml'
- name: Setup Anchor
if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule' || github.event_name == 'push'
uses: heyAyushh/[email protected]
with:
anchor-version: ${{ matrix.anchor-version }}
solana-cli-version: ${{ matrix.solana-version }}
node-version: ${{ matrix.node-version }}
- name: Display versions and Install pnpm
if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule'
run: |
solana -V
solana-keygen new --no-bip39-passphrase
rustc -V
anchor -V
npm i -g pnpm
# Run only if it's triggered by PR to main,
# Build the changed programs
- name: Build Changed Anchor programs
if: steps.changes.outputs.anchor == 'true' && steps.changes.outputs.anchor_action != 'true'
run: |
changed_files=(${{ steps.changes.outputs.anchor_files }})
# Read ignored projects from .github/.ghaignore, ignoring empty lines and comments
ignored_projects=($(grep . .github/.ghaignore | grep -v '^$'))
# Find anchor projects and remove ignored projects
ProjectDirs=($(for file in "${changed_files[@]}"; do
anchor_path=$(dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g')
if [[ ! " ${ignored_projects[*]} " =~ " ${anchor_path} " ]]; then
echo "$anchor_path"
fi
done | sort -u))
# Build anchor projects
echo "Projects to Build:"
printf "%s\n" "${ProjectDirs[@]}"
for projectDir in "${ProjectDirs[@]}"; do
echo "
********
Building $projectDir
********"
cd $projectDir
if anchor build; then
echo "Build succeeded for $projectDir."
rm -rf target
else
failed=true
failed_builds+=($projectDir)
echo "Build failed for $projectDir. Continuing with the next program."
fi
cd - > /dev/null
done
if [ "$failed" = true ]; then
echo "Programs that failed building:"
printf "%s\n" "${failed_builds[@]}"
exit 1
else
echo "All programs built successfully."
fi
shell: bash
# Skip Building all Programs if it's a PR to main branch
- name: Build All Anchor programs
if: github.event_name == 'schedule' || github.event_name == 'push' || steps.changes.outputs.anchor_action == 'true'
run: |
# Find all anchor projects and remove ignored projects
declare -a ProjectDirs=($(find . -type d -name 'anchor' | sed 's|^\./||'| grep -v -f <(grep . .github/.ghaignore | grep -v '^$')))
echo "Projects to Build:"
printf "%s\n" "${ProjectDirs[@]}"
# Build anchor projects
for projectDir in "${ProjectDirs[@]}"; do
echo "
********
Building $projectDir
********"
cd $projectDir
if anchor build; then
echo "Build succeeded for $projectDir."
rm -rf target
else
failed=true
failed_builds+=($projectDir)
echo "Build failed for $projectDir. Continuing with the next program."
fi
cd - > /dev/null
done
if [ "$failed" = true ]; then
echo "Programs that failed building:"
printf "%s\n" "${failed_builds[@]}"
exit 1
else
echo "All programs built successfully."
fi
shell: bash
test:
runs-on: ubuntu-latest
permissions:
pull-requests: read
strategy:
matrix:
node-version: [20.x]
solana-version: [1.18.17, stable]
anchor-version: [0.30.1]
steps:
- uses: actions/checkout@v4
- uses: dorny/paths-filter@v3
if: github.event_name == 'pull_request'
id: changes
with:
list-files: shell
filters: |
anchor:
- added|modified: '**/anchor/**'
anchor_action:
- added|modified: '**/workflows/anchor.yml'
# Skip Installing and Displaying versions if theres no change in anchor programs or anchor action workflow file or isn't a schedule event
- name: Setup Anchor
if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule' || github.event_name == 'push'
uses: heyAyushh/[email protected]
with:
anchor-version: ${{ matrix.anchor-version }}
solana-cli-version: ${{ matrix.solana-version }}
node-version: ${{ matrix.node-version }}
- name: Display versions and Install pnpm
if: steps.changes.outputs.anchor == 'true' || steps.changes.outputs.anchor_action == 'true' || github.event_name == 'schedule' || github.event_name == 'push'
run: |
solana -V
solana-keygen new --no-bip39-passphrase
rustc -V
anchor -V
npm i -g pnpm
- name: Test Changed Anchor Programs
if: steps.changes.outputs.anchor == 'true' && steps.changes.outputs.anchor_action != 'true'
run: |
changed_files=(${{ steps.changes.outputs.anchor_files }})
ProjectDirs=($(for file in "${changed_files[@]}"; do dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g'; done | grep -v -f <(grep . .github/.ghaignore | grep -v '^$') | sort -u))
echo "Projects to Test:"
printf "%s\n" "${ProjectDirs[@]}"
for projectDir in "${ProjectDirs[@]}"; do
echo "
********
Testing $projectDir
********"
cd $projectDir
if pnpm install --frozen-lockfile && anchor test; then
echo "Tests succeeded for $projectDir."
rm -rf target node_modules
else
failed=true
failed_tests+=($projectDir)
echo "Tests failed for $val. Continuing with the next program."
fi
cd - > /dev/null
done
if [ "$failed" = true ]; then
echo "*****************************"
echo "Programs that failed testing:"
printf "%s\n" "${failed_tests[@]}"
exit 1
else
echo "All tests passed."
fi
shell: bash
# Skip Testing all Programs if it's a CRON job or a change in the workflow file
- name: Test All Anchor Programs
if: github.event_name == 'schedule' || github.event_name == 'push' || steps.changes.outputs.anchor_action == 'true'
run: |
declare -a ProjectDirs=($(find . -type d -name "anchor"| grep -v -f <(grep . .github/.ghaignore | grep -v '^$')))
echo "Projects to Test:"
printf "%s\n" "${ProjectDirs[@]}"
for projectDir in "${ProjectDirs[@]}"; do
echo "
********
Testing $projectDir
********"
cd $projectDir
pnpm install --frozen-lockfile
if anchor test; then
echo "Tests succeeded for $projectDir."
rm -rf target node_modules
else
failed=true
failed_tests+=($projectDir)
echo "Tests failed for $val. Continuing with the next program."
fi
cd - > /dev/null
done
if [ "$failed" = true ]; then
echo "*****************************"
echo "Programs that failed testing:"
printf "%s\n" "${failed_tests[@]}"
exit 1
else
echo "All tests passed."
fi
shell: bash