188 lines
5.9 KiB
YAML
188 lines
5.9 KiB
YAML
name: Deploy
|
|
|
|
on:
|
|
push:
|
|
branches: ["main", "dev"]
|
|
pull_request:
|
|
branches: ["main", "dev"]
|
|
|
|
permissions:
|
|
contents: write
|
|
|
|
jobs:
|
|
build:
|
|
name: Build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install pnpm
|
|
uses: pnpm/action-setup@v6
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "24"
|
|
cache: "pnpm"
|
|
cache-dependency-path: "**/pnpm-lock.yaml"
|
|
|
|
- name: Install dependencies
|
|
run: pnpm full-install
|
|
|
|
- name: Generate Prisma client
|
|
run: cd Backend && pnpm generate
|
|
env:
|
|
DATABASE_URL: mysql://x:x@localhost/x
|
|
|
|
- name: Build (both sides)
|
|
run: pnpm run build
|
|
|
|
test-and-lint:
|
|
name: Test & Lint
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install pnpm
|
|
uses: pnpm/action-setup@v6
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "24"
|
|
cache: "pnpm"
|
|
cache-dependency-path: "**/pnpm-lock.yaml"
|
|
|
|
- name: Install dependencies
|
|
run: pnpm full-install
|
|
|
|
- name: Copy environment file
|
|
run: cp example.env Backend/.env
|
|
|
|
- name: Generate Prisma client
|
|
run: cd Backend && pnpm generate
|
|
|
|
- name: Backend unit tests
|
|
run: cd Backend && pnpm test
|
|
|
|
- name: UI ESLint
|
|
run: cd UI && pnpm lint
|
|
|
|
generate_openapi_release:
|
|
name: Generate OpenAPI Release
|
|
needs: [build, test-and-lint]
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Install pnpm
|
|
uses: pnpm/action-setup@v6
|
|
|
|
- name: Setup Node.js
|
|
uses: actions/setup-node@v4
|
|
with:
|
|
node-version: "24"
|
|
cache: "pnpm"
|
|
cache-dependency-path: "**/pnpm-lock.yaml"
|
|
|
|
- name: Install dependencies
|
|
run: pnpm full-install
|
|
|
|
- name: Copy environment file
|
|
run: cp example.env Backend/.env
|
|
|
|
- name: Generate Prisma client
|
|
run: cd Backend && pnpm generate
|
|
|
|
- name: Start backend
|
|
run: |
|
|
cd Backend
|
|
set -a && source .env && set +a
|
|
nohup pnpm dev >/tmp/backend.log 2>&1 &
|
|
echo $! >/tmp/backend.pid
|
|
echo "PORT=${PORT}" >> $GITHUB_ENV
|
|
|
|
- name: Fetch OpenAPI spec
|
|
run: |
|
|
for i in {1..10}; do
|
|
if curl -sf http://localhost:$PORT/api/openapi.json -o openapi.json; then
|
|
exit 0
|
|
fi
|
|
sleep 2
|
|
done
|
|
echo "Backend did not become ready in time" >&2
|
|
cat /tmp/backend.log || true
|
|
exit 1
|
|
|
|
- name: Stop backend
|
|
if: always()
|
|
run: |
|
|
if [ -f /tmp/backend.pid ]; then
|
|
kill "$(cat /tmp/backend.pid)" || true
|
|
fi
|
|
|
|
- name: Upload OpenAPI artifact
|
|
uses: actions/upload-artifact@v4
|
|
with:
|
|
name: openapi-spec
|
|
path: openapi.json
|
|
|
|
- name: Publish release with OpenAPI spec
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
tag_name: openapi-${{ github.run_number }}
|
|
name: OpenAPI ${{ github.run_number }}
|
|
body: Generated OpenAPI spec from commit ${{ github.sha }}.
|
|
files: openapi.json
|
|
env:
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
push-image:
|
|
name: Build and Push Docker Image
|
|
needs: [build, test-and-lint]
|
|
runs-on: ubuntu-latest
|
|
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev')
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup Buildx
|
|
uses: docker/setup-buildx-action@v3
|
|
|
|
- name: Generate image metadata
|
|
id: meta
|
|
uses: docker/metadata-action@v5
|
|
with:
|
|
images: registry.reversed.dev/shsf/core
|
|
tags: |
|
|
type=raw,value=prod,enable=${{ github.ref == 'refs/heads/main' }}
|
|
type=raw,value=latest,enable=${{ github.ref == 'refs/heads/main' }}
|
|
type=raw,value=dev,enable=${{ github.ref == 'refs/heads/dev' }}
|
|
type=sha,format=long
|
|
labels: |
|
|
org.opencontainers.image.title=SHSF
|
|
org.opencontainers.image.description=SelfHostable Serverless Functions
|
|
org.opencontainers.image.vendor=space
|
|
|
|
- name: Log in to Harbor
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: registry.reversed.dev
|
|
username: ${{ secrets.HARBOR_USERNAME }}
|
|
password: ${{ secrets.HARBOR_PASSWORD }}
|
|
|
|
- name: Build and push image
|
|
uses: docker/build-push-action@v6
|
|
with:
|
|
context: .
|
|
push: true
|
|
provenance: false
|
|
sbom: false
|
|
tags: ${{ steps.meta.outputs.tags }}
|
|
labels: ${{ steps.meta.outputs.labels }}
|