Skip to content

Commit

Permalink
ci: Refactor Node.js setup to a composite action.
Browse files Browse the repository at this point in the history
  • Loading branch information
kovipu committed Nov 21, 2024
1 parent 16b0335 commit b33b9e6
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 43 deletions.
13 changes: 13 additions & 0 deletions .github/actions/setup-node/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Setup Node.js with .nvmrc
description: Reads the .nvmrc file and sets up the corresponding Node.js version
runs:
using: composite
steps:
- name: Read .nvmrc
run: echo "node-version=$(cat .nvmrc)" >> $GITHUB_ENV
shell: bash

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ env.node-version }}
10 changes: 6 additions & 4 deletions .github/actions/setup-rust-stellar/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ runs:
toolchain: stable
targets: wasm32-unknown-unknown

- name: Rust cache
uses: stellar/actions/rust-cache@main

- name: Install Stellar CLI
run: |
cargo install --locked stellar-cli --version ${{ inputs.stellar_version }} --features opt
wget -q https://github.com/stellar/stellar-cli/releases/download/v22.0.0/stellar-cli-22.0.0-x86_64-unknown-linux-gnu.tar.gz
tar xvf stellar-cli-22.0.0-x86_64-unknown-linux-gnu.tar.gz
sudo mv stellar /usr/local/bin/
stellar --version
shell: bash


15 changes: 3 additions & 12 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@ jobs:
- name: Checkout your repository using git
uses: actions/checkout@v4

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'

- name: Rust cache
uses: Swatinem/rust-cache@v2

- name: Setup Rust and Stellar
uses: ./.github/actions/setup-rust-stellar

- name: Setup Node.js
uses: ./.github/actions/setup-node

- name: Build contracts
run: make build

Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,8 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Setup Node.js
uses: ./.github/actions/setup-node

- name: Install dependencies
run: npm ci
Expand Down
13 changes: 5 additions & 8 deletions .github/workflows/verify-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,15 @@ jobs:
- name: Checkout your repository using git
uses: actions/checkout@v4

- name: Read .nvmrc
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
id: nvm

- name: Setup node
uses: actions/setup-node@v3
with:
node-version: '${{ steps.nvm.outputs.NVMRC }}'
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2

- name: Setup Rust and Stellar
uses: ./.github/actions/setup-rust-stellar

- name: Setup Node.js
uses: ./.github/actions/setup-node

- name: Build contracts
run: make build

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Cargo.lock
## soroban/Rust output
target
.soroban
.stellar

# build output
dist/
Expand Down
3 changes: 1 addition & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
[toolchain]
channel = "1.81.0"
channel = "nightly"
targets = ["wasm32-unknown-unknown"]

8 changes: 4 additions & 4 deletions scripts/initialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ console.log('######################Initializing contracts ######################

const deploy = (wasm: string) => {
exe(
`stellar contract deploy --wasm ${wasm} --ignore-checks > ./.soroban/contract-ids/${filenameNoExtension(wasm)}.txt`,
`stellar contract deploy --wasm ${wasm} --ignore-checks > ./.stellar/contract-ids/${filenameNoExtension(wasm)}.txt`,
);
};

/** Deploy loan_manager contract as there will only be one for all the pools.
* Loan_manager is used as a factory for the loan_pools.
*/
const deployLoanManager = () => {
const contractsDir = `.soroban/contract-ids`;
const contractsDir = `.stellar/contract-ids`;
mkdirSync(contractsDir, { recursive: true });

deploy(`./target/wasm32-unknown-unknown/release/loan_manager.wasm`);
Expand All @@ -43,7 +43,7 @@ const deployLoanManager = () => {

/** Deploy liquidity pools using the loan-manager as a factory contract */
const deployLoanPools = () => {
const wasmHash = readTextFile('./.soroban/contract-wasm-hash/loan_pool.txt');
const wasmHash = readTextFile('./.stellar/contract-wasm-hash/loan_pool.txt');

CURRENCIES.forEach(({ tokenContractAddress, ticker, loanPoolName }: Currency) => {
const salt = crypto.randomBytes(32).toString('hex');
Expand All @@ -58,7 +58,7 @@ const deployLoanPools = () => {
--token_address ${tokenContractAddress} \
--ticker ${ticker} \
--liquidation_threshold 800000 \
| tr -d '"' > ./.soroban/contract-ids/${loanPoolName}.txt`,
| tr -d '"' > ./.stellar/contract-ids/${loanPoolName}.txt`,
);
});
};
Expand Down
10 changes: 5 additions & 5 deletions scripts/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ export const buildContracts = () => {
exe(`make build`);
};

/** Install all contracts and save their wasm hashes to .soroban */
/** Install all contracts and save their wasm hashes to .stellar */
export const installContracts = () => {
const contractsDir = `./.soroban/contract-wasm-hash`;
const contractsDir = `./.stellar/contract-wasm-hash`;
mkdirSync(contractsDir, { recursive: true });

const wasmFiles = readdirSync(`./target/wasm32-unknown-unknown/release`).filter((file) => file.endsWith('.wasm'));
Expand All @@ -55,7 +55,7 @@ export const installContracts = () => {
/* Install a contract */
const install = (wasm: string) => {
exe(
`stellar contract install --wasm ${wasm} --ignore-checks > ./.soroban/contract-wasm-hash/${filenameNoExtension(wasm)}.txt`,
`stellar contract install --wasm ${wasm} --ignore-checks > ./.stellar/contract-wasm-hash/${filenameNoExtension(wasm)}.txt`,
);
};

Expand All @@ -67,7 +67,7 @@ export const readTextFile = (path: string): string => readFileSync(path, { encod

// This is a function so its value can update during init.
export const loanManagerAddress = (): string =>
process.env.CONTRACT_ID_LOAN_MANAGER || readTextFile('./.soroban/contract-ids/loan_manager.txt');
process.env.CONTRACT_ID_LOAN_MANAGER || readTextFile('./.stellar/contract-ids/loan_manager.txt');

export const createContractBindings = () => {
bind('loan_manager', process.env.CONTRACT_ID_LOAN_MANAGER);
Expand All @@ -79,7 +79,7 @@ export const createContractBindings = () => {
};

const bind = (contractName: string, address: string | undefined) => {
const address_ = address || readTextFile(`./.soroban/contract-ids/${contractName}.txt`);
const address_ = address || readTextFile(`./.stellar/contract-ids/${contractName}.txt`);
exe(
`stellar contract bindings typescript --contract-id ${address_} --output-dir ./packages/${contractName} --overwrite`,
);
Expand Down

0 comments on commit b33b9e6

Please sign in to comment.