Skip to content

Commit

Permalink
Create default setup GitHub workflow
Browse files Browse the repository at this point in the history
A new default setup workflow has been created for the GitHub Actions to consolidate common steps shared among all workflows. This new workflow reduces redundancy by providing a centralized setup procedure used in other workflows like 'lint' and 'test'. The setup includes key steps such as Node.js setup, dependencies installation, Foundry installation and others.
  • Loading branch information
shuhuiluo committed Jul 20, 2024
1 parent 3aefbe3 commit 812e3ec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 65 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/default-setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: default-setup

on:
workflow_call:
secrets:
INFURA_API_KEY:
required: true
outputs:
cache-key:
description: "Cache key"
value: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
jobs:
setup:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Install dependencies 📦
run: yarn install --frozen-lockfile

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Generate contract Rust bindings
run: yarn bind

- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
77 changes: 12 additions & 65 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,41 +13,15 @@ env:
jobs:
lint:
name: Lint
needs: setup
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Install dependencies 📦
run: yarn install --frozen-lockfile

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Generate contract Rust bindings
run: yarn bind

- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Setup
id: setup
uses: ./.github/workflows/default-setup.yml
secrets:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

- name: Install Rust toolchain via rustup
run: |
Expand All @@ -58,43 +32,16 @@ jobs:
run: cargo clippy --all-targets --all-features -- -D warnings

test:
needs: lint
needs: [ setup, lint ]
name: Test
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Use Node.js 20.x
uses: actions/setup-node@v4
with:
node-version: 20.x
cache: "yarn"
cache-dependency-path: "yarn.lock"

- name: Install dependencies 📦
run: yarn install --frozen-lockfile

- name: Install Foundry
uses: foundry-rs/foundry-toolchain@v1
with:
version: nightly

- name: Generate contract Rust bindings
run: forge bind -b src/bindings/ --module --overwrite

- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Setup
id: setup
uses: ./.github/workflows/default-setup.yml
secrets:
INFURA_API_KEY: ${{ secrets.INFURA_API_KEY }}

- name: Build
run: cargo build
Expand Down

0 comments on commit 812e3ec

Please sign in to comment.