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

ci: Add downstream build for anchor #34343

Merged
merged 2 commits into from
Dec 7, 2023
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions .github/workflows/downstream-project-anchor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Downstream Project - Anchor

on:
push:
branches:
- master
- v[0-9]+.[0-9]+
pull_request:
branches:
- master
- v[0-9]+.[0-9]+
paths:
- "**.rs"
- "Cargo.toml"
- "Cargo.lock"
- "cargo-build-bpf"
- "cargo-test-bpf"
- "cargo-build-sbf"
- "cargo-test-sbf"
- ".github/workflows/downstream-project-anchor.yml"
workflow_call:
inputs:
branch:
required: false
type: string
default: "master"

env:
SHELL: /bin/bash
SCCACHE_GHA_ENABLED: "true"
RUSTC_WRAPPER: "sccache"

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
version: ["v0.29.0"]
steps:
- uses: actions/checkout@v3

- shell: bash
run: |
.github/scripts/purge-ubuntu-runner.sh

- uses: mozilla-actions/sccache-action@v0.0.3
with:
version: "v0.5.4"

- shell: bash
run: |
source .github/scripts/downstream-project-spl-install-deps.sh
./scripts/build-downstream-anchor-projects.sh ${{ matrix.version }}
36 changes: 21 additions & 15 deletions scripts/build-downstream-anchor-projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ source ci/_
source scripts/patch-crates.sh
source scripts/read-cargo-variable.sh

anchor_version=$1
solana_ver=$(readCargoVariable version Cargo.toml)
solana_dir=$PWD
cargo="$solana_dir"/cargo
cargo_build_sbf="$solana_dir"/cargo-build-sbf
cargo_test_sbf="$solana_dir"/cargo-test-sbf

Expand Down Expand Up @@ -43,15 +45,20 @@ anchor() {
set -x
rm -rf anchor
git clone https://github.com/coral-xyz/anchor.git
cd anchor || exit 1

# checkout tag
if [[ -n "$anchor_version" ]]; then
git checkout "$anchor_version"
fi

# copy toolchain file to use solana's rust version
cp "$solana_dir"/rust-toolchain.toml anchor/
cd anchor
cp "$solana_dir"/rust-toolchain.toml .

update_solana_dependencies . "$solana_ver"
patch_crates_io_solana Cargo.toml "$solana_dir"

cargo build
cargo test
$cargo test

anchor_dir=$PWD
anchor_ver=$(readCargoVariable version "$anchor_dir"/lang/Cargo.toml)
Expand All @@ -73,8 +80,9 @@ mango() {
patch_crates_io_solana Cargo.toml "$solana_dir"
patch_crates_io_anchor Cargo.toml "$anchor_dir"

cargo build
cargo test
cd program
$cargo build
$cargo test
$cargo_build_sbf
$cargo_test_sbf
)
Expand All @@ -83,19 +91,17 @@ mango() {
metaplex() {
(
set -x
rm -rf metaplex-program-library
git clone https://github.com/metaplex-foundation/metaplex-program-library
# copy toolchain file to use solana's rust version
cp "$solana_dir"/rust-toolchain.toml metaplex-program-library/
cd metaplex-program-library
rm -rf mpl-token-metadata
git clone https://github.com/metaplex-foundation/mpl-token-metadata
# copy toolchain file to use solana's rust version
cp "$solana_dir"/rust-toolchain.toml mpl-token-metadata/
cd mpl-token-metadata/programs/token-metadata/program

update_solana_dependencies . "$solana_ver"
update_anchor_dependencies . "$anchor_ver"
patch_crates_io_solana Cargo.toml "$solana_dir"
patch_crates_io_anchor Cargo.toml "$anchor_dir"

cargo build
cargo test
$cargo build
$cargo test
$cargo_build_sbf
$cargo_test_sbf
)
Expand Down
5 changes: 5 additions & 0 deletions scripts/patch-crates.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@ update_solana_dependencies() {
while IFS='' read -r line; do tomls+=("$line"); done < <(find "$project_root" -name Cargo.toml)

sed -i -e "s#\(solana-program = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-program = { version = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-program-test = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-program-test = { version = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-sdk = \"\).*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-sdk = { version = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-client = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-client = { version = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-cli-config = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-cli-config = { version = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-clap-utils = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-clap-utils = { version = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
sed -i -e "s#\(solana-account-decoder = \"\)[^\"]*\(\"\)#\1=$solana_ver\2#g" "${tomls[@]}" || return $?
Expand All @@ -30,6 +34,7 @@ patch_crates_io_solana() {
solana-account-decoder = { path = "$solana_dir/account-decoder" }
solana-clap-utils = { path = "$solana_dir/clap-utils" }
solana-client = { path = "$solana_dir/client" }
solana-cli-config = { path = "$solana_dir/cli-config" }
solana-program = { path = "$solana_dir/sdk/program" }
solana-program-test = { path = "$solana_dir/program-test" }
solana-sdk = { path = "$solana_dir/sdk" }
Expand Down