Skip to content

Commit

Permalink
Merge pull request #74 from credbull/fix-github-actions
Browse files Browse the repository at this point in the history
Fix the broken GitHub Actions for `ops` and `sdk`.
  • Loading branch information
jplodge-pro authored Jul 8, 2024
2 parents 13eec92 + b76ce57 commit 95e7823
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 105 deletions.
19 changes: 17 additions & 2 deletions .github/workflows/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,50 @@
## Running Actions Locally

### Pre-requisite

1. Install act https://nektosact.com/installation/index.html
2. Jobs should be run from root folder (.././/)

### List Jobs

List jobs, with optional "--container-architecture" flag for Mac m chips

```bash
act --list --container-architecture linux/amd64
```

### Run check-env sample jobs
Run all jobs in ci-check-env.yml. Pass in an .env file as Environment variables and Secrets

Run all jobs in ci-check-env.yml. Pass in an .env file as Environment variables and Secrets

```bash
act -W .github/workflows/ci-check-env.yml --var-file packages/contracts/.env --secret-file packages/contracts/.secret --container-architecture linux/amd64
```

### Run Contracts jobs

Runs the contracts job - only the Env should be an .env (configs are in .toml) - local secrets are in .env

```bash
act -W .github/workflows/ci-dev-contracts.yml --var ENVIRONMENT=local --secret-file packages/contracts/.env --container-architecture linux/amd64
```

### Run API jobs

Runs the api job - only the Env should be an .env (configs are in .toml) - local secrets are in .env

```bash
act -W .github/workflows/ci-dev-api.yml --var ENVIRONMENT=local --secret-file packages/api/.env --container-architecture linux/amd64
```

### Run Ops jobs

Runs the ops job - only the Env should be an .env (configs are in .toml) - local secrets are in .env

```bash
act -W .github/workflows/ci-dev-ops.yml --var ENVIRONMENT=ci --secret-file packages/ops/.env --container-architecture linux/amd64
```
```

### Github Action Limitations

The workflows `ci-dev-sdk.yml` and `ci-dev-ops.yml` are nigh on identical, using a 'local' setup for CI invocation. An attempt to resolve this duplication of content using GitHub's Reusable Workflows was made, but that mechanism has proven unsuitable. As yet, no suitable mechanism is known, so we have duplication.
23 changes: 12 additions & 11 deletions .github/workflows/ci-dev-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ defaults:
on:
workflow_dispatch:
push:
branches:
- "main*"
- "development*"
- "ops*"
paths:
- "packages/app/**"
- "packages/contracts/**"
- ".github/workflows/ci-dev-app.yml"
branches:
- "main*"
- "development*"
paths:
- "packages/app/**"
- "packages/contracts/**"
- ".github/workflows/ci-dev-app.yml"

jobs:
app-build-deploy:
Expand All @@ -43,8 +42,10 @@ jobs:
with:
version: nightly

- name: Install dependencies
run: yarn install
- name: Install Project dependencies and Build
run: |
yarn install
yarn build
- name: Run Tests
run: yarn run test
Expand All @@ -61,7 +62,7 @@ jobs:

- name: Pull Vercel Environment Information
run: vercel pull --yes --environment=preview --cwd ../.. --token=${{ secrets.VERCEL_TOKEN }}
#

- name: Build Project Artifacts
run: vercel build --cwd ../.. --token=${{ secrets.VERCEL_TOKEN }}
env:
Expand Down
54 changes: 41 additions & 13 deletions .github/workflows/ci-dev-ops.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ on:
jobs:
ops-int-test:
runs-on: ubuntu-latest
environment: ci
environment: local

steps:
- name: Checkout
- name: Checkout credbull-defi
uses: actions/checkout@v4

- name: Install yarn
Expand All @@ -44,17 +44,45 @@ jobs:
- name: Install Project Dependencies
run: yarn install

- name: Run Ops tests
- name: Setup Local Environment
run: find . -type f -name ".env*.sample" -exec sh -c 'F={}; cp -nv $F $(dirname $F)/$(basename $F .sample)' \;

- name: Build Project
run: yarn build

- name: Setup Supabase CLI
uses: supabase/[email protected]
with:
version: latest

- name: Start Supabase
run: supabase start
working-directory: packages/api

- name: Run Docker Compose with Background Services
run: docker compose --env-file packages/api/.env up --detach --build --wait

- name: Deploy Credbull Contracts
run: yarn deploy
working-directory: packages/contracts

- name: Create Default Users
run: yarn op --create-default-users
working-directory: packages/ops

- name: Run Ops Integration Tests
run: yarn int-test
working-directory: packages/ops
env:
ENVIRONMENT: ${{ vars.ENVIRONMENT }}
DEPLOYER_PRIVATE_KEY: ${{ secrets.DEVOPS_SEPOLIA_DEPLOYER_PRIVATE_KEY }}
ADMIN_PRIVATE_KEY: ${{ secrets.DEVOPS_SEPOLIA_ADMIN_PRIVATE_KEY }}
ALICE_PRIVATE_KEY: ${{ secrets.DEVOPS_SEPOLIA_ALICE_PRIVATE_KEY }}
BOB_PRIVATE_KEY: ${{ secrets.DEVOPS_SEPOLIA_BOB_PRIVATE_KEY }}
SUPABASE_SERVICE_ROLE_KEY: ${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}
ADMIN_PASSWORD: NeverGuessThis
ALICE_PASSWORD: alice-1234
BOB_PASSWORD: bobword

- name: See API Logs, If Tests Failed
run: docker logs api
if: ${{ failure() }}

- name: Shutdown Docker Compose detached
run: docker compose --env-file packages/api/.env down
if: ${{ always() }}

- name: Stop Supabase
run: supabase stop --no-backup
working-directory: packages/api
if: ${{ always() }}
52 changes: 20 additions & 32 deletions .github/workflows/ci-dev-sdk.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,17 @@ on:
branches:
- "main*"
- "development*"
- "ops*"
paths:
- "packages/sdk/**"
- ".github/workflows/ci-dev-sdk.yml"

jobs:
sdk-int-test:
runs-on: ubuntu-latest
environment: testnet
environment: local

steps:
- name: Checkout
- name: Checkout credbull-defi
uses: actions/checkout@v4

- name: Install yarn
Expand All @@ -43,26 +42,12 @@ jobs:
- name: Install Project Dependencies
run: yarn install

- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Setup Local Environment
run: find . -type f -name ".env*.sample" -exec sh -c 'F={}; cp -nv $F $(dirname $F)/$(basename $F .sample)' \;
working-directory: .

# Docker compose detached (-d) so other jobs can continue
# Env variables are sourced and then exported (set -a)
- name: Run Docker compose detached
run: |
set -a
source packages/api/.env
set +a
docker-compose up -d --build
- name: Build Project
run: yarn build

# TODO: using local supabase for SDK.
# if we want a deployed instance, we need to set up a new one for the SDK.
- name: Setup Supabase CLI
uses: supabase/[email protected]
with:
Expand All @@ -72,6 +57,9 @@ jobs:
run: supabase start
working-directory: packages/api

- name: Run Docker Compose with Background Services
run: docker compose --env-file packages/api/.env up --detach --build --wait

- name: Deploy Credbull Contracts
run: yarn deploy
working-directory: packages/contracts
Expand All @@ -80,19 +68,19 @@ jobs:
run: yarn op --create-default-users
working-directory: packages/ops

- name: Logs
run: docker logs api --tail all

- name: Run SDK tests
run: |
set -a
source ../api/.env
source .env
set +a
yarn int-test
- name: Run SDK Integration Tests
run: yarn int-test
working-directory: packages/sdk

- name: Clean vault data
run: yarn op --clean-vault-table
working-directory: packages/ops
- name: See API Logs, If Tests Failed
run: docker logs api
if: ${{ failure() }}

- name: Shutdown Docker Compose detached
run: docker compose --env-file packages/api/.env down
if: ${{ always() }}

- name: Stop Supabase
run: supabase stop --no-backup
working-directory: packages/api
if: ${{ always() }}
17 changes: 4 additions & 13 deletions Dockerfile-api
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# syntax = docker/dockerfile:1

# Adjust NODE_VERSION as desired
ARG NODE_VERSION=20.11.0
ARG NODE_VERSION=20.15.0

FROM node:${NODE_VERSION}-slim as base
FROM node:${NODE_VERSION}-slim AS base

LABEL fly_launch_runtime="NestJS"

Expand All @@ -14,21 +14,12 @@ WORKDIR /app
ENV NODE_ENV="production"
ENV APP_PORT=3001



# Copy built application
# Copy already-built application.
COPY packages/contracts /app/contracts
COPY packages/api /app/api
COPY yarn.lock /app

# Start the server by default, this can be overwritten at runtime

WORKDIR /app
RUN yarn install

WORKDIR /app/api
RUN yarn build
EXPOSE 3001


CMD [ "yarn", "run", "start:prod" ]
CMD [ "node", "dist/src/main" ]
27 changes: 2 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: '3.8'
name: api-with-anvil

services:
anvil:
container_name: anvil
image: anvil
network_mode: "host"
platform: linux/amd64
build:
build:
context: .
dockerfile: Dockerfile-anvil

Expand All @@ -25,26 +25,3 @@ services:
SUPABASE_JWT_SECRET: ${SUPABASE_JWT_SECRET}
CRON_SECRET: ${CRON_SECRET}
SLACK_TOKEN: ${SLACK_TOKEN}

# depends_on:
# - supabase

# supabase:
# container_name: supabase
# image: public.ecr.aws/supabase/postgres:15.1.1.9
# ports:
# - 5432:5432
# environment:
# POSTGRES_PASSWORD: postgres
# POSTGRES_USER: postgres

# supabase-kong:
# container_name: supabase-kong
# image: public.ecr.aws/supabase/kong:2.8.1
# ports:
# - 54321:8000
# environment:
# POSTGRES_PASSWORD: postgres
# POSTGRES_USER: postgres

# docker build -f Dockerfile -t imagename ../..
18 changes: 9 additions & 9 deletions packages/sdk/test/src/utils/ops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@ import { Schema } from './schema';

export async function createFixedYieldVault(
config: any,
treasuryAddress: string,
activityRewardAddress: string,
collateralPercentage: number,
treasuryAddress?: string,
activityRewardAddress?: string,
collateralPercentage?: number,
): Promise<any> {
Schema.ADDRESS.parse(treasuryAddress);
Schema.ADDRESS.parse(activityRewardAddress);
Schema.PERCENTAGE.parse(collateralPercentage);
Schema.ADDRESS.optional().parse(treasuryAddress);
Schema.ADDRESS.optional().parse(activityRewardAddress);
Schema.PERCENTAGE.optional().parse(collateralPercentage);

const modifiedConfig = {
...config,
evm: {
...config.evm,
address: {
...config.evm.address,
treasury: treasuryAddress,
activity_reward: activityRewardAddress,
...(treasuryAddress ? { treasury: treasuryAddress } : {}),
...(activityRewardAddress ? { activity_reward: activityRewardAddress } : {}),
},
},
operation: {
...config.operation,
createVault: {
...config.operation.createVault,
collateral_percentage: collateralPercentage,
...(collateralPercentage ? { collateral_percentage: collateralPercentage } : {}),
},
},
};
Expand Down

0 comments on commit 95e7823

Please sign in to comment.