Skip to content

Commit

Permalink
improve CI contract build times (#876)
Browse files Browse the repository at this point in the history
* test: improve CI contract build times

* improve rust.yml runtime

* cache hello-world target

* use larger runners

* clone contracts from build context instead of pull
  • Loading branch information
aalu1418 authored Oct 2, 2024
1 parent af30344 commit 3ff8c1b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 50 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/relay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ on:
jobs:
relay_run_unit_tests:
name: Relay Run Unit Tests
runs-on: ubuntu-latest
runs-on: ubuntu-latest-8cores-32GB
steps:
- name: Collect Metrics
id: collect-gha-metrics
Expand Down
95 changes: 46 additions & 49 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,52 @@ jobs:
id: psversion
uses: ./.github/actions/projectserum_version

rust_run_anchor_tests:
name: Rust Run Anchor Tests
build_wrapped_anchor_image:
name: build contract test image
runs-on: ubuntu-latest
needs: [get_projectserum_version]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Cache cargo registry
- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-v2-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-v2-cargo-index-${{ hashFiles('**/Cargo.lock') }}
path: contracts/docker-build.tar
key: ${{ runner.os }}-docker-build-${{ needs.get_projectserum_version.outputs.projectserum_version }}-${{ hashFiles('**/Cargo.lock') }}'
- name: build & save image
if: steps.cache-image.outputs.cache-hit != 'true'
run: |
docker buildx build . -t chainlink-solana:build --build-arg ANCHOR_CLI=${{ needs.get_projectserum_version.outputs.projectserum_version }}
docker save chainlink-solana > docker-build.tar
rust_run_anchor_tests:
name: Rust Run Anchor Tests
runs-on: ubuntu-latest-8cores-32GB
needs: [get_projectserum_version, build_wrapped_anchor_image]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Cache cargo target dir
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: contracts/target
key: ${{ runner.os }}-v2-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: Cache hello-world target dir
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: contracts/examples/hello-world/target
key: ${{ runner.os }}-v2-cargo-build-target-hello-world-${{ hashFiles('**/Cargo.lock') }}
- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: contracts/docker-build.tar
key: ${{ runner.os }}-docker-build-${{ needs.get_projectserum_version.outputs.projectserum_version }}-${{ hashFiles('**/Cargo.lock') }}'
- name: load cached image
run: |
docker load --input docker-build.tar
- name: run tests
env:
psversion: ${{ needs.get_projectserum_version.outputs.projectserum_version }}
run: |
docker run -v "$(pwd)/../":/repo backpackapp/build:"${psversion}" bash -c "\
docker run -v "$(pwd)/../":/repo chainlink-solana:build bash -c "\
set -eoux pipefail &&\
RUSTUP_HOME=\"/root/.rustup\" &&\
FORCE_COLOR=1 &&\
Expand All @@ -62,50 +79,32 @@ jobs:
cd /repo/contracts &&\
yarn install --frozen-lockfile &&\
anchor test &&\
chmod -R 755 ./target &&\
cd /repo/contracts/examples/hello-world &&\
yarn install --frozen-lockfile &&\
anchor test"
# - run: solana-keygen new -o id.json --no-bip39-passphrase
# - name: Compile typescript client
# run: |
# cd ../ts
# yarn install --frozen-lockfile
# yarn build
# - name: anchor test contracts
# run: |
# yarn install --frozen-lockfile
# anchor test
# - name: anchor test hello-world
# run: |
# cd examples/hello-world
# yarn install --frozen-lockfile
# anchor test
anchor test &&\
chmod -R 755 ./target"
rust_lint:
name: Rust Lint
runs-on: ubuntu-latest
needs: [get_projectserum_version]
needs: [get_projectserum_version, build_wrapped_anchor_image]
steps:
- uses: actions/checkout@44c2b7a8a4ea60a981eaca3cf939b5f4305c123b # v4.1.5
- name: Cache cargo registry
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-v2-cargo-registry-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo index
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-v2-cargo-index-${{ hashFiles('**/Cargo.lock') }}

- name: Cache cargo target dir
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: contracts/target
key: ${{ runner.os }}-v2-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}

- name: cache docker build image
id: cache-image
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: contracts/docker-build.tar
key: ${{ runner.os }}-docker-build-${{ needs.get_projectserum_version.outputs.projectserum_version }}-${{ hashFiles('**/Cargo.lock') }}'
- name: load cached image
run: |
docker load --input docker-build.tar
- name: format contracts + artifacts
run: |
yarn install --frozen-lockfile
Expand All @@ -115,10 +114,8 @@ jobs:
git diff --stat --exit-code
- name: cargo check
env:
psversion: ${{ needs.get_projectserum_version.outputs.projectserum_version }}
run: |
docker run -v "$(pwd)/../":/repo backpackapp/build:"${psversion}" bash -c "\
docker run -v "$(pwd)/../":/repo chainlink-solana:build bash -c "\
set -eoux pipefail &&\
RUSTUP_HOME=\"/root/.rustup\" &&\
FORCE_COLOR=1 &&\
Expand Down
1 change: 1 addition & 0 deletions contracts/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
10 changes: 10 additions & 0 deletions contracts/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ARG ANCHOR_CLI

FROM backpackapp/build:${ANCHOR_CLI}

COPY . /contracts

RUN cd /contracts && anchor build

# only keep downloaded artifacts in /root/.cargo cached
RUN rm -rf /contracts

0 comments on commit 3ff8c1b

Please sign in to comment.