console/.github/workflows/ci.yaml
Dimitri POSTOLOV 12ceda69dc
Use pnpm instead of yarn (#477)
Co-authored-by: enisdenjo <badurinadenis@gmail.com>
Co-authored-by: Denis Badurina <denis@domonda.com>
2022-11-01 02:11:53 +02:00

596 lines
16 KiB
YAML

name: CI
on: [pull_request]
jobs:
setup:
name: Setup
runs-on: ubuntu-latest
timeout-minutes: 10
services:
postgres:
image: postgres:13.1-alpine
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: registry
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
outputs:
hive_token_present: ${{ steps.secrets_present.outputs.hive_token }}
env:
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: registry
HIVE_TOKEN: ${{ secrets.HIVE_TOKEN }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
cache: pnpm
- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Create Database
working-directory: packages/services/storage
run: pnpm db:create
- name: Migrate Database
working-directory: packages/services/storage
run: pnpm db:migrator up
- name: Generate Database Types
working-directory: packages/services/storage
run: pnpm db:generate
- name: Check if DB types were modified
run: git diff --exit-code ./packages/services/storage/src/db/types.ts
continue-on-error: true
- name: Share node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: Check for Presence of Repository Secrets
id: secrets_present
run: echo "::set-output name=hive_token::${{ env.HIVE_TOKEN != '' }}"
schema-check:
name: Schema Check
runs-on: ubuntu-latest
needs: setup
if: needs.setup.outputs.hive_token_present == 'true'
timeout-minutes: 5
env:
HIVE_TOKEN: ${{ secrets.HIVE_TOKEN }}
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 5
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Pull node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: Generate Types
run: pnpm graphql:generate
- name: Check PR label
if: contains(github.event.pull_request.labels.*.name, 'non-breaking')
run: echo '::set-output name=SAFE_FLAG::--forceSafe'
id: pr-label-check
- name: Schema Check
run: ./packages/libraries/cli/bin/dev schema:check "packages/services/api/src/modules/*/module.graphql.ts" ${{ steps.pr-label-check.outputs.SAFE_FLAG }} --github
test:
name: Tests
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 5
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 1
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Pull node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: Generate Types
run: pnpm graphql:generate
- name: Test
run: pnpm test
build:
name: Build
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 15
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 5
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Pull node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: Setup Turbo
run: node ./scripts/turborepo-setup.js
- name: Generate Types
run: pnpm graphql:generate
- name: Build
run: pnpm build
- name: Archive @hive/app
run: zip -r packages/web/app/dist.zip packages/web/app/dist
- uses: actions/upload-artifact@v3
name: Upload Docker Build Artifacts
if: ${{ !github.event.pull_request.head.repo.fork }}
with:
name: docker-build-sources
path: |
docker.hcl
services.dockerfile
app.dockerfile
packages/services/emails/dist
packages/services/rate-limit/dist
packages/services/schema/dist
packages/services/server/dist
packages/services/storage/dist
packages/services/stripe-billing/dist
packages/services/tokens/dist
packages/services/usage-estimator/dist
packages/services/usage-ingestor/dist
packages/services/usage/dist
packages/services/webhooks/dist
packages/web/app/dist.zip
rust:
name: Build Rust
runs-on: ubuntu-latest
timeout-minutes: 40
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 2
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
cache: pnpm
- name: Install dependencies
run: pnpm i --frozen-lockfile
- name: Install Rust
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y
rustup target add x86_64-unknown-linux-gnu
- name: Cache Rust
uses: Swatinem/rust-cache@v1
with:
key: rust_linux_cross
- name: Build
run: cargo build --target x86_64-unknown-linux-gnu --release
- name: Strip binary from debug symbols
run: strip target/x86_64-unknown-linux-gnu/release/router
- name: Compress
run: ./target/x86_64-unknown-linux-gnu/release/compress ./target/x86_64-unknown-linux-gnu/release/router ./router.tar.gz
- name: Upload artifact
uses: actions/upload-artifact@v3
with:
name: router-linux
path: target/x86_64-unknown-linux-gnu/release/router
lint:
name: Lint
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 25
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 5
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Pull node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: ESLint cache
uses: actions/cache@v2
with:
path: '.eslintcache'
key: ${{ runner.os }}-eslint-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-eslint
- name: Setup Turbo
run: node ./scripts/turborepo-setup.js
- name: Generate Types
run: pnpm graphql:generate
- name: Type Check
run: pnpm typecheck
- name: Lint ESLint
run: pnpm lint
- name: Lint Prettier
run: pnpm lint:prettier
docker-build-push:
needs: build
runs-on: ubuntu-latest
timeout-minutes: 40
if: ${{ !github.event.pull_request.head.repo.fork }}
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
permissions:
contents: read
packages: write
steps:
- uses: actions/download-artifact@v3
with:
name: docker-build-sources
path: ./
- name: Unarchive @hive/app
run: unzip packages/web/app/dist.zip
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
with:
platforms: 'linux/arm64,linux/amd64'
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v6
- uses: frabert/replace-string-action@v2.0
id: branch_name_fix
with:
pattern: '(\/|-)'
string: ${{ steps.branch-name.outputs.current_branch }}
replace-with: '_'
- name: Build Docker Images
env:
DOCKER_REGISTRY: ${{ env.REGISTRY }}/${{ github.repository }}/
COMMIT_SHA: ${{ github.sha }}
RELEASE: ${{ github.sha }}
BRANCH_NAME: ${{ steps.branch_name_fix.outputs.replaced }}
BUILD_TYPE: 'publish'
run: |
docker buildx bake \
-f docker.hcl \
build --push
integration-tests:
name: Integration Tests
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 25
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
DOCKER_REGISTRY: ghcr.io/${{ github.repository }}/
DOCKER_TAG: :${{ github.sha }}
steps:
- name: Check out repository code
uses: actions/checkout@v3
with:
fetch-depth: 5
- name: Install pnpm
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Pull node_modules
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: Setup Turbo
run: node ./scripts/turborepo-setup.js
- name: Build
run: pnpm --filter integration-tests build-and-pack
- name: Build
run: pnpm build
- name: Pull images
run: |
docker-compose -f integration-tests/docker-compose.yml pull \
db \
clickhouse \
zookeeper \
broker \
redis \
supertokens \
local_cdn \
external_composition
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Images
env:
COMMIT_SHA: ${{ github.sha }}
RELEASE: ${{ github.sha }}
BUILD_TYPE: 'ci'
run: |
docker buildx bake \
-f docker.hcl \
build \
--load
- name: Integration Tests
run: pnpm --filter integration-tests dockest
timeout-minutes: 15
env:
STRIPE_PUBLIC_KEY: ${{ secrets.TEST_STRIPE_PUBLIC_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
SUPERTOKENS_CONNECTION_URI: http://127.0.0.1:3567
SUPERTOKENS_API_KEY: bubatzbieber6942096420
EXTERNAL_COMPOSITION_SECRET: secretsecret
- name: Dockest logs
if: always()
run: cat integration-tests/*.log
integration-tests-ff:
name: Integration Tests (with Feature Flags enabled)
runs-on: ubuntu-latest
needs: setup
timeout-minutes: 25
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ secrets.TURBO_TEAM }}
TURBO_API_URL: ${{ secrets.TURBO_API_URL }}
TURBO_REMOTE_ONLY: 'true'
DOCKER_REGISTRY: ghcr.io/${{ github.repository }}/
DOCKER_TAG: :${{ github.sha }}
# Feature Flags
FF_CLICKHOUSE_V2_TABLES: '1'
steps:
- name: Detect feature flags
id: feature_flags
run: |
total=$(env | grep "FF_.*" -c)
if [ $total -gt 0 ]; then
echo '::set-output name=detected::true'
fi
- name: Check out repository code
if: steps.feature_flags.outputs.detected == 'true'
uses: actions/checkout@v3
with:
fetch-depth: 5
- name: Install pnpm
if: steps.feature_flags.outputs.detected == 'true'
uses: pnpm/action-setup@v2.2.4
with:
version: 7
- name: Install Node
if: steps.feature_flags.outputs.detected == 'true'
uses: actions/setup-node@v3
with:
node-version-file: .node-version
- name: Pull node_modules
if: steps.feature_flags.outputs.detected == 'true'
uses: actions/cache@v2
with:
path: '**/node_modules'
key: ${{ github.sha }}
- name: Setup Turbo
if: steps.feature_flags.outputs.detected == 'true'
run: node ./scripts/turborepo-setup.js
- name: Build
if: steps.feature_flags.outputs.detected == 'true'
run: pnpm --filter integration-tests build-and-pack
- name: Build
if: steps.feature_flags.outputs.detected == 'true'
run: pnpm build
- name: Pull images
if: steps.feature_flags.outputs.detected == 'true'
run: |
docker-compose -f integration-tests/docker-compose.yml pull \
db \
clickhouse \
zookeeper \
broker \
redis \
supertokens \
local_cdn \
external_composition
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build Docker Images
env:
COMMIT_SHA: ${{ github.sha }}
RELEASE: ${{ github.sha }}
BUILD_TYPE: 'ci'
run: |
docker buildx bake \
-f docker.hcl \
build \
--load
- name: Integration Tests
if: steps.feature_flags.outputs.detected == 'true'
run: pnpm --filter integration-tests dockest
timeout-minutes: 15
env:
STRIPE_PUBLIC_KEY: ${{ secrets.TEST_STRIPE_PUBLIC_KEY }}
STRIPE_SECRET_KEY: ${{ secrets.TEST_STRIPE_SECRET_KEY }}
SUPERTOKENS_CONNECTION_URI: http://127.0.0.1:3567
SUPERTOKENS_API_KEY: bubatzbieber6942096420
EXTERNAL_COMPOSITION_SECRET: secretsecret
- name: Dockest logs
if: steps.feature_flags.outputs.detected == 'true' && always()
run: cat integration-tests/*.log