From d5e5bb6a2133bb7468f35d9f5a5d11c9efefd99a Mon Sep 17 00:00:00 2001 From: kimcascante Date: Fri, 29 Aug 2025 19:58:37 -0600 Subject: [PATCH 1/2] feat: Add comprehensive CI/CD pipeline - Add CI workflow for frontend and contracts testing - Add deployment workflow for automatic deployment - Add security and code quality analysis workflow - Fix Vitest configuration for Next.js compatibility - Update Scarb.toml dependencies to resolve version conflicts - All CI checks pass locally (format, lint, types, tests, build) --- .github/workflows/ci.yml | 201 ++++++++++++++++++++++++ .github/workflows/deploy.yml | 90 +++++++++++ .github/workflows/security.yml | 110 +++++++++++++ packages/nextjs/vitest.config.ts | 4 +- packages/snfoundry/contracts/Scarb.toml | 2 +- 5 files changed, 404 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/security.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..b4de461 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,201 @@ +name: CI + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + +env: + NODE_VERSION: '18' + YARN_VERSION: '3.2.3' + +jobs: + # Job para el frontend (Next.js) + frontend: + name: Frontend Tests & Build + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint frontend + run: yarn next:lint + working-directory: packages/nextjs + + - name: Check TypeScript types + run: yarn next:check-types + working-directory: packages/nextjs + + - name: Run frontend tests + run: yarn test:nextjs + working-directory: packages/nextjs + + - name: Build frontend + run: yarn build + working-directory: packages/nextjs + + # Job para los contratos (Cairo/Starknet) + contracts: + name: Contracts Tests & Compilation + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Scarb + uses: actions-rs/install@v0.1 + with: + crate: scarb + use-tool-cache: true + + - name: Install Starknet Foundry + uses: actions-rs/install@v0.1 + with: + crate: snforge + use-tool-cache: true + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Check formatting + run: yarn format:check + + - name: Compile contracts + run: yarn compile + working-directory: packages/snfoundry + + - name: Run contract tests + run: yarn test + working-directory: packages/snfoundry + + # Job para tests generales del proyecto + tests: + name: All Tests + runs-on: ubuntu-latest + needs: [frontend, contracts] + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Scarb + uses: actions-rs/install@v0.1 + with: + crate: scarb + use-tool-cache: true + + - name: Install Starknet Foundry + uses: actions-rs/install@v0.1 + with: + crate: snforge + use-tool-cache: true + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run contract tests + run: yarn test + working-directory: packages/snfoundry + + - name: Run frontend tests + run: yarn test:nextjs + working-directory: packages/nextjs + + # Job para verificación de formato + format-check: + name: Format Check + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Scarb + uses: actions-rs/install@v0.1 + with: + crate: scarb + use-tool-cache: true + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Check formatting + run: yarn format:check + + # Job para linting general + lint: + name: Lint Check + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Lint frontend + run: yarn next:lint + working-directory: packages/nextjs + + - name: Check TypeScript types + run: yarn next:check-types + working-directory: packages/nextjs diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..1687b2f --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,90 @@ +name: Deploy + +on: + push: + branches: [ main ] + +env: + NODE_VERSION: '18' + +jobs: + deploy-frontend: + name: Deploy Frontend + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Build frontend + run: yarn build + working-directory: packages/nextjs + + # Si usas Vercel, puedes descomentar estas líneas + # - name: Deploy to Vercel + # uses: amondnet/vercel-action@v25 + # with: + # vercel-token: ${{ secrets.VERCEL_TOKEN }} + # vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} + # vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} + # working-directory: ./packages/nextjs + + deploy-contracts: + name: Deploy Contracts + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/main' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Scarb + uses: actions-rs/install@v0.1 + with: + crate: scarb + use-tool-cache: true + + - name: Install Starknet Foundry + uses: actions-rs/install@v0.1 + with: + crate: snforge + use-tool-cache: true + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Compile contracts + run: yarn compile + working-directory: packages/snfoundry + + # Descomenta estas líneas si quieres deploy automático de contratos + # - name: Deploy contracts + # run: yarn deploy + # working-directory: packages/snfoundry + # env: + # PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + # RPC_URL: ${{ secrets.RPC_URL }} diff --git a/.github/workflows/security.yml b/.github/workflows/security.yml new file mode 100644 index 0000000..e30714d --- /dev/null +++ b/.github/workflows/security.yml @@ -0,0 +1,110 @@ +name: Security & Code Quality + +on: + push: + branches: [ main, develop ] + pull_request: + branches: [ main, develop ] + schedule: + # Ejecutar análisis de seguridad semanalmente + - cron: '0 2 * * 1' + +env: + NODE_VERSION: '18' + +jobs: + security-audit: + name: Security Audit + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Run npm audit + run: yarn audit + continue-on-error: true + + - name: Run Snyk security scan + uses: snyk/actions/node@master + env: + SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }} + with: + args: --severity-threshold=high + continue-on-error: true + + code-quality: + name: Code Quality Analysis + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: ${{ env.NODE_VERSION }} + cache: 'yarn' + cache-dependency-path: '**/yarn.lock' + + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + + - name: Install Scarb + uses: actions-rs/install@v0.1 + with: + crate: scarb + use-tool-cache: true + + - name: Install dependencies + run: yarn install --frozen-lockfile + + - name: Check code formatting + run: yarn format:check + + - name: Lint frontend code + run: yarn next:lint + working-directory: packages/nextjs + + - name: Check TypeScript types + run: yarn next:check-types + working-directory: packages/nextjs + + - name: Run SonarCloud analysis + uses: SonarSource/sonarcloud-github-action@master + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: > + -Dsonar.projectKey=your-project-key + -Dsonar.organization=your-organization + continue-on-error: true + + dependency-review: + name: Dependency Review + runs-on: ubuntu-latest + if: github.event_name == 'pull_request' + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Dependency Review + uses: actions/dependency-review-action@v4 + with: + fail-on-severity: moderate diff --git a/packages/nextjs/vitest.config.ts b/packages/nextjs/vitest.config.ts index 0744653..70f0716 100644 --- a/packages/nextjs/vitest.config.ts +++ b/packages/nextjs/vitest.config.ts @@ -1,9 +1,9 @@ +/// import { defineConfig } from "vitest/config"; -import path from "path"; import react from "@vitejs/plugin-react"; +import path from "path"; export default defineConfig({ - // @ts-ignore plugins: [react()], test: { environment: "jsdom", diff --git a/packages/snfoundry/contracts/Scarb.toml b/packages/snfoundry/contracts/Scarb.toml index 7b8bc68..798bd0b 100644 --- a/packages/snfoundry/contracts/Scarb.toml +++ b/packages/snfoundry/contracts/Scarb.toml @@ -13,7 +13,7 @@ openzeppelin_token = "2.0.0" [dev-dependencies] openzeppelin_utils = "2.0.0" openzeppelin_testing = "4.3.0" -snforge_std = "0.42.0" +snforge_std = "0.46.0" assert_macros = "2.11.4" [[target.starknet-contract]] From cbc8e94050f6ac949eac31762e0fceef732c1f1c Mon Sep 17 00:00:00 2001 From: kimcascante Date: Fri, 29 Aug 2025 20:23:22 -0600 Subject: [PATCH 2/2] fix: Simplify CI/CD to single job - reduce complexity and fix errors --- .github/workflows/ci.yml | 159 ++++------------------------------- .github/workflows/deploy.yml | 55 +----------- 2 files changed, 19 insertions(+), 195 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4de461..e3cdbee 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -8,12 +8,10 @@ on: env: NODE_VERSION: '18' - YARN_VERSION: '3.2.3' jobs: - # Job para el frontend (Next.js) - frontend: - name: Frontend Tests & Build + test-and-build: + name: Test & Build runs-on: ubuntu-latest steps: @@ -27,40 +25,6 @@ jobs: cache: 'yarn' cache-dependency-path: '**/yarn.lock' - - name: Install dependencies - run: yarn install --frozen-lockfile - - - name: Lint frontend - run: yarn next:lint - working-directory: packages/nextjs - - - name: Check TypeScript types - run: yarn next:check-types - working-directory: packages/nextjs - - - name: Run frontend tests - run: yarn test:nextjs - working-directory: packages/nextjs - - - name: Build frontend - run: yarn build - working-directory: packages/nextjs - - # Job para los contratos (Cairo/Starknet) - contracts: - name: Contracts Tests & Compilation - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'yarn' - - name: Install Rust uses: actions-rs/toolchain@v1 with: @@ -85,117 +49,26 @@ jobs: - name: Check formatting run: yarn format:check - - name: Compile contracts - run: yarn compile - working-directory: packages/snfoundry - - - name: Run contract tests - run: yarn test - working-directory: packages/snfoundry - - # Job para tests generales del proyecto - tests: - name: All Tests - runs-on: ubuntu-latest - needs: [frontend, contracts] - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'yarn' - cache-dependency-path: '**/yarn.lock' - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Install Scarb - uses: actions-rs/install@v0.1 - with: - crate: scarb - use-tool-cache: true - - - name: Install Starknet Foundry - uses: actions-rs/install@v0.1 - with: - crate: snforge - use-tool-cache: true - - - name: Install dependencies - run: yarn install --frozen-lockfile + - name: Lint frontend + run: yarn next:lint + working-directory: packages/nextjs - - name: Run contract tests - run: yarn test - working-directory: packages/snfoundry + - name: Check TypeScript types + run: yarn next:check-types + working-directory: packages/nextjs - name: Run frontend tests run: yarn test:nextjs working-directory: packages/nextjs - # Job para verificación de formato - format-check: - name: Format Check - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'yarn' - cache-dependency-path: '**/yarn.lock' - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Install Scarb - uses: actions-rs/install@v0.1 - with: - crate: scarb - use-tool-cache: true - - - name: Install dependencies - run: yarn install --frozen-lockfile - - - name: Check formatting - run: yarn format:check - - # Job para linting general - lint: - name: Lint Check - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'yarn' - cache-dependency-path: '**/yarn.lock' - - - name: Install dependencies - run: yarn install --frozen-lockfile + - name: Compile contracts + run: yarn compile + working-directory: packages/snfoundry - - name: Lint frontend - run: yarn next:lint - working-directory: packages/nextjs + - name: Run contract tests + run: yarn test + working-directory: packages/snfoundry - - name: Check TypeScript types - run: yarn next:check-types + - name: Build frontend + run: yarn build working-directory: packages/nextjs diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1687b2f..94247c2 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -8,8 +8,8 @@ env: NODE_VERSION: '18' jobs: - deploy-frontend: - name: Deploy Frontend + deploy: + name: Deploy runs-on: ubuntu-latest if: github.ref == 'refs/heads/main' @@ -31,7 +31,7 @@ jobs: run: yarn build working-directory: packages/nextjs - # Si usas Vercel, puedes descomentar estas líneas + # Descomenta para deploy automático a Vercel # - name: Deploy to Vercel # uses: amondnet/vercel-action@v25 # with: @@ -39,52 +39,3 @@ jobs: # vercel-org-id: ${{ secrets.VERCEL_ORG_ID }} # vercel-project-id: ${{ secrets.VERCEL_PROJECT_ID }} # working-directory: ./packages/nextjs - - deploy-contracts: - name: Deploy Contracts - runs-on: ubuntu-latest - if: github.ref == 'refs/heads/main' - - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: ${{ env.NODE_VERSION }} - cache: 'yarn' - cache-dependency-path: '**/yarn.lock' - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - - name: Install Scarb - uses: actions-rs/install@v0.1 - with: - crate: scarb - use-tool-cache: true - - - name: Install Starknet Foundry - uses: actions-rs/install@v0.1 - with: - crate: snforge - use-tool-cache: true - - - name: Install dependencies - run: yarn install --frozen-lockfile - - - name: Compile contracts - run: yarn compile - working-directory: packages/snfoundry - - # Descomenta estas líneas si quieres deploy automático de contratos - # - name: Deploy contracts - # run: yarn deploy - # working-directory: packages/snfoundry - # env: - # PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} - # RPC_URL: ${{ secrets.RPC_URL }}