Skip to content

Commit a3b87a4

Browse files
authored
update: tokens native, formatter, trigger action on project changes (#81)
1 parent bd62ad7 commit a3b87a4

File tree

697 files changed

+33935
-10195
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

697 files changed

+33935
-10195
lines changed

.github/.ghaignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# build and test error
2+
basics/realloc/native
3+
basics/cross-program-invocation/native
4+
5+
# uses generated client from shank, can't rewrite to solana-bankrun
6+
tools/shank-and-solita/native
7+
8+
# can't test on localnet
9+
tokens/pda-mint-authority/native
10+
tokens/nft-minter/native
11+
tokens/transfer-tokens/native
12+
tokens/spl-token-minter/native
13+
tokens/create-token/native
14+
tokens/create-token/anchor
15+
tokens/nft-minter/anchor
16+
tokens/pda-mint-authority/anchor
17+
tokens/spl-token-minter/anchor
18+
tokens/token-swap/anchor
19+
tokens/transfer-tokens/anchor
20+
21+
# not building with stable solana
22+
tokens/token-2022/mint-close-authority/native
23+
tokens/token-2022/non-transferable/native
24+
tokens/token-2022/default-account-state/native
25+
tokens/token-2022/transfer-fee/native
26+
tokens/token-2022/multiple-extensions/native
27+
28+
# not building
29+
oracles/pyth/anchor
30+
31+
# not building
32+
compression/cutils/anchor
33+
compression/cnft-vault/anchor
34+
# builds but need to test on localhost
35+
compression/cnft-burn/anchor
36+
tokens/token-2022/nft-meta-data-pointer/anchor-example/anchor

.github/CONTRIBUTING.md

+13-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ When contributing code examples, please follow these guidelines to ensure progra
1717

1818
1. Use pnpm as the default package manager for the project. You can install pnpm by following the instructions [here](https://pnpm.io/installation). Commit pnpm-lock.yaml to the repository.
1919

20-
2. Tests for Solana native and Anchor programs should be written with [ts-mocha](https://github.com/piotrwitek/ts-mocha).
20+
2. Programs written for Solana Native should be in directory `native` and Anchor programs should be in directory `anchor`.
2121

22-
3. Tests for solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun)
22+
3. Tests for Solana native and Anchor programs should be written with [ts-mocha](https://github.com/piotrwitek/ts-mocha).
2323

24-
4. here are some helpful scripts to add to your `package.json` file:
24+
4. Tests for solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun)
25+
26+
5. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json`. file for successful ci/cd builds:
2527

2628
```json
2729
"scripts": {
@@ -32,7 +34,14 @@ When contributing code examples, please follow these guidelines to ensure progra
3234
},
3335
```
3436

35-
5. Test command for anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
37+
6. Test command for anchor should execute `pnpm test` instead of `yarn run test` for anchor programs. Replace `yarn` with `pnpm` in `[script]` table inside [Anchor.toml file.](https://www.anchor-lang.com/docs/manifest#scripts-required-for-testing)
38+
39+
7. TypeScript, JavaScript and JSON files are formatted and linted using
40+
[Biome](https://biomejs.dev/). Execute the following command to format and lint your code at the root of this project before submitting a pull request:
41+
42+
```bash
43+
pnpm check:fix
44+
```
3645

3746
## Code of Conduct
3847
We are committed to providing a friendly, safe, and welcoming environment for all contributors, regardless of their background, experience level, or personal characteristics. As a contributor, you are expected to:

.github/workflows/anchor.yml

+125-78
Original file line numberDiff line numberDiff line change
@@ -14,64 +14,92 @@ on:
1414
jobs:
1515
build:
1616
runs-on: ubuntu-latest
17+
permissions:
18+
pull-requests: read
1719
strategy:
1820
matrix:
1921
node-version: [20.x]
2022
solana-version: [1.18.8, beta]
2123
anchor-version: [0.30.0]
2224
steps:
2325
- uses: actions/checkout@v4
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v4
26-
with:
27-
node-version: ${{ matrix.node-version }}
28-
check-latest: true
29-
- uses: heyAyushh/[email protected]
26+
- name: Setup Anchor
27+
uses: heyAyushh/[email protected]
3028
with:
29+
anchor-version: ${{ matrix.anchor-version }}
3130
solana-cli-version: ${{ matrix.solana-version }}
32-
- run: solana block
33-
shell: bash
34-
- name: Install Anchor
31+
node-version: ${{ matrix.node-version }}
32+
- name: Display versions
3533
run: |
3634
solana -V
35+
solana-keygen new --no-bip39-passphrase
3736
rustc -V
38-
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
39-
avm install ${{ matrix.anchor-version }}
40-
avm use ${{ matrix.anchor-version }}
41-
npm install --global pnpm
42-
- name: Build Anchor programs
37+
anchor -V
38+
npm i -g pnpm
39+
# Run only if it's triggered by PR to main,
40+
# Build the changed programs
41+
- uses: dorny/paths-filter@v3
42+
if: github.event_name == 'pull_request'
43+
id: changes
44+
with:
45+
list-files: shell
46+
filters: |
47+
anchor:
48+
- added|modified: '**/anchor/**'
49+
- name: Build Changed Anchor programs
50+
if: ${{ steps.changes.outputs.anchor == 'true' }}
51+
run: |
52+
changed_files=(${{ steps.changes.outputs.anchor_files }})
53+
54+
# Read ignored projects from .github/.ghaignore, ignoring empty lines and comments
55+
ignored_projects=($(grep . .github/.ghaignore | grep -v '^$'))
56+
57+
# Find anchor projects and remove ignored projects
58+
ProjectDirs=($(for file in "${changed_files[@]}"; do
59+
anchor_path=$(dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g')
60+
if [[ ! " ${ignored_projects[*]} " =~ " ${anchor_path} " ]]; then
61+
echo "$anchor_path"
62+
fi
63+
done | sort -u))
64+
65+
# Build anchor projects
66+
echo "Projects to Build:"
67+
printf "%s\n" "${ProjectDirs[@]}"
68+
for projectDir in "${ProjectDirs[@]}"; do
69+
echo "
70+
********
71+
Building $projectDir
72+
********"
73+
cd $projectDir
74+
if anchor build; then
75+
echo "Build succeeded for $projectDir."
76+
rm -rf target
77+
else
78+
failed=true
79+
failed_builds+=($projectDir)
80+
echo "Build failed for $projectDir. Continuing with the next program."
81+
fi
82+
cd - > /dev/null
83+
done
84+
if [ "$failed" = true ]; then
85+
echo "Programs that failed building:"
86+
printf "%s\n" "${failed_builds[@]}"
87+
exit 1
88+
else
89+
echo "All programs built successfully."
90+
fi
91+
shell: bash
92+
# Skip Building all Programs if it's a PR to main branch
93+
- name: Build All Anchor programs
94+
if: github.event_name != 'pull_request'
4395
run: |
44-
declare -a ProjectDirs=(
45-
"basics/account-data/anchor"
46-
"basics/checking-accounts/anchor"
47-
"basics/close-account/anchor"
48-
"basics/counter/anchor"
49-
"basics/create-account/anchor"
50-
"basics/hello-solana/anchor"
51-
"basics/pda-rent-payer/anchor"
52-
"basics/processing-instructions/anchor"
53-
"basics/program-derived-addresses/anchor"
54-
"basics/realloc/anchor"
55-
"basics/rent/anchor"
56-
"basics/repository-layout/anchor"
57-
"basics/transfer-sol/anchor"
58-
"tokens/token-2022/basics/anchor"
59-
"tokens/token-2022/cpi-guard/anchor"
60-
"tokens/token-2022/default-account-state/anchor"
61-
"tokens/token-2022/group/anchor"
62-
"tokens/token-2022/immutable-owner/anchor"
63-
"tokens/token-2022/interest-bearing/anchor"
64-
"tokens/token-2022/memo-transfer/anchor"
65-
"tokens/token-2022/metadata/anchor"
66-
"tokens/token-2022/mint-close-authority/anchor"
67-
"tokens/token-2022/non-transferable/anchor"
68-
"tokens/token-2022/permanent-delegate/anchor"
69-
"tokens/token-2022/transfer-fee/anchor"
70-
"tokens/token-2022/transfer-hook/anchor/TransferHookCounter"
71-
"tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld"
72-
"tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost"
73-
"tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist"
74-
)
96+
# Find all anchor projects and remove ignored projects
97+
declare -a ProjectDirs=($(find . -type d -name 'anchor' | sed 's|^\./||'| grep -v -f <(grep . .github/.ghaignore | grep -v '^$')))
98+
99+
echo "Projects to Build:"
100+
printf "%s\n" "${ProjectDirs[@]}"
101+
102+
# Build anchor projects
75103
for projectDir in "${ProjectDirs[@]}"; do
76104
echo "
77105
********
@@ -99,6 +127,8 @@ jobs:
99127

100128
test:
101129
runs-on: ubuntu-latest
130+
permissions:
131+
pull-requests: read
102132
strategy:
103133
matrix:
104134
node-version: [20.x]
@@ -107,7 +137,7 @@ jobs:
107137
steps:
108138
- uses: actions/checkout@v4
109139
- name: Setup Anchor
110-
uses: heyAyushh/setup-anchor@v2.2
140+
uses: heyAyushh/setup-anchor@v3.10
111141
with:
112142
anchor-version: ${{ matrix.anchor-version }}
113143
solana-cli-version: ${{ matrix.solana-version }}
@@ -119,39 +149,56 @@ jobs:
119149
rustc -V
120150
anchor -V
121151
npm i -g pnpm
122-
- name: Test anchor programs
152+
# Run only if it's triggered by PR to main,
153+
# Test the changed programs (if any)
154+
- uses: dorny/paths-filter@v3
155+
if: github.event_name == 'pull_request'
156+
id: changes
157+
with:
158+
list-files: shell
159+
filters: |
160+
anchor:
161+
- added|modified: '**/anchor/**'
162+
- name: Test Changed Anchor Programs
163+
if: ${{ steps.changes.outputs.anchor == 'true' }}
164+
run: |
165+
changed_files=(${{ steps.changes.outputs.anchor_files }})
166+
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))
167+
echo "Projects to Test:"
168+
printf "%s\n" "${ProjectDirs[@]}"
169+
for projectDir in "${ProjectDirs[@]}"; do
170+
echo "
171+
********
172+
Testing $projectDir
173+
********"
174+
cd $projectDir
175+
pnpm install --frozen-lockfile
176+
if anchor test; then
177+
echo "Tests succeeded for $projectDir."
178+
rm -rf target node_modules
179+
else
180+
failed=true
181+
failed_tests+=($projectDir)
182+
echo "Tests failed for $val. Continuing with the next program."
183+
fi
184+
cd - > /dev/null
185+
done
186+
if [ "$failed" = true ]; then
187+
echo "*****************************"
188+
echo "Programs that failed testing:"
189+
printf "%s\n" "${failed_tests[@]}"
190+
exit 1
191+
else
192+
echo "All tests passed."
193+
fi
194+
shell: bash
195+
# Skip Testing all Programs if it's a PR to main branch
196+
- name: Test All Anchor Programs
197+
if: github.event_name != 'pull_request'
123198
run: |
124-
declare -a ProjectDirs=(
125-
"basics/account-data/anchor"
126-
"basics/checking-accounts/anchor"
127-
"basics/close-account/anchor"
128-
"basics/counter/anchor"
129-
"basics/create-account/anchor"
130-
"basics/hello-solana/anchor"
131-
"basics/pda-rent-payer/anchor"
132-
"basics/processing-instructions/anchor"
133-
"basics/program-derived-addresses/anchor"
134-
"basics/realloc/anchor"
135-
"basics/rent/anchor"
136-
"basics/repository-layout/anchor"
137-
"basics/transfer-sol/anchor"
138-
"tokens/token-2022/basics/anchor"
139-
"tokens/token-2022/cpi-guard/anchor"
140-
"tokens/token-2022/default-account-state/anchor"
141-
"tokens/token-2022/group/anchor"
142-
"tokens/token-2022/immutable-owner/anchor"
143-
"tokens/token-2022/interest-bearing/anchor"
144-
"tokens/token-2022/memo-transfer/anchor"
145-
"tokens/token-2022/metadata/anchor"
146-
"tokens/token-2022/mint-close-authority/anchor"
147-
"tokens/token-2022/non-transferable/anchor"
148-
"tokens/token-2022/permanent-delegate/anchor"
149-
"tokens/token-2022/transfer-fee/anchor"
150-
"tokens/token-2022/transfer-hook/anchor/TransferHookCounter"
151-
"tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld"
152-
"tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost"
153-
"tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist"
154-
)
199+
declare -a ProjectDirs=($(find . -type d -name "anchor"| grep -v -f <(grep . .github/.ghaignore | grep -v '^$')))
200+
echo "Projects to Test:"
201+
printf "%s\n" "${ProjectDirs[@]}"
155202
for projectDir in "${ProjectDirs[@]}"; do
156203
echo "
157204
********

.github/workflows/biome.yml

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Typescript Code quality
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [ opened, synchronize, reopened ]
9+
branches:
10+
- main
11+
jobs:
12+
quality:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
- name: Setup Biome
18+
uses: biomejs/setup-biome@v2
19+
- name: Run Biome
20+
run: |
21+
biome ci ./ --config-path biome.json

.github/workflows/rust.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ jobs:
2929
# The uses keyword specifies that this step will run v3 of the actions/checkout action.
3030
# This is an action that checks out your repository onto the runner, allowing you to run scripts or other actions against your code (such as build and test tools).
3131
# You should use the checkout action any time your workflow will run against the repository's code.
32-
uses: actions/checkout@v3
32+
uses: actions/checkout@v4
3333

3434
# This GitHub Action installs a Rust toolchain using rustup. It is designed for one-line concise usage and good defaults.
3535
- name: Install the Rust toolchain
@@ -43,7 +43,7 @@ jobs:
4343
name: Rustfmt
4444
runs-on: ubuntu-latest
4545
steps:
46-
- uses: actions/checkout@v3
46+
- uses: actions/checkout@v4
4747
- uses: dtolnay/rust-toolchain@stable
4848
with:
4949
# Specific to dtolnay/rust-toolchain: Comma-separated string of additional components to install
@@ -56,7 +56,7 @@ jobs:
5656
name: Clippy
5757
runs-on: ubuntu-latest
5858
steps:
59-
- uses: actions/checkout@v3
59+
- uses: actions/checkout@v4
6060
- uses: dtolnay/rust-toolchain@stable
6161
with:
6262
components: clippy

0 commit comments

Comments
 (0)