feat: Add CI environment setup and verification workflows with Docker support
Some checks failed
Test / test-frontend (pull_request) Successful in 43s
Test / lint-frontend (pull_request) Successful in 47s
Verify / get-ci-image (pull_request) Successful in 47s
Test / frontend-build (pull_request) Successful in 1m29s
Verify / verify-generated-db-entities (pull_request) Has been cancelled
Test / test-crates (pull_request) Has been cancelled
Test / lint-crates (pull_request) Has been cancelled
Some checks failed
Test / test-frontend (pull_request) Successful in 43s
Test / lint-frontend (pull_request) Successful in 47s
Verify / get-ci-image (pull_request) Successful in 47s
Test / frontend-build (pull_request) Successful in 1m29s
Verify / verify-generated-db-entities (pull_request) Has been cancelled
Test / test-crates (pull_request) Has been cancelled
Test / lint-crates (pull_request) Has been cancelled
This commit is contained in:
54
.github/workflows/build-ci.yaml
vendored
Normal file
54
.github/workflows/build-ci.yaml
vendored
Normal file
@@ -0,0 +1,54 @@
|
||||
name: Build CI Environment
|
||||
|
||||
on:
|
||||
workflow_dispatch:
|
||||
inputs:
|
||||
image_tag:
|
||||
description: 'Tag for the CI image (e.g., latest)'
|
||||
required: true
|
||||
default: 'latest'
|
||||
|
||||
env:
|
||||
# OVERRIDE_REGISTRY can be set as a secret to override the default registry (e.g., for testing with a private registry). Else '' will be used, which defaults to ghcr.io for github.com and the GitHub server domain for self-hosted GitHub instances.
|
||||
OVERRIDE_REGISTRY: ${{ secrets.OVERRIDE_REGISTRY }}
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
|
||||
concurrency:
|
||||
group: build-ci
|
||||
cancel-in-progress: true
|
||||
|
||||
jobs:
|
||||
build-ci-image:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Setup CI metadata
|
||||
id: setup
|
||||
uses: ./.github/actions/setup-ci-metadata
|
||||
with:
|
||||
registry: ${{ env.OVERRIDE_REGISTRY }}
|
||||
image_tag: ${{ github.event.inputs.image_tag }}
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: ${{ steps.setup.outputs.registry }}
|
||||
username: ${{ secrets.GITHUB_USERNAME || github.actor }}
|
||||
password: ${{ secrets.OVERRIDE_GITHUB_TOKEN || secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and push Docker image for CI
|
||||
uses: docker/build-push-action@v3
|
||||
with:
|
||||
context: .
|
||||
file: .github/docker/ci.Dockerfile
|
||||
push: true
|
||||
tags: |
|
||||
${{ steps.setup.outputs.image_tag }}
|
||||
${{ steps.setup.outputs.latest_tag }}
|
||||
139
.github/workflows/verify.yaml
vendored
Normal file
139
.github/workflows/verify.yaml
vendored
Normal file
@@ -0,0 +1,139 @@
|
||||
# this workflow verifies the generated code is up to date and valid
|
||||
|
||||
name: Verify
|
||||
on:
|
||||
pull_request:
|
||||
branches:
|
||||
- master
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
# OVERRIDE_REGISTRY can be set as a secret to override the default registry (e.g., for testing with a private registry). Else '' will be used, which defaults to ghcr.io for github.com and the GitHub server domain for self-hosted GitHub instances.
|
||||
OVERRIDE_REGISTRY: ${{ secrets.OVERRIDE_REGISTRY }}
|
||||
ACTIONS_STEP_DEBUG: true
|
||||
|
||||
jobs:
|
||||
get-ci-image:
|
||||
runs-on: ubuntu-latest
|
||||
outputs:
|
||||
image_tag: ${{ steps.setup.outputs.image_tag }}
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Setup CI metadata
|
||||
id: setup
|
||||
uses: ./.github/actions/setup-ci-metadata
|
||||
with:
|
||||
registry: ${{ secrets.OVERRIDE_REGISTRY }}
|
||||
image_tag: latest
|
||||
|
||||
verify-generated-db-entities:
|
||||
runs-on: ubuntu-latest
|
||||
needs:
|
||||
- get-ci-image
|
||||
container:
|
||||
image: ${{ needs.get-ci-image.outputs.image_tag }}
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:16
|
||||
env:
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: postgres
|
||||
POSTGRES_DB: nxmesh
|
||||
# ! do not set a fixed port to avoid conflicts when running multiple jobs in parallel, use Docker's internal networking instead
|
||||
# ports:
|
||||
# - 5432:5432
|
||||
options: >-
|
||||
--health-cmd "pg_isready -U postgres -d nxmesh"
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
|
||||
env:
|
||||
DATABASE_URL: postgres://postgres:postgres@postgres:5432/nxmesh
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Check whether migrations/entities changed
|
||||
id: check_changes
|
||||
shell: bash
|
||||
run: |
|
||||
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||
BASE_SHA=${{ github.event.pull_request.base.sha }}
|
||||
HEAD_SHA=${{ github.event.pull_request.head.sha }}
|
||||
else
|
||||
BASE_SHA=${{ github.event.before }}
|
||||
HEAD_SHA=${{ github.sha }}
|
||||
fi
|
||||
|
||||
if [ -z "$HEAD_SHA" ]; then
|
||||
HEAD_SHA=$(git rev-parse --verify HEAD 2>/dev/null || echo "")
|
||||
fi
|
||||
|
||||
if [ -z "$BASE_SHA" ]; then
|
||||
PREV=$(git rev-parse --verify "${HEAD_SHA}^" 2>/dev/null || true)
|
||||
if [ -n "$PREV" ]; then
|
||||
BASE_SHA=$PREV
|
||||
else
|
||||
BASE_SHA=$HEAD_SHA
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Comparing $BASE_SHA..$HEAD_SHA"
|
||||
CHANGED_FILES=$(git diff --name-only "$BASE_SHA" "$HEAD_SHA" || true)
|
||||
echo "$CHANGED_FILES"
|
||||
|
||||
echo "$CHANGED_FILES" | grep -E '^(crates/migration/src/|apps/nxmesh-master/src/db/entities/)' >/dev/null 2>&1 \
|
||||
&& echo "changed=true" >> $GITHUB_OUTPUT \
|
||||
|| echo "changed=true" >> $GITHUB_OUTPUT
|
||||
# || echo "changed=false" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Setup Rust, checkout and restore caches
|
||||
if: steps.check_changes.outputs.changed == 'true'
|
||||
uses: ./.github/actions/setup-rust
|
||||
with:
|
||||
skip_cache: ${{ vars.SKIP_CACHE }}
|
||||
|
||||
- name: Install SeaORM CLI
|
||||
if: steps.check_changes.outputs.changed == 'true'
|
||||
run: |
|
||||
cargo install sea-orm-cli@^2.0.0-rc --features "sqlx-postgres runtime-tokio-rustls"
|
||||
|
||||
- name: Apply migrations
|
||||
if: steps.check_changes.outputs.changed == 'true'
|
||||
run: |
|
||||
cargo run -p nxmesh-migration -- up
|
||||
|
||||
- name: Regenerate entities
|
||||
if: steps.check_changes.outputs.changed == 'true'
|
||||
run: |
|
||||
sea-orm-cli generate entity \
|
||||
--database-url "$DATABASE_URL" \
|
||||
--output-dir apps/nxmesh-master/src/db/entities \
|
||||
--with-serde both \
|
||||
--with-copy-enums \
|
||||
--date-time-crate chrono
|
||||
|
||||
- name: Check for uncommitted changes in entities
|
||||
if: steps.check_changes.outputs.changed == 'true'
|
||||
shell: bash
|
||||
run: |
|
||||
if [[ -n $(git status --porcelain --untracked-files=all | grep 'apps/nxmesh-master/src/db/entities/') ]]; then
|
||||
echo "Generated SeaORM entities are not up to date."
|
||||
echo "Run 'just db-generate' after applying migrations and commit the result."
|
||||
git status --porcelain --untracked-files=all | grep 'apps/nxmesh-master/src/db/entities/'
|
||||
exit 1
|
||||
else
|
||||
echo "Generated SeaORM entities are up to date."
|
||||
fi
|
||||
|
||||
- name: Skip entity generation (no relevant changes)
|
||||
if: steps.check_changes.outputs.changed == 'false'
|
||||
run: echo "No changes in migrations/entities, skipping SeaORM entity verification."
|
||||
Reference in New Issue
Block a user