Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tokens native, formatter, trigger action on project changes #81

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
36 changes: 36 additions & 0 deletions .github/.ghaignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# build and test error
basics/realloc/native
basics/cross-program-invocation/native

# uses generated client from shank, can't rewrite to solana-bankrun
tools/shank-and-solita/native

# can't test on localnet
tokens/pda-mint-authority/native
tokens/nft-minter/native
tokens/transfer-tokens/native
tokens/spl-token-minter/native
tokens/create-token/native
tokens/create-token/anchor
tokens/nft-minter/anchor
tokens/pda-mint-authority/anchor
tokens/spl-token-minter/anchor
tokens/token-swap/anchor
tokens/transfer-tokens/anchor

# not building with stable solana
tokens/token-2022/mint-close-authority/native
tokens/token-2022/non-transferable/native
tokens/token-2022/default-account-state/native
tokens/token-2022/transfer-fee/native
tokens/token-2022/multiple-extensions/native

# not building
oracles/pyth/anchor

# not building
compression/cutils/anchor
compression/cnft-vault/anchor
# builds but need to test on localhost
compression/cnft-burn/anchor
tokens/token-2022/nft-meta-data-pointer/anchor-example/anchor
17 changes: 13 additions & 4 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ When contributing code examples, please follow these guidelines to ensure progra

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).
2. Programs written for Solana Native should be in directory `native` and Anchor programs should be in directory `anchor`.

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

4. here are some helpful scripts to add to your `package.json` file:
4. Tests for solana native programs should be written with [solana-bankrun](https://kevinheavey.github.io/solana-bankrun)

5. For Solana native programs ensure adding these mandatory pnpm run scripts to your `package.json`. file for successful ci/cd builds:

```json
"scripts": {
Expand All @@ -32,7 +34,14 @@ When contributing code examples, please follow these guidelines to ensure progra
},
```

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)
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)

7. TypeScript, JavaScript and JSON files are formatted and linted using
[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:

```bash
pnpm check:fix
```

## 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:
Expand Down
203 changes: 125 additions & 78 deletions .github/workflows/anchor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,64 +14,92 @@ on:
jobs:
build:
runs-on: ubuntu-latest
permissions:
pull-requests: read
strategy:
matrix:
node-version: [20.x]
solana-version: [1.18.8, beta]
anchor-version: [0.30.0]
steps:
- 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]
- name: Setup Anchor
uses: heyAyushh/[email protected]
with:
anchor-version: ${{ matrix.anchor-version }}
solana-cli-version: ${{ matrix.solana-version }}
- run: solana block
shell: bash
- name: Install Anchor
node-version: ${{ matrix.node-version }}
- name: Display versions
run: |
solana -V
solana-keygen new --no-bip39-passphrase
rustc -V
cargo install --git https://github.com/coral-xyz/anchor avm --locked --force
avm install ${{ matrix.anchor-version }}
avm use ${{ matrix.anchor-version }}
npm install --global pnpm
- name: Build Anchor programs
anchor -V
npm i -g pnpm
# Run only if it's triggered by PR to main,
# Build the changed programs
- uses: dorny/paths-filter@v3
if: github.event_name == 'pull_request'
id: changes
with:
list-files: shell
filters: |
anchor:
- added|modified: '**/anchor/**'
- name: Build Changed Anchor programs
if: ${{ steps.changes.outputs.anchor == '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 != 'pull_request'
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"
"tokens/token-2022/basics/anchor"
"tokens/token-2022/cpi-guard/anchor"
"tokens/token-2022/default-account-state/anchor"
"tokens/token-2022/group/anchor"
"tokens/token-2022/immutable-owner/anchor"
"tokens/token-2022/interest-bearing/anchor"
"tokens/token-2022/memo-transfer/anchor"
"tokens/token-2022/metadata/anchor"
"tokens/token-2022/mint-close-authority/anchor"
"tokens/token-2022/non-transferable/anchor"
"tokens/token-2022/permanent-delegate/anchor"
"tokens/token-2022/transfer-fee/anchor"
"tokens/token-2022/transfer-hook/anchor/TransferHookCounter"
"tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld"
"tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost"
"tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist"
)
# 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 "
********
Expand Down Expand Up @@ -99,6 +127,8 @@ jobs:

test:
runs-on: ubuntu-latest
permissions:
pull-requests: read
strategy:
matrix:
node-version: [20.x]
Expand All @@ -107,7 +137,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Setup Anchor
uses: heyAyushh/setup-anchor@v2.2
uses: heyAyushh/setup-anchor@v3.10
with:
anchor-version: ${{ matrix.anchor-version }}
solana-cli-version: ${{ matrix.solana-version }}
Expand All @@ -119,39 +149,56 @@ jobs:
rustc -V
anchor -V
npm i -g pnpm
- name: Test anchor programs
# Run only if it's triggered by PR to main,
# Test the changed programs (if any)
- uses: dorny/paths-filter@v3
if: github.event_name == 'pull_request'
id: changes
with:
list-files: shell
filters: |
anchor:
- added|modified: '**/anchor/**'
- name: Test Changed Anchor Programs
if: ${{ steps.changes.outputs.anchor == '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
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
# Skip Testing all Programs if it's a PR to main branch
- name: Test All Anchor Programs
if: github.event_name != 'pull_request'
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"
"tokens/token-2022/basics/anchor"
"tokens/token-2022/cpi-guard/anchor"
"tokens/token-2022/default-account-state/anchor"
"tokens/token-2022/group/anchor"
"tokens/token-2022/immutable-owner/anchor"
"tokens/token-2022/interest-bearing/anchor"
"tokens/token-2022/memo-transfer/anchor"
"tokens/token-2022/metadata/anchor"
"tokens/token-2022/mint-close-authority/anchor"
"tokens/token-2022/non-transferable/anchor"
"tokens/token-2022/permanent-delegate/anchor"
"tokens/token-2022/transfer-fee/anchor"
"tokens/token-2022/transfer-hook/anchor/TransferHookCounter"
"tokens/token-2022/transfer-hook/anchor/TransferHookHelloWorld"
"tokens/token-2022/transfer-hook/anchor/TransferHookTransferCost"
"tokens/token-2022/transfer-hook/anchor/TransferHookWhitelist"
)
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 "
********
Expand Down
21 changes: 21 additions & 0 deletions .github/workflows/biome.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Typescript Code quality

on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]
branches:
- main
jobs:
quality:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Biome
uses: biomejs/setup-biome@v2
- name: Run Biome
run: |
biome ci ./ --config-path biome.json
6 changes: 3 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# The uses keyword specifies that this step will run v3 of the actions/checkout action.
# 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).
# You should use the checkout action any time your workflow will run against the repository's code.
uses: actions/checkout@v3
uses: actions/checkout@v4

# This GitHub Action installs a Rust toolchain using rustup. It is designed for one-line concise usage and good defaults.
- name: Install the Rust toolchain
Expand All @@ -43,7 +43,7 @@ jobs:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
# Specific to dtolnay/rust-toolchain: Comma-separated string of additional components to install
Expand All @@ -56,7 +56,7 @@ jobs:
name: Clippy
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
Expand Down
Loading