From f56eac28f77a9b082e8d54f94172bc59342c93a9 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 1 Aug 2026 18:46:27 +0200 Subject: [PATCH] feat: add CI workflows for linting, testing, and Docker image build & push --- .github/workflows/docker.yml | 66 +++++++++++++++++++++++++++++ .github/workflows/lint.yml | 44 ++++++++++++++++++++ .github/workflows/server-ci.yml | 73 --------------------------------- .github/workflows/tests.yml | 51 +++++++++++++++++++++++ 4 files changed, 161 insertions(+), 73 deletions(-) create mode 100644 .github/workflows/docker.yml create mode 100644 .github/workflows/lint.yml delete mode 100644 .github/workflows/server-ci.yml create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..b63f91e --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,66 @@ +name: Build & Push Docker Image + +on: + push: + branches: + - "**" + paths: + - 'CollabTableServer/**' + - '.github/workflows/docker.yml' + pull_request: + branches: + - main + - master + paths: + - 'CollabTableServer/**' + - '.github/workflows/docker.yml' + workflow_dispatch: {} + +jobs: + build: + name: Docker Build & Push + runs-on: ubuntu-latest + permissions: + contents: read + + steps: + - name: Checkout code + uses: actions/checkout@v7 + + # Multi-arch (arm64) is only built and published from main; other branches and PRs + # only need an amd64 build to validate they compile, which needs no emulation. + - name: Set up QEMU (multi-arch builds) + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: docker/setup-qemu-action@v4 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v4 + + - name: Log in to Docker Hub + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: docker/login-action@v4 + with: + username: ${{ vars.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v6 + with: + images: ${{ vars.DOCKERHUB_USERNAME }}/collabtableserver + tags: | + type=ref,event=branch + type=sha,prefix=sha-,format=short + type=raw,value=latest,enable={{is_default_branch}} + + - name: Build and push + uses: docker/build-push-action@v7 + with: + context: ./CollabTableServer + platforms: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && 'linux/amd64,linux/arm64' || 'linux/amd64' }} + push: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=registry,ref=${{ vars.DOCKERHUB_USERNAME }}/collabtableserver:buildcache + cache-to: ${{ (github.event_name == 'push' && github.ref == 'refs/heads/main') && format('type=registry,ref={0}/collabtableserver:buildcache,mode=max', vars.DOCKERHUB_USERNAME) || '' }} + provenance: false diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..c2a75d7 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,44 @@ +name: Lint + +on: + push: + branches: + - "**" + paths: + - 'CollabTableServer/**' + - '.github/workflows/lint.yml' + pull_request: + branches: + - main + - master + paths: + - 'CollabTableServer/**' + - '.github/workflows/lint.yml' + workflow_dispatch: {} + +jobs: + lint: + name: Lint + runs-on: ubuntu-latest + defaults: + run: + working-directory: CollabTableServer + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: CollabTableServer/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Run ESLint + run: npm run lint diff --git a/.github/workflows/server-ci.yml b/.github/workflows/server-ci.yml deleted file mode 100644 index d82ba17..0000000 --- a/.github/workflows/server-ci.yml +++ /dev/null @@ -1,73 +0,0 @@ -name: Server CI - -on: - push: - branches: [ '**' ] - paths: - - 'CollabTableServer/**' - - '.github/workflows/server-ci.yml' - pull_request: - branches: [ '**' ] - paths: - - 'CollabTableServer/**' - - '.github/workflows/server-ci.yml' - workflow_dispatch: - -jobs: - lint: - name: Lint - runs-on: ubuntu-latest - defaults: - run: - working-directory: CollabTableServer - permissions: - contents: read - - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: '20' - cache: 'npm' - cache-dependency-path: CollabTableServer/package-lock.json - - - name: Install dependencies - run: npm ci - - - name: Run ESLint - run: npm run lint - - build-and-push: - name: Build & Push Docker Image - needs: lint - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v3 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v3 - - - name: Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v6 - with: - context: ./CollabTableServer - push: ${{ github.event_name == 'push' }} - tags: | - gabriel20xx/CollabTableServer:latest - gabriel20xx/CollabTableServer:${{ github.sha }} - platforms: linux/amd64,linux/arm64 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..aa2047c --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,51 @@ +name: Tests + +on: + push: + branches: + - "**" + paths: + - 'CollabTableServer/**' + - '.github/workflows/tests.yml' + pull_request: + branches: + - main + - master + paths: + - 'CollabTableServer/**' + - '.github/workflows/tests.yml' + workflow_dispatch: {} + +jobs: + test: + name: Test + runs-on: ubuntu-latest + defaults: + run: + working-directory: CollabTableServer + permissions: + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: CollabTableServer/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: | + if find src -iname '*.test.ts' -o -iname '*.spec.ts' | grep -q .; then + echo "Test files found for CollabTableServer — running npm test." + npm test + else + echo "No test suite configured for CollabTableServer yet — skipping." + exit 0 + fi