Bläddra i källkod

re-add test CI

Shahed Nasser 1 år sedan
förälder
incheckning
098b691007
2 ändrade filer med 178 tillägg och 0 borttagningar
  1. 29 0
      .github/scripts/wait-for-server-live.sh
  2. 149 0
      .github/workflows/test-cli.yml

+ 29 - 0
.github/scripts/wait-for-server-live.sh

@@ -0,0 +1,29 @@
+#!/bin/bash
+
+for i in {1..6}
+do
+  echo $i
+  status_code=$(curl \
+    -X GET \
+    --write-out %{http_code} \
+    --silent\
+    --output /dev/null\
+    http://localhost:9000/store/products)
+
+echo $status_code
+  if [[ "$status_code" -ne 000 ]] ; then
+    echo "exiting"
+    exit 0
+  else
+    sleep 5
+  fi
+done
+
+echo $status_code
+
+if [[ "$status_code" =  000 ]] ; then
+  echo "Site status changed to $status_code"
+  exit 1
+else
+  exit 0
+fi

+ 149 - 0
.github/workflows/test-cli.yml

@@ -0,0 +1,149 @@
+name: Test CLI
+on:
+ pull_request:
+  branches:
+    - 'feat/v2'
+    - 'feat/v2-ci'
+
+jobs:
+  test-cli-yarn:
+    name: "Test CLI (Yarn)"
+    env:
+      NODE_ENV: CI
+      REDIS_URL: redis://localhost:6379
+      DATABASE_URL: "postgres://postgres:postgres@localhost/cli-test"
+      POSTGRES_URL: "postgres://postgres:postgres@localhost/cli-test"
+    services:
+      redis:
+        image: redis
+        options: >-
+          --health-cmd "redis-cli ping"
+          --health-interval 10s
+          --health-timeout 5s
+          --health-retries 5
+        ports:
+          - 6379:6379
+ 
+      postgres:
+        image: postgres
+        env:
+          POSTGRES_PASSWORD: postgres
+          POSTGRES_USER: postgres
+          POSTGRES_DB: cli-test
+        options: >-
+          --health-cmd pg_isready
+          --health-interval 10s
+          --health-timeout 5s
+          --health-retries 5
+        ports:
+          - 5432:5432
+ 
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
+
+      - name: Cancel Previous Runs
+        uses: styfle/cancel-workflow-action@0.11.0
+        with:
+          access_token: ${{ github.token }}
+
+      - name: Setup Node.js environment
+        uses: actions/setup-node@v3
+        with:
+          node-version: 20
+  
+      - name: Install Dependencies
+        run: yarn install
+
+      - name: Check CLI tool is installed
+        run: ./node_modules/.bin/medusa -v
+
+      - name: run build
+        run: yarn build
+
+      - name: Run migrations
+        run: npx medusa migrations run
+
+      - name: Run seed
+        run: yarn seed
+
+      - name: Run development server
+        run: yarn dev &
+
+      - name: Wait for live server response
+        shell: "bash"
+        run: ./.github/scripts/wait-for-server-live.sh
+
+      - name: Kill server
+        shell: "bash"
+        run: kill -9 $(lsof -t -i :9000)
+          
+  test-cli-npm:
+    name: "Test CLI (npm)"
+    env:
+      NODE_ENV: CI
+      REDIS_URL: redis://localhost:6379
+      DATABASE_URL: "postgres://postgres:postgres@localhost/cli-test"
+      POSTGRES_URL: "postgres://postgres:postgres@localhost/cli-test"
+    services: 
+      postgres:
+        image: postgres
+        env:
+          POSTGRES_PASSWORD: postgres
+          POSTGRES_USER: postgres
+          POSTGRES_DB: cli-test
+        options: >-
+          --health-cmd pg_isready
+          --health-interval 10s
+          --health-timeout 5s
+          --health-retries 5
+        ports:
+          - 5432:5432
+ 
+    runs-on: ubuntu-latest
+    steps:
+      - name: Checkout
+        uses: actions/checkout@v3
+        with:
+          fetch-depth: 0
+
+      - name: Cancel Previous Runs
+        uses: styfle/cancel-workflow-action@0.11.0
+        with:
+          access_token: ${{ github.token }}
+
+      - name: Setup Node.js environment
+        uses: actions/setup-node@v3
+        with:
+          node-version: 20
+          cache: "npm"
+  
+      - name: Install Dependencies
+        run: npm install
+
+      - name: Check CLI tool is installed
+        run: ./node_modules/.bin/medusa -v
+
+      - name: run medusa build
+        run: npm run build
+
+      - name: Run migrations
+        run: npx medusa migrations run
+
+      - name: Run seed
+        run: npm run seed
+
+      - name: Run development server
+        run: npm run dev -- &
+
+      - name: Wait for live server response
+        shell: "bash"
+        run: ./.github/scripts/wait-for-server-live.sh
+
+      - name: Kill server
+        shell: "bash"
+        run: kill -9 $(lsof -t -i :9000)
+