瀏覽代碼

ci: re-enable SPL downstream project test on Github Action (#32677)

* ci: init spl downstream project on Github Action

* ci: fix spl downstream project doesn't use cargo-test-sbf

* ci: move nightly build to another individual file

* ci: get more space for runners on Github Action

* ci: trun off fali-fast

* Update .github/workflows/downstream-project-spl.yml

Co-authored-by: Jon Cinque <me@jonc.dev>

* ci: separate all spl programs

* use reusable workflow

* add error reporting for nightly build

* update test method

* add build and test

* only build required program

* remove other branches

* Update .github/workflows/downstream-project-spl.yml

Co-authored-by: Jon Cinque <me@jonc.dev>

* Update .github/workflows/downstream-project-spl.yml

Co-authored-by: Jon Cinque <me@jonc.dev>

* add check

* update build and test

* add lacking programs

* remove unnecessary programs

---------

Co-authored-by: Jon Cinque <me@jonc.dev>
Yihau Chen 2 年之前
父節點
當前提交
bc5ad1d2ab

+ 24 - 0
.github/scripts/downstream-project-spl-common.sh

@@ -0,0 +1,24 @@
+#!/usr/bin/env bash
+set -e
+
+here="$(dirname "${BASH_SOURCE[0]}")"
+
+#shellcheck source=ci/downstream-projects/common.sh
+source "$here"/../../ci/downstream-projects/common.sh
+
+set -x
+rm -rf spl
+git clone https://github.com/solana-labs/solana-program-library.git spl
+
+# copy toolchain file to use solana's rust version
+cp "$SOLANA_DIR"/rust-toolchain.toml spl/
+cd spl || exit 1
+
+project_used_solana_version=$(sed -nE 's/solana-sdk = \"[>=<~]*(.*)\"/\1/p' <"token/program/Cargo.toml")
+echo "used solana version: $project_used_solana_version"
+if semverGT "$project_used_solana_version" "$SOLANA_VER"; then
+  echo "skip"
+  return
+fi
+
+./patch.crates-io.sh "$SOLANA_DIR"

+ 17 - 0
.github/scripts/purge-ubuntu-runner.sh

@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+sudo rm -rf /usr/share/dotnet
+sudo rm -rf /usr/share/swift
+sudo rm -rf /usr/share/mysql
+sudo rm -rf /usr/share/az_*
+sudo rm -rf /usr/share/postgresql-common
+
+sudo rm -rf /opt/ghc
+sudo rm -rf /opt/az
+sudo rm -rf /opt/pipx
+sudo rm -rf /opt/microsoft
+sudo rm -rf /opt/google
+sudo rm -rf /opt/hostedtoolcache
+
+sudo rm -rf /usr/local/lib/android
+sudo rm -rf /usr/local/lib/heroku

+ 24 - 0
.github/workflows/downstream-project-spl-nightly.yml

@@ -0,0 +1,24 @@
+name: Downstream Project - SPL (Nightly)
+
+on:
+  schedule:
+    - cron: "0 3 * * *"
+
+jobs:
+  main:
+    strategy:
+      fail-fast: false
+      matrix:
+        branch:
+          - master
+    uses: ./.github/workflows/downstream-project-spl.yml
+    with:
+      branch: ${{ matrix.branch }}
+
+  error_reporting:
+    needs:
+      - main
+    if: failure()
+    uses: ./.github/workflows/error-reporting.yml
+    secrets:
+      WEBHOOK: ${{ secrets.SLACK_ERROR_REPORTING_WEBHOOK }}

+ 154 - 0
.github/workflows/downstream-project-spl.yml

@@ -0,0 +1,154 @@
+name: Downstream Project - SPL
+
+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"
+      - "ci/downstream-projects/run-spl.sh"
+      - ".github/workflows/downstream-project-spl.yml"
+  workflow_call:
+    inputs:
+      branch:
+        required: false
+        type: string
+        default: "master"
+
+env:
+  SHELL: /bin/bash
+  SCCACHE_GHA_ENABLED: "true"
+  RUSTC_WRAPPER: "sccache"
+
+jobs:
+  check:
+    runs-on: ubuntu-latest
+    steps:
+      - uses: actions/checkout@v3
+
+      - shell: bash
+        run: |
+          .github/scripts/purge-ubuntu-runner.sh
+
+      - uses: mozilla-actions/sccache-action@v0.0.3
+
+      - shell: bash
+        run: |
+          source .github/scripts/downstream-project-spl-common.sh
+
+          sudo apt update
+          sudo apt install libudev-dev binutils-dev libunwind-dev -y
+
+          cargo check
+
+  test:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        arrays:
+          [
+            {
+              test_paths: ["token/cli"],
+              required_programs:
+                [
+                  "token/program",
+                  "token/program-2022",
+                  "associated-token-account/program",
+                ],
+            },
+            {
+              test_paths: ["single-pool/cli"],
+              required_programs:
+                [
+                  "single-pool/program",
+                ],
+            },
+            {
+              test_paths: ["token-upgrade/cli"],
+              required_programs:
+                [
+                  "token-upgrade/program",
+                ],
+            },
+          ]
+    steps:
+      - uses: actions/checkout@v3
+
+      - shell: bash
+        run: |
+          .github/scripts/purge-ubuntu-runner.sh
+
+      - uses: mozilla-actions/sccache-action@v0.0.3
+
+      - shell: bash
+        run: |
+          source .github/scripts/downstream-project-spl-common.sh
+
+          sudo apt update
+          sudo apt install libudev-dev binutils-dev libunwind-dev -y
+
+          programStr="${{ tojson(matrix.arrays.required_programs) }}"
+          IFS=', ' read -ra programs <<<"${programStr//[\[\]$'\n'$'\r' ]/}"
+          for program in "${programs[@]}"; do
+            $CARGO_BUILD_SBF --manifest-path "$program"/Cargo.toml
+          done
+
+          testPathsStr="${{ tojson(matrix.arrays.test_paths) }}"
+          IFS=', ' read -ra test_paths <<<"${testPathsStr//[\[\]$'\n'$'\r' ]/}"
+          for test_path in "${test_paths[@]}"; do
+            cargo test --manifest-path "$test_path"/Cargo.toml
+          done
+
+  cargo-test-sbf:
+    runs-on: ubuntu-latest
+    strategy:
+      matrix:
+        programs:
+          - [token/program]
+          - [
+              instruction-padding/program,
+              token/program-2022,
+              token/program-2022-test,
+            ]
+          - [
+              associated-token-account/program,
+              associated-token-account/program-test,
+            ]
+          - [token-upgrade/program]
+          - [feature-proposal/program]
+          - [governance/addin-mock/program, governance/program]
+          - [memo/program]
+          - [name-service/program]
+          - [stake-pool/program]
+          - [single-pool/program]
+
+    steps:
+      - uses: actions/checkout@v3
+
+      - shell: bash
+        run: |
+          .github/scripts/purge-ubuntu-runner.sh
+
+      - uses: mozilla-actions/sccache-action@v0.0.3
+
+      - shell: bash
+        run: |
+          source .github/scripts/downstream-project-spl-common.sh
+
+          programStr="${{ tojson(matrix.programs) }}"
+          IFS=', ' read -ra programs <<<"${programStr//[\[\]$'\n'$'\r' ]/}"
+
+          for program in "${programs[@]}"; do
+            $CARGO_TEST_SBF --manifest-path "$program"/Cargo.toml
+          done

+ 1 - 1
ci/downstream-projects/func-spl.sh

@@ -35,7 +35,7 @@ spl() {
     ./patch.crates-io.sh "$SOLANA_DIR"
 
     for program in "${PROGRAMS[@]}"; do
-      $CARGO_BUILD_SBF --manifest-path "$program"/Cargo.toml
+      $CARGO_TEST_SBF --manifest-path "$program"/Cargo.toml
     done
 
     # TODO better: `build.rs` for spl-token-cli doesn't seem to properly build