Skip to content

Commit

Permalink
ci: add build workflow (#752)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
sebastijankuzner and sebastijankuzner authored Nov 5, 2024
1 parent c1d539a commit 57d4bb5
Show file tree
Hide file tree
Showing 3 changed files with 199 additions and 165 deletions.
84 changes: 0 additions & 84 deletions .github/workflows/e2e.yml

This file was deleted.

68 changes: 0 additions & 68 deletions .github/workflows/integration.yml

This file was deleted.

212 changes: 199 additions & 13 deletions .github/workflows/unit.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

0 comments on commit 57d4bb5

Please sign in to comment.