Skip to content

Commit 6bac4b2

Browse files
committed
ci: Refactor Node.js setup to a composite action.
1 parent 16b0335 commit 6bac4b2

File tree

10 files changed

+43
-44
lines changed

10 files changed

+43
-44
lines changed

.github/actions/setup-node/action.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Setup Node.js with .nvmrc
2+
description: Reads the .nvmrc file and sets up the corresponding Node.js version
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Read .nvmrc
7+
run: echo "node-version=$(cat .nvmrc)" >> $GITHUB_ENV
8+
shell: bash
9+
10+
- name: Setup Node.js
11+
uses: actions/setup-node@v3
12+
with:
13+
node-version: ${{ env.node-version }}

.github/actions/setup-rust-stellar/action.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ runs:
1414
toolchain: stable
1515
targets: wasm32-unknown-unknown
1616

17-
- name: Rust cache
18-
uses: stellar/actions/rust-cache@main
19-
2017
- name: Install Stellar CLI
2118
run: |
22-
cargo install --locked stellar-cli --version ${{ inputs.stellar_version }} --features opt
19+
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
20+
tar xvf stellar-cli-22.0.0-x86_64-unknown-linux-gnu.tar.gz
21+
sudo mv stellar /usr/local/bin/
22+
stellar --version
2323
shell: bash
24+
25+

.github/workflows/deploy.yml

+3-12
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,12 @@ jobs:
1515
- name: Checkout your repository using git
1616
uses: actions/checkout@v4
1717

18-
- name: Read .nvmrc
19-
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
20-
id: nvm
21-
22-
- name: Setup node
23-
uses: actions/setup-node@v3
24-
with:
25-
node-version: '${{ steps.nvm.outputs.NVMRC }}'
26-
27-
- name: Rust cache
28-
uses: Swatinem/rust-cache@v2
29-
3018
- name: Setup Rust and Stellar
3119
uses: ./.github/actions/setup-rust-stellar
3220

21+
- name: Setup Node.js
22+
uses: ./.github/actions/setup-node
23+
3324
- name: Build contracts
3425
run: make build
3526

.github/workflows/nodejs.yml

+3-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: NodeJS
1+
name: Node.js
22

33
on:
44
push:
@@ -19,14 +19,8 @@ jobs:
1919
steps:
2020
- uses: actions/checkout@v3
2121

22-
- name: Read .nvmrc
23-
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
24-
id: nvm
25-
26-
- name: Setup node
27-
uses: actions/setup-node@v3
28-
with:
29-
node-version: '${{ steps.nvm.outputs.NVMRC }}'
22+
- name: Setup Node.js
23+
uses: ./.github/actions/setup-node
3024

3125
- name: Install dependencies
3226
run: npm ci

.github/workflows/verify-build.yml

+6-7
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ jobs:
1010
- name: Checkout your repository using git
1111
uses: actions/checkout@v4
1212

13-
- name: Read .nvmrc
14-
run: echo ::set-output name=NVMRC::$(cat .nvmrc)
15-
id: nvm
16-
17-
- name: Setup node
18-
uses: actions/setup-node@v3
13+
- name: Cache Rust dependencies
14+
uses: Swatinem/rust-cache@v2
1915
with:
20-
node-version: '${{ steps.nvm.outputs.NVMRC }}'
16+
cache-on-failure: "true"
2117

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

21+
- name: Setup Node.js
22+
uses: ./.github/actions/setup-node
23+
2524
- name: Build contracts
2625
run: make build
2726

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Cargo.lock
2626
## soroban/Rust output
2727
target
2828
.soroban
29+
.stellar
2930

3031
# build output
3132
dist/

rust-toolchain.toml

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[toolchain]
22
channel = "1.81.0"
33
targets = ["wasm32-unknown-unknown"]
4-

scripts/initialize.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ console.log('######################Initializing contracts ######################
2020

2121
const deploy = (wasm: string) => {
2222
exe(
23-
`stellar contract deploy --wasm ${wasm} --ignore-checks > ./.soroban/contract-ids/${filenameNoExtension(wasm)}.txt`,
23+
`stellar contract deploy --wasm ${wasm} --ignore-checks > ./.stellar/contract-ids/${filenameNoExtension(wasm)}.txt`,
2424
);
2525
};
2626

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

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

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

4848
CURRENCIES.forEach(({ tokenContractAddress, ticker, loanPoolName }: Currency) => {
4949
const salt = crypto.randomBytes(32).toString('hex');
@@ -58,7 +58,7 @@ const deployLoanPools = () => {
5858
--token_address ${tokenContractAddress} \
5959
--ticker ${ticker} \
6060
--liquidation_threshold 800000 \
61-
| tr -d '"' > ./.soroban/contract-ids/${loanPoolName}.txt`,
61+
| tr -d '"' > ./.stellar/contract-ids/${loanPoolName}.txt`,
6262
);
6363
});
6464
};

scripts/upgrade.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ console.log('######################Updating contracts ########################')
1414

1515
// Invoke the upgrade-action of loan manager. It will upgrade its pools as well.
1616
const upgradeContracts = () => {
17-
const managerWasmHash = readTextFile('./.soroban/contract-wasm-hash/loan_manager.txt');
18-
const poolWasmHash = readTextFile('./.soroban/contract-wasm-hash/loan_pool.txt');
17+
const managerWasmHash = readTextFile('./.stellar/contract-wasm-hash/loan_manager.txt');
18+
const poolWasmHash = readTextFile('./.stellar/contract-wasm-hash/loan_pool.txt');
1919

2020
exe(`stellar contract invoke \
2121
--id ${loanManagerAddress()} \

scripts/util.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ export const buildContracts = () => {
4040
exe(`make build`);
4141
};
4242

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

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

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

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

7272
export const createContractBindings = () => {
7373
bind('loan_manager', process.env.CONTRACT_ID_LOAN_MANAGER);
@@ -79,7 +79,7 @@ export const createContractBindings = () => {
7979
};
8080

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

0 commit comments

Comments
 (0)