From 57d4bb52ca914ae3ae941a779a4deb4b3f6d8257 Mon Sep 17 00:00:00 2001 From: "Sebastijan K." <58827427+sebastijankuzner@users.noreply.github.com> Date: Tue, 5 Nov 2024 11:48:06 +0100 Subject: [PATCH] ci: add build workflow (#752) * Add build workflow * style: resolve style guide violations * Rename test * Reorganize unit test * Run on build completed * Wait for build * Rename file * Create single file * Fix key --------- Co-authored-by: sebastijankuzner --- .github/workflows/e2e.yml | 84 --------- .github/workflows/integration.yml | 68 -------- .github/workflows/{unit.yml => test.yml} | 212 +++++++++++++++++++++-- 3 files changed, 199 insertions(+), 165 deletions(-) delete mode 100644 .github/workflows/e2e.yml delete mode 100644 .github/workflows/integration.yml rename .github/workflows/{unit.yml => test.yml} (55%) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml deleted file mode 100644 index 75b6d0e96..000000000 --- a/.github/workflows/e2e.yml +++ /dev/null @@ -1,84 +0,0 @@ -name: CI - -on: - push: - branches: - - "main" - - "develop" - pull_request: - types: [ready_for_review, synchronize, opened] - -jobs: - e2e: - concurrency: - cancel-in-progress: true - group: ${{ github.head_ref }}-e2e-${{ matrix.name }} - runs-on: ubuntu-latest - - timeout-minutes: 10 - - strategy: - matrix: - node-version: [20.x] - name: ["consensus"] - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - name: Setup pnpm - uses: pnpm/action-setup@v4 - with: - run_install: false - version: latest - - name: Get pnpm store directory - id: pnpm-cache - run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - shell: bash - - name: Cache pnpm modules - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - restore-keys: ${{ runner.os }}-pnpm- - - name: Cache lerna - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-lerna - path: ./.cache - restore-keys: ${{ runner.os }}-lerna- - - name: Install dependencies - run: pnpm install - - name: Build - run: pnpm run build - - - name: Docker ${{ matrix.name }} - run: sudo chmod -R 777 tests/e2e/${{ matrix.name }}/nodes && cd tests/e2e/${{ matrix.name }} && docker compose up -d - - - name: Running checks for ${{ matrix.name }} - run: | - container_id=$(docker ps -a | grep 'consensus-checks' | awk '{print $1}') - while docker ps | grep -q $container_id; do echo "checks running..."; sleep 5; done - exit_code=$(docker container inspect $container_id --format='{{.State.ExitCode}}') - if [ "$exit_code" != "0" ]; then - echo "Error: checks exited with code $exit_code" - exit 1 - fi - - name: Show logs - node0 - if: always() - run: docker logs consensus-node0-1 - - name: Show logs - node1 - if: always() - run: docker logs consensus-node1-1 - - name: Show logs - node2 - if: always() - run: docker logs consensus-node2-1 - - name: Show logs - node3 - if: always() - run: docker logs consensus-node3-1 - - name: Show logs - node4 - if: always() - run: docker logs consensus-node4-1 diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml deleted file mode 100644 index aa4d70e14..000000000 --- a/.github/workflows/integration.yml +++ /dev/null @@ -1,68 +0,0 @@ -jobs: - integration: - concurrency: - cancel-in-progress: true - group: ${{ github.head_ref }}-integration - runs-on: ubuntu-latest - - services: - postgres: - image: postgres:16 - env: - POSTGRES_DB: test_db - POSTGRES_USER: test_db - POSTGRES_PASSWORD: password - ports: - - 127.0.0.1:5432:5432 - options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 - - steps: - - uses: actions/checkout@v4 - with: - ref: ${{ github.head_ref }} - - uses: actions/setup-node@v4 - with: - node-version: ${{ matrix.node-version }} - - name: Setup pnpm - uses: pnpm/action-setup@v4 - with: - run_install: false - version: latest - - name: Get pnpm store directory - id: pnpm-cache - run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - shell: bash - - name: Cache pnpm modules - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} - path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} - restore-keys: ${{ runner.os }}-pnpm- - - name: Cache lerna - uses: actions/cache@v4 - with: - key: ${{ runner.os }}-lerna - path: ./.cache - restore-keys: ${{ runner.os }}-lerna- - - name: Install dependencies - run: pnpm install - - name: Build - run: pnpm run build - - - name: Test api-http - run: cd packages/api-http && pnpm run test:integration - strategy: - matrix: - node-version: - - 20.x -name: CI -on: - pull_request: - types: - - ready_for_review - - synchronize - - opened - push: - branches: - - main - - develop diff --git a/.github/workflows/unit.yml b/.github/workflows/test.yml similarity index 55% rename from .github/workflows/unit.yml rename to .github/workflows/test.yml index 613ad7609..e249de8e7 100644 --- a/.github/workflows/unit.yml +++ b/.github/workflows/test.yml @@ -1,5 +1,72 @@ +name: Test + +on: + pull_request: + types: + - ready_for_review + - synchronize + - opened + push: + branches: + - main + - develop + jobs: + build: + strategy: + matrix: + node-version: + - 20.x + concurrency: + cancel-in-progress: true + group: ${{ github.head_ref }}-unit + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + run_install: false + version: latest + + - name: Get pnpm store directory + id: pnpm-cache + run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + shell: bash + + - name: Cache pnpm modules + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + restore-keys: ${{ runner.os }}-pnpm- + + - name: Cache lerna + uses: actions/cache@v4 + with: + key: lerna-${{ runner.os }}-${{ github.run_id }} + path: ./.cache + restore-keys: lerna-${{ runner.os }} + + - name: Install dependencies + run: pnpm install + - name: Build + run: pnpm run build + unit: + needs: + - build + strategy: + matrix: + node-version: + - 20.x concurrency: cancel-in-progress: true group: ${{ github.head_ref }}-unit @@ -29,9 +96,9 @@ jobs: - name: Cache lerna uses: actions/cache@v4 with: - key: ${{ runner.os }}-lerna + key: lerna-${{ runner.os }} path: ./.cache - restore-keys: ${{ runner.os }}-lerna- + restore-keys: lerna-${{ runner.os }}- - name: Install dependencies run: pnpm install - name: Build @@ -164,18 +231,137 @@ jobs: # run: cd packages/validator && pnpm run test - name: Test webhooks run: cd packages/webhooks && pnpm run test + + integration: + needs: + - build strategy: matrix: node-version: - 20.x -name: CI -on: - pull_request: - types: - - ready_for_review - - synchronize - - opened - push: - branches: - - main - - develop + concurrency: + cancel-in-progress: true + group: ${{ github.head_ref }}-integration + runs-on: ubuntu-latest + services: + postgres: + image: postgres:16 + env: + POSTGRES_DB: test_db + POSTGRES_USER: test_db + POSTGRES_PASSWORD: password + ports: + - 127.0.0.1:5432:5432 + options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + run_install: false + version: latest + - name: Get pnpm store directory + id: pnpm-cache + run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + shell: bash + - name: Cache pnpm modules + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + restore-keys: ${{ runner.os }}-pnpm- + - name: Cache lerna + uses: actions/cache@v4 + with: + key: lerna-${{ runner.os }} + path: ./.cache + restore-keys: lerna-${{ runner.os }}- + - name: Install dependencies + run: pnpm install + - name: Build + run: pnpm run build + + - name: Test api-http + run: cd packages/api-http && pnpm run test:integration + + e2e: + needs: + - build + concurrency: + cancel-in-progress: true + group: ${{ github.head_ref }}-e2e-${{ matrix.name }} + runs-on: ubuntu-latest + + timeout-minutes: 10 + + strategy: + matrix: + node-version: [20.x] + name: ["consensus"] + + steps: + - uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + - uses: actions/setup-node@v4 + with: + node-version: ${{ matrix.node-version }} + - name: Setup pnpm + uses: pnpm/action-setup@v4 + with: + run_install: false + version: latest + - name: Get pnpm store directory + id: pnpm-cache + run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT + shell: bash + - name: Cache pnpm modules + uses: actions/cache@v4 + with: + key: ${{ runner.os }}-pnpm-${{ hashFiles('**/pnpm-lock.yaml') }} + path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} + restore-keys: ${{ runner.os }}-pnpm- + - name: Cache lerna + uses: actions/cache@v4 + with: + key: lerna-${{ runner.os }} + path: ./.cache + restore-keys: lerna-${{ runner.os }}- + - name: Install dependencies + run: pnpm install + - name: Build + run: pnpm run build + + - name: Docker ${{ matrix.name }} + run: sudo chmod -R 777 tests/e2e/${{ matrix.name }}/nodes && cd tests/e2e/${{ matrix.name }} && docker compose up -d + + - name: Running checks for ${{ matrix.name }} + run: | + container_id=$(docker ps -a | grep 'consensus-checks' | awk '{print $1}') + while docker ps | grep -q $container_id; do echo "checks running..."; sleep 5; done + exit_code=$(docker container inspect $container_id --format='{{.State.ExitCode}}') + if [ "$exit_code" != "0" ]; then + echo "Error: checks exited with code $exit_code" + exit 1 + fi + - name: Show logs - node0 + if: always() + run: docker logs consensus-node0-1 + - name: Show logs - node1 + if: always() + run: docker logs consensus-node1-1 + - name: Show logs - node2 + if: always() + run: docker logs consensus-node2-1 + - name: Show logs - node3 + if: always() + run: docker logs consensus-node3-1 + - name: Show logs - node4 + if: always() + run: docker logs consensus-node4-1