Ver código fonte

ci: Switch to github actions, parallelise tests (#1066)

Paul 3 anos atrás
pai
commit
a4002dfb95

+ 19 - 0
.github/actions/setup-solana/action.yaml

@@ -0,0 +1,19 @@
+name: "Setup Solana"
+description: "Setup Solana"
+runs:
+  using: "composite"
+  steps:
+      - uses: actions/cache@v2
+        name: Cache Solana Tool Suite
+        id: cache-solana
+        with:
+          path: |
+            ~/.cache/solana/
+            ~/.local/share/solana/
+          key: solana-${{ runner.os }}-v0000-${{ env.SOLANA_CLI_VERSION }}
+      - run: sh -c "$(curl -sSfL https://release.solana.com/v${{ env.SOLANA_CLI_VERSION }}/install)"
+        shell: bash
+      - run: echo "/home/runner/.local/share/solana/install/active_release/bin" >> $GITHUB_PATH
+        shell: bash
+      - run: solana-keygen new --no-bip39-passphrase
+        shell: bash

+ 21 - 0
.github/actions/setup-ts/action.yaml

@@ -0,0 +1,21 @@
+name: "Setup ts"
+description: "Setup ts"
+runs:
+  using: "composite"
+  steps:
+      - uses: actions/setup-node@v2
+        with:
+          node-version: ${{ env.NODE_VERSION }}
+      - uses: actions/cache@v2
+        name: Cache Typescript node_modules
+        id: cache-typescript
+        with:
+          path: |
+            ./ts/node_modules
+          key: solana-${{ runner.os }}-v0000-${{ env.NODE_VERSION }}-${{ hashFiles('**/yarn.lock') }}
+      - run: cd ts && yarn && yarn build && yarn link && cd ../
+        shell: bash
+      - run: cd examples/tutorial && yarn link @project-serum/anchor && yarn && cd ../../
+        shell: bash
+      - run: cd tests && yarn link @project-serum/anchor && yarn && cd ..
+        shell: bash

+ 11 - 0
.github/actions/setup/action.yaml

@@ -0,0 +1,11 @@
+name: "Setup"
+description: "Setup"
+runs:
+  using: "composite"
+  steps:
+      - run: sudo apt-get install -y pkg-config build-essential libudev-dev
+        shell: bash
+      - run: echo "ANCHOR_VERSION=$(cat ./VERSION)" >> $GITHUB_ENV
+        shell: bash
+      - run: git submodule update --init --recursive
+        shell: bash

+ 260 - 0
.github/workflows/tests.yaml

@@ -0,0 +1,260 @@
+name: Tests
+
+on:
+  push:
+    branches:
+      - master
+  pull_request:
+    branches:
+      - master
+env: 
+  SOLANA_CLI_VERSION: 1.8.0
+  NODE_VERSION: 17.0.1
+
+jobs:
+  test-core:
+    name: Core Tests
+    runs-on: ubuntu-18.04
+    steps:
+      - uses: actions/checkout@v2
+      - uses: ./.github/actions/setup/
+      - uses: actions/setup-node@v2
+        with:
+          node-version: ${{ env.NODE_VERSION }}
+      - uses: actions/cache@v2
+        name: Cache Cargo registry + index
+        id: cache-cargo-build
+        with:
+          path: |
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            ./target/
+          key: cargo-${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
+      - run: cargo build
+      - run: cargo fmt -- --check
+      - run: cargo clippy --all-targets -- -D warnings
+      - run: cargo test
+      - run: cd ts && yarn 
+      - run: cd ts && yarn test 
+      - run: cd ts && yarn lint 
+
+  setup-anchor-cli:
+    name: Setup Anchor cli
+    runs-on: ubuntu-18.04
+    steps:
+      - uses: actions/checkout@v2
+      - uses: ./.github/actions/setup/
+
+      - uses: actions/cache@v2
+        name: Cache Cargo registry + index
+        id: cache-anchor
+        with:
+          path: |
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            ./target/
+          key: cargo-${{ runner.os }}-anchor-${{ hashFiles('**/Cargo.lock') }}
+      - run: cargo install --path cli anchor-cli --locked --force
+      - uses: actions/upload-artifact@v2
+        with:
+          name: anchor-binary
+          path: ~/.cargo/bin/anchor
+
+  test-examples:
+    needs: setup-anchor-cli
+    name: Examples Test
+    runs-on: ubuntu-18.04
+    steps:
+      - uses: actions/checkout@v2
+      - uses: actions/download-artifact@v2
+        with:
+          name: anchor-binary
+          path: ~/.cargo/bin/
+      - run: chmod +rwx ~/.cargo/bin/anchor
+      - uses: ./.github/actions/setup/
+      - uses: ./.github/actions/setup-solana/
+      - uses: ./.github/actions/setup-ts/
+      - uses: actions/cache@v2
+        name: basic-0 cache
+        id: cache-basic-0
+        with:
+          path: ./examples/tutorial/basic-0/target
+          key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-0/**/Cargo.toml') }}
+      - uses: actions/cache@v2
+        name: basic-1 cache
+        id: cache-basic-1
+        with:
+          path: ./examples/tutorial/basic-1/target
+          key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-1/**/Cargo.toml') }}
+      - uses: actions/cache@v2
+        name: basic-2 cache
+        id: cache-basic-2
+        with:
+          path: ./examples/tutorial/basic-2/target
+          key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-2/**/Cargo.toml') }}
+      - uses: actions/cache@v2
+        name: basic-3 cache
+        id: cache-basic-3
+        with:
+          path: ./examples/tutorial/basic-3/target
+          key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-3/**/Cargo.toml') }}
+      - uses: actions/cache@v2
+        name: basic-4 cache
+        id: cache-basic-4
+        with:
+          path: ./examples/tutorial/basic-4/target
+          key: cargo-${{ runner.os }}-${{ hashFiles('./examples/tutorial/basic-4/**/Cargo.toml') }}
+      - run: cd examples/tutorial && yarn workspaces run test
+
+  setup-client-example:
+    needs: setup-anchor-cli
+    name: Setup Client Example Test
+    runs-on: ubuntu-18.04
+    strategy:
+      matrix:
+        node:
+          - path: tests/events/
+            name: events.so
+          - path: examples/tutorial/basic-4/
+            name: basic_4.so
+          - path: examples/tutorial/basic-2/
+            name: basic_2.so
+          - path: tests/composite/
+            name: composite.so
+    steps:
+      - uses: actions/checkout@v2
+      - uses: ./.github/actions/setup/
+      - uses: ./.github/actions/setup-solana/
+
+      - uses: actions/download-artifact@v2
+        with:
+          name: anchor-binary
+          path: ~/.cargo/bin/
+      - run: chmod +rwx ~/.cargo/bin/anchor
+      - run: cd ${{ matrix.node.path }} && anchor build 
+      - uses: actions/upload-artifact@v2
+        with:
+          name: ${{ matrix.node.name }}
+          path: ${{ matrix.node.path }}target/deploy/${{ matrix.node.name }}
+  
+  test-client-example:
+    needs: setup-client-example
+    name: Client Example Test
+    runs-on: ubuntu-18.04
+    steps:
+      - uses: actions/checkout@v2
+      - uses: ./.github/actions/setup/
+      - uses: ./.github/actions/setup-ts/
+
+      - uses: actions/download-artifact@v2
+        with:
+          name: anchor-binary
+          path: ~/.cargo/bin/
+      - uses: actions/download-artifact@v2
+        with:
+          name: events.so
+          path: tests/events/target/deploy/
+      - uses: actions/download-artifact@v2
+        with:
+          name: basic_4.so
+          path: examples/tutorial/basic-4/target/deploy/
+      - uses: actions/download-artifact@v2
+        with:
+          name: basic_2.so
+          path: examples/tutorial/basic-2/target/deploy/
+      - uses: actions/download-artifact@v2
+        with:
+          name: composite.so
+          path: tests/composite/target/deploy/
+      - uses: actions/cache@v2
+        name: Cache client/example target
+        id: cache-test-target
+        with:
+          path: client/example/target
+          key: cargo-${{ runner.os }}-client/example-${{ env.ANCHOR_VERSION }}
+      - uses: ./.github/actions/setup-solana/
+      - run: cd client/example && ./run-test.sh 
+
+  test-programs:
+    needs: setup-anchor-cli
+    name: Test ${{ matrix.node.path }}
+    runs-on: ubuntu-18.04
+    strategy:
+      matrix:
+        node:
+          - cmd: cd tests/sysvars && anchor test 
+            path: tests/sysvars
+          - cmd: cd tests/composite && anchor test 
+            path: tests/composite
+          - cmd: cd tests/errors && anchor test 
+            path: tests/errors
+          - cmd: cd tests/spl/token-proxy && anchor test 
+            path: spl/token-proxy
+          - cmd: cd tests/multisig && anchor test 
+            path: tests/multisig
+          - cmd: cd tests/interface && anchor test 
+            path: tests/interface
+          - cmd: cd tests/lockup && anchor test 
+            path: tests/lockup
+          - cmd: cd tests/permissioned-markets/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test 
+            path: tests/permissioned-markets
+          - cmd: cd tests/swap/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test 
+            path: tests/swap
+          - cmd: cd tests/escrow && anchor test 
+            path: tests/escrow
+          - cmd: cd tests/pyth && anchor test 
+            path: tests/pyth
+          - cmd: cd tests/system-accounts && anchor test 
+            path: tests/system-accounts
+          - cmd: cd tests/misc && anchor test 
+            path: tests/misc
+          - cmd: cd tests/events && anchor test 
+            path: tests/events
+          - cmd: cd tests/cashiers-check && anchor test 
+            path: tests/cashiers-check
+          - cmd: cd tests/typescript && anchor test 
+            path: tests/typescript
+          - cmd: cd tests/zero-copy && anchor test 
+            path: tests/zero-copy
+          - cmd: cd tests/chat && anchor test 
+            path: tests/chat
+          - cmd: cd tests/ido-pool && anchor test 
+            path: tests/ido-pool
+          - cmd: cd tests/cfo && anchor run test-with-build 
+            path: tests/cfo
+    steps:
+      - uses: actions/checkout@v2
+      - uses: ./.github/actions/setup/
+      - uses: ./.github/actions/setup-ts/
+      - uses: ./.github/actions/setup-solana/
+
+      - uses: actions/cache@v2
+        name: Cache Cargo registry + index
+        id: cache-anchor
+        with:
+          path: |
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            ./target/
+          key: cargo-${{ runner.os }}-anchor-${{ hashFiles('**/Cargo.lock') }}
+
+      - uses: actions/download-artifact@v2
+        with:
+          name: anchor-binary
+          path: ~/.cargo/bin/
+
+      - uses: actions/cache@v2
+        name: Cache ${{ matrix.node.path }} target
+        id: cache-test-target
+        with:
+          path: ${{ matrix.node.path }}/target
+          key: cargo-${{ runner.os }}-${{ matrix.node.path }}-${{ env.ANCHOR_VERSION }}
+      
+      - run: ${{ matrix.node.cmd }}
+        name: ${{ matrix.node.path }} program test

+ 0 - 73
.travis.yml

@@ -1,73 +0,0 @@
-dist: bionic
-language: rust
-rust:
-  - stable
-cache: cargo
-env:
-  global:
-    - NODE_VERSION="17.0.1"
-    - SOLANA_CLI_VERSION="1.8.0"
-git:
-  submodules: true
-
-_defaults: &defaults
-  before_install:
-  - rustup component add rustfmt clippy
-  - nvm install $NODE_VERSION
-  - sudo apt-get install -y pkg-config build-essential libudev-dev
-
-_tests: &tests
-  before_install:
-  - nvm install $NODE_VERSION
-  - cd ts && yarn && yarn build && yarn link && cd ../
-  - cd examples/tutorial && yarn link @project-serum/anchor && yarn && cd ../../
-  - cd tests && yarn link @project-serum/anchor && yarn && cd ..
-  - sudo apt-get install -y pkg-config build-essential libudev-dev
-  - sh -c "$(curl -sSfL https://release.solana.com/v${SOLANA_CLI_VERSION}/install)"
-  - export PATH="/home/travis/.local/share/solana/install/active_release/bin:$PATH"
-  - yes | solana-keygen new
-  - cargo install --path $TRAVIS_BUILD_DIR/cli anchor-cli --locked
-
-jobs:
-  include:
-    - <<: *defaults
-      name: Build and test Rust
-      script:
-        - cargo build
-        - cargo fmt -- --check
-        - cargo clippy --all-targets -- -D warnings
-        - cargo test
-        - pushd ts && yarn && popd
-        - pushd ts && yarn test && popd
-        - pushd ts && yarn lint && popd
-    - <<: *tests
-      name: Runs the e2e tests 1
-      script:
-        - pushd client/example && ./run-test.sh && popd
-        - pushd tests/sysvars && anchor test && popd
-        - pushd tests/composite && anchor test && popd
-        - pushd tests/errors && anchor test && popd
-        - pushd tests/spl/token-proxy && anchor test && popd
-        - pushd tests/multisig && anchor test && popd
-        - pushd tests/interface && anchor test && popd
-        - pushd tests/lockup && anchor test && popd
-        - pushd tests/permissioned-markets/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test && popd
-    - <<: *tests
-      name: Runs the e2e tests 2
-      script:
-        - pushd tests/misc && anchor test && popd
-        - pushd tests/events && anchor test && popd
-        - pushd tests/cashiers-check && anchor test && popd
-        - pushd tests/typescript && anchor test && popd
-        - pushd tests/zero-copy && anchor test && popd
-        - pushd tests/chat && anchor test && popd
-        - pushd tests/ido-pool && anchor test && popd
-        - pushd tests/swap/deps/serum-dex/dex && cargo build-bpf && cd ../../../ && anchor test && popd
-        - pushd tests/cfo && anchor run test-with-build && popd
-    - <<: *tests
-      name: Runs the e2e tests 3
-      script:
-        - pushd tests/escrow && anchor test && popd
-        - pushd tests/pyth && anchor test && popd
-        - pushd tests/system-accounts && anchor test && popd
-        - pushd examples/tutorial && yarn workspaces run test

+ 0 - 12
client/example/run-test.sh

@@ -22,22 +22,10 @@ main() {
     #
     # Build programs.
     #
-    pushd ../../tests/composite/
-    anchor build
     local composite_pid="EHthziFziNoac9LBGxEaVN47Y3uUiRoXvqAiR6oes4iU"
-    popd
-    pushd ../../examples/tutorial/basic-2/
-    anchor build
     local basic_2_pid="Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS"
-    popd
-    pushd ../../examples/tutorial/basic-4/
-    anchor build
     local basic_4_pid="CwrqeMj2U8tFr1Rhkgwc84tpAsqbt9pTt2a4taoTADPr"
-    popd
-    pushd ../../tests/events
-    anchor build
     local events_pid="2dhGsWUzy5YKUsjZdLHLmkNpUDAXkNa9MYWsPc4Ziqzy"
-    popd
 
     #
     # Bootup validator.