refactor(deps): source BN from anchor and drop unused @types/bn.js #2867
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Anchor | |
| on: | |
| schedule: | |
| - cron: '0 0 * * *' | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| types: [opened, synchronize, reopened] | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: ${{ github.event_name == 'pull_request' }} | |
| env: | |
| MAX_JOBS: 64 | |
| MIN_PROJECTS_PER_JOB: 4 | |
| MIN_PROJECTS_FOR_MATRIX: 4 | |
| # See https://github.blog/changelog/2025-09-19-deprecation-of-node-20-on-github-actions-runners/ | |
| FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true | |
| # Harden cargo against transient crates.io index fetch failures that flake | |
| # cargo build-sbf ("failed to get <crate> as a dependency"). | |
| CARGO_NET_RETRY: '10' | |
| CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse | |
| jobs: | |
| changes: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| outputs: | |
| changed_projects: ${{ steps.analyze.outputs.changed_projects }} | |
| total_projects: ${{ steps.analyze.outputs.total_projects }} | |
| matrix: ${{ steps.matrix.outputs.matrix }} | |
| projects_per_job: ${{ steps.matrix.outputs.projects_per_job }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - uses: dorny/paths-filter@7b450fff21473bca461d4b92ce414b9d0420d706 # v4 | |
| id: changes | |
| if: github.event_name == 'pull_request' | |
| with: | |
| list-files: shell | |
| filters: | | |
| anchor: | |
| - added|modified: '**/anchor/**' | |
| workflow: | |
| - added|modified: '.github/workflows/anchor.yml' | |
| - name: Analyze Changes | |
| id: analyze | |
| run: | | |
| # Generate ignore pattern, excluding comments | |
| ignore_pattern=$(grep -v '^#' .github/.ghaignore | grep -v '^$' | tr '\n' '|' | sed 's/|$//') | |
| echo "Ignore pattern: $ignore_pattern" | |
| function get_projects() { | |
| find . -type d -name "anchor" | grep -vE "$ignore_pattern" | sort | |
| } | |
| # Determine which projects to build and test | |
| if [[ "${{ github.event_name }}" == "push" || "${{ github.event_name }}" == "schedule" || "${{ steps.changes.outputs.workflow }}" == "true" ]]; then | |
| projects=$(get_projects) | |
| elif [[ "${{ steps.changes.outputs.anchor }}" == "true" ]]; then | |
| changed_files=(${{ steps.changes.outputs.anchor_files }}) | |
| projects=$(for file in "${changed_files[@]}"; do dirname "${file}" | grep anchor | sed 's#/anchor/.*#/anchor#g'; done | grep -vE "$ignore_pattern" | sort -u) | |
| else | |
| projects="" | |
| fi | |
| # Output project information | |
| if [[ -n "$projects" ]]; then | |
| echo "Projects to build and test" | |
| echo "$projects" | |
| total_projects=$(echo "$projects" | wc -l) | |
| echo "Total projects: $total_projects" | |
| echo "total_projects=$total_projects" >> $GITHUB_OUTPUT | |
| echo "changed_projects=$(echo "$projects" | jq -R -s -c 'split("\n")[:-1]')" >> $GITHUB_OUTPUT | |
| else | |
| echo "No projects to build and test." | |
| echo "total_projects=0" >> $GITHUB_OUTPUT | |
| echo "changed_projects=[]" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Generate matrix | |
| id: matrix | |
| run: | | |
| total_projects=${{ steps.analyze.outputs.total_projects }} | |
| max_jobs=${{ env.MAX_JOBS }} | |
| min_projects_per_job=${{ env.MIN_PROJECTS_PER_JOB }} | |
| min_projects_for_matrix=${{ env.MIN_PROJECTS_FOR_MATRIX }} | |
| # Generate matrix based on number of projects | |
| if [ "$total_projects" -lt "$min_projects_for_matrix" ]; then | |
| echo "matrix=[0]" >> $GITHUB_OUTPUT | |
| echo "projects_per_job=$total_projects" >> $GITHUB_OUTPUT | |
| else | |
| projects_per_job=$(( (total_projects + max_jobs - 1) / max_jobs )) | |
| projects_per_job=$(( projects_per_job > min_projects_per_job ? projects_per_job : min_projects_per_job )) | |
| num_jobs=$(( (total_projects + projects_per_job - 1) / projects_per_job )) | |
| indices=$(seq 0 $(( num_jobs - 1 ))) | |
| echo "matrix=[$(echo $indices | tr ' ' ',')]" >> $GITHUB_OUTPUT | |
| echo "projects_per_job=$projects_per_job" >> $GITHUB_OUTPUT | |
| fi | |
| build-and-test: | |
| needs: changes | |
| if: needs.changes.outputs.total_projects != '0' | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 90 | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| index: ${{ fromJson(needs.changes.outputs.matrix) }} | |
| name: build-and-test-group-${{ matrix.index }} | |
| outputs: | |
| failed_projects: ${{ steps.set-failed.outputs.failed_projects }} | |
| steps: | |
| - uses: actions/checkout@v7 | |
| # Solana 3.1.8 matches the [toolchain] solana_version every anchor | |
| # example pins in Anchor.toml. Installing anything else makes anchor | |
| # build fetch 3.1.8 through agave-install at build time, which fails | |
| # whenever the weekly toolchain cache is cold. | |
| - uses: ./.github/actions/setup | |
| with: | |
| solana-version: '3.1.8' | |
| install-anchor: 'true' | |
| anchor-version: '1.0.2' | |
| - name: Display Versions | |
| run: | | |
| solana -V | |
| # it's okay to use --force in github action since all programs are tested in isolation | |
| solana-keygen new --no-bip39-passphrase --force | |
| rustc -V | |
| anchor -V | |
| - name: Build and Test | |
| env: | |
| TOTAL_PROJECTS: ${{ needs.changes.outputs.total_projects }} | |
| PROJECTS_PER_JOB: ${{ needs.changes.outputs.projects_per_job }} | |
| run: | | |
| function build_and_test() { | |
| local project=$1 | |
| echo "Building and Testing $project" | |
| cd "$project" || return 1 | |
| # Install dependencies first | |
| if ! pnpm install --frozen-lockfile; then | |
| echo "::error::pnpm install failed for $project" | |
| echo "$project: pnpm install failed" >> $GITHUB_WORKSPACE/failed_projects.txt | |
| cd - > /dev/null | |
| return 1 | |
| fi | |
| # Run anchor build | |
| # --ignore-keys: most examples don't commit program keypairs, so CI | |
| # generates ephemeral ones that won't match the source declare_id! | |
| if ! anchor build --ignore-keys; then | |
| echo "::error::anchor build failed for $project" | |
| echo "$project: anchor build failed" >> $GITHUB_WORKSPACE/failed_projects.txt | |
| rm -rf target | |
| cd - > /dev/null | |
| return 1 | |
| fi | |
| # Typecheck (after anchor build so generated target/types exist) | |
| if [ -f tsconfig.json ]; then | |
| if ! pnpm exec tsc --noEmit -p tsconfig.json; then | |
| echo "::error::typecheck failed for $project" | |
| echo "$project: typecheck failed" >> $GITHUB_WORKSPACE/failed_projects.txt | |
| rm -rf target | |
| cd - > /dev/null | |
| return 1 | |
| fi | |
| fi | |
| # Run anchor test. Anchor 1.0.x syncs program ids to the ephemeral | |
| # keypair during its own build, so no separate keys sync is needed — | |
| # re-verify this if anchor-version is bumped. | |
| # --validator legacy: surfpool (the Anchor 1.0 default) isn't installed in CI | |
| if ! anchor test --validator legacy; then | |
| echo "::error::anchor test failed for $project" | |
| echo "$project: anchor test failed" >> $GITHUB_WORKSPACE/failed_projects.txt | |
| rm -rf target node_modules | |
| cd - > /dev/null | |
| return 1 | |
| fi | |
| echo "Build and tests succeeded for $project." | |
| rm -rf target node_modules | |
| cd - > /dev/null | |
| return 0 | |
| } | |
| # Determine which projects to build in this job | |
| readarray -t all_projects < <(echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]?') | |
| start_index=$(( ${{ matrix.index }} * PROJECTS_PER_JOB )) | |
| end_index=$(( start_index + PROJECTS_PER_JOB )) | |
| end_index=$(( end_index > TOTAL_PROJECTS ? TOTAL_PROJECTS : end_index )) | |
| echo "Projects to build and test in this job" | |
| for i in $(seq $start_index $(( end_index - 1 ))); do | |
| echo "${all_projects[$i]}" | |
| done | |
| # Build and test projects | |
| failed=false | |
| failed_projects=() | |
| for i in $(seq $start_index $(( end_index - 1 ))); do | |
| echo "::group::Building and testing ${all_projects[$i]}" | |
| if ! build_and_test "${all_projects[$i]}"; then | |
| failed=true | |
| failed_projects+=("${all_projects[$i]}") | |
| fi | |
| echo "::endgroup::" | |
| done | |
| if [[ "$failed" == "true" ]]; then | |
| echo "::group::Failed projects" | |
| cat $GITHUB_WORKSPACE/failed_projects.txt | |
| echo "::endgroup::" | |
| echo "failed_projects=${failed_projects[@]}" >> $GITHUB_OUTPUT | |
| exit 1 | |
| else | |
| echo "failed_projects=" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Set failed projects output | |
| id: set-failed | |
| if: failure() | |
| run: | | |
| # Prepare failed projects list for output | |
| failed_projects=$(cat $GITHUB_WORKSPACE/failed_projects.txt | jq -R -s -c 'split("\n")[:-1]') | |
| echo "failed_projects=$failed_projects" >> $GITHUB_OUTPUT | |
| summary: | |
| needs: [changes, build-and-test] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - uses: actions/checkout@v7 | |
| - name: Create job summary | |
| run: | | |
| echo "## Anchor Workflow Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "- Total projects: ${{ needs.changes.outputs.total_projects }}" >> $GITHUB_STEP_SUMMARY | |
| # List all processed projects | |
| echo "<details>" >> $GITHUB_STEP_SUMMARY | |
| echo "<summary>Projects processed (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo '${{ needs.changes.outputs.changed_projects }}' | jq -r '.[]' | while read project; do | |
| echo "- $project" >> $GITHUB_STEP_SUMMARY | |
| done | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "</details>" >> $GITHUB_STEP_SUMMARY | |
| # Report build and test results | |
| if [[ "${{ needs.build-and-test.result }}" == "failure" ]]; then | |
| echo "## :x: Build or tests failed" >> $GITHUB_STEP_SUMMARY | |
| echo "<details>" >> $GITHUB_STEP_SUMMARY | |
| echo "<summary>Failed projects (click to expand)</summary>" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| failed_projects='${{ needs.build-and-test.outputs.failed_projects }}' | |
| if [[ -n "$failed_projects" ]]; then | |
| echo "$failed_projects" | jq -r '.[]' | while IFS=: read -r project failure_reason; do | |
| echo "- **$project**" >> $GITHUB_STEP_SUMMARY | |
| echo " - Failure reason: $failure_reason" >> $GITHUB_STEP_SUMMARY | |
| done | |
| else | |
| echo "No failed projects reported. This might indicate an unexpected error in the workflow." >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "</details>" >> $GITHUB_STEP_SUMMARY | |
| elif [[ "${{ needs.build-and-test.result }}" == "success" ]]; then | |
| echo "## :white_check_mark: All builds and tests passed" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "## :warning: Build and test job was skipped or canceled" >> $GITHUB_STEP_SUMMARY | |
| fi |