Skip to content

Commit

Permalink
Merge branch 'main' into anchor-update
Browse files Browse the repository at this point in the history
  • Loading branch information
ZYJLiu committed May 7, 2024
2 parents 39a2518 + a70c93b commit b4618e8
Show file tree
Hide file tree
Showing 100 changed files with 32,130 additions and 2,826 deletions.
44 changes: 44 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Contribution Guidelines
Thank you for considering contributing to the Solana Program Examples repository. We greatly appreciate your interest and efforts in helping us improve and expand this valuable resource for the Solana developer community.

We believe that a welcoming and inclusive environment fosters collaboration and encourages participation from developers of all backgrounds and skill levels.

To ensure a smooth and effective contribution process, please take a moment to review and follow the guidelines outlined below.

## How to Contribute
We welcome contributions in the form of code, documentation, bug reports, feature requests, and other forms of feedback. Here are some ways you can contribute:

- **Code Contributions:** You can contribute code examples in Rust, Python, or Solidity that demonstrate various Solana program functionalities. You can also contribute improvements to existing examples, such as bug fixes, optimizations, or additional features.

- **Bug Reports, Ideas or Feedback:** If you encounter any issues or have ideas for new examples, please submit a bug report or feature request. Your feedback is valuable and helps us improve the quality and relevance of the examples.

## Contributing code examples:
When contributing code examples, please follow these guidelines to ensure programs build and test successfully:

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.

2. Tests for Solana native and Anchor programs should be written with [ts-mocha](https://github.com/piotrwitek/ts-mocha).

3. Tests for solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun)

4. here are some helpful scripts to add to your `package.json` file:

```json
"scripts": {
"test": "pnpm ts-mocha -p ./tests/tsconfig.test.json -t 1000000 ./tests/realloc.test.ts",
"build-and-test": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./tests/fixtures && pnpm test",
"build": "cargo build-sbf --manifest-path=./program/Cargo.toml --sbf-out-dir=./program/target/so",
"deploy": "solana program deploy ./program/target/so/program.so"
},
```

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)

## Code of Conduct
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:

Be respectful and inclusive in your interactions with others.
Refrain from engaging in any form of harassment, discrimination, or offensive behavior. Be open to constructive feedback and be willing to learn from others.
Help create a positive and supportive community where everyone feels valued and respected.

If you encounter any behavior that violates our code of conduct, please report it to the project maintainers immediately.
169 changes: 131 additions & 38 deletions .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
@@ -1,53 +1,146 @@
name: Anchor Build
name: Anchor

on:
schedule:
- cron: '0 0 1 * *'
- cron: '0 0 * * *'
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]
solana-version: [stable, 1.17.25]
anchor-version: [0.29.0]
steps:
- uses: actions/checkout@v2

- name: Install dependencies
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
check-latest: true
- uses: heyAyushh/[email protected]
with:
solana-cli-version: ${{ matrix.solana-version }}
- run: solana block
shell: bash
- name: Install Anchor
run: |
sh -c "$(curl -sSfL https://release.solana.com/stable/install)"
export PATH="/home/runner/.local/share/solana/install/active_release/bin:$PATH"
solana -V
rustc -V
sudo apt-get update && sudo apt-get upgrade && sudo apt-get install -y pkg-config build-essential libudev-dev libssl-dev
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install latest
avm use latest
declare -a StringArray=(
"basics/checking-accounts/anchor"
"basics/close-account/anchor"
"basics/counter/anchor"
"basics/create-account/anchor"
"basics/hello-solana/anchor"
"basics/pda-rent-payer/anchor"
"basics/processing-instructions/anchor"
"basics/program-derived-addresses/anchor"
"basics/realloc/anchor"
"basics/rent/anchor"
"basics/repository-layout/anchor"
"basics/transfer-sol/anchor"
"compression/cnft-vault/anchor"
"oracles/pyth/anchor"
"tokens/create-token/anchor"
"tokens/nft-minter/anchor"
"tokens/pda-mint-authority/anchor"
"tokens/spl-token-minter/anchor"
"tokens/token-2022/basics/anchor"
"tokens/transfer-tokens/anchor"
"basics/account-data/anchor"
avm install ${{ matrix.anchor-version }}
avm use ${{ matrix.anchor-version }}
npm install --global pnpm
- name: Build Anchor programs
run: |
declare -a ProjectDirs=(
"basics/account-data/anchor"
"basics/checking-accounts/anchor"
"basics/close-account/anchor"
"basics/counter/anchor"
"basics/create-account/anchor"
"basics/hello-solana/anchor"
"basics/pda-rent-payer/anchor"
"basics/processing-instructions/anchor"
"basics/program-derived-addresses/anchor"
"basics/realloc/anchor"
"basics/rent/anchor"
"basics/repository-layout/anchor"
"basics/transfer-sol/anchor"
)
for projectDir in "${ProjectDirs[@]}"; do
echo "
********
Building $projectDir
********"
cd $projectDir
if anchor build; then
echo "Build succeeded for $projectDir."
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
strategy:
matrix:
node-version: [20.x]
solana-version: [1.18.4, stable]
anchor-version: [0.29.0]
steps:
- uses: actions/checkout@v4
- name: Setup Anchor
uses: heyAyushh/[email protected]
with:
anchor-version: ${{ matrix.anchor-version }}
solana-cli-version: ${{ matrix.solana-version }}
node-version: ${{ matrix.node-version }}
- name: Display versions
run: |
solana -V
solana-keygen new --no-bip39-passphrase
rustc -V
anchor -V
npm i -g pnpm
- name: Test anchor programs
run: |
declare -a ProjectDirs=(
"basics/account-data/anchor"
"basics/checking-accounts/anchor"
"basics/close-account/anchor"
"basics/counter/anchor"
"basics/create-account/anchor"
"basics/hello-solana/anchor"
"basics/pda-rent-payer/anchor"
"basics/processing-instructions/anchor"
"basics/program-derived-addresses/anchor"
"basics/realloc/anchor"
"basics/rent/anchor"
"basics/repository-layout/anchor"
"basics/transfer-sol/anchor"
)
for val in "${StringArray[@]}"; do
echo "Building $val..."
cd $val
anchor build
cd - > /dev/null
for projectDir in "${ProjectDirs[@]}"; do
echo "
********
Testing $projectDir
********"
cd $projectDir
pnpm install --frozen-lockfile
if anchor test; then
echo "Tests succeeded for $projectDir."
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
52 changes: 0 additions & 52 deletions .github/workflows/native.yml

This file was deleted.

Loading

0 comments on commit b4618e8

Please sign in to comment.