Skip to content

feat: add validate session route #31

feat: add validate session route

feat: add validate session route #31

Workflow file for this run

name: CI/CD - Node Hybrid JWT + Session Auth API
on:
push:
branches: [main]
pull_request:
branches: [main]
types: [opened, synchronize, reopened]
jobs:
build-test-push:
name: Build, Test and Push Docker Image
runs-on: ubuntu-latest
steps:
# 1. Checkout source code
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetches full history for better caching/context
# 2. Set up Docker Buildx
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# 3. Cache Docker layers
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: ${{ runner.os }}-buildx-
# 4. Cache npm dependencies
- name: Cache npm dependencies
uses: actions/cache@v4
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: ${{ runner.os }}-npm-
# 5. Extract metadata
- name: Extract metadata
id: meta
run: |
echo "REPO_NAME=${GITHUB_REPOSITORY##*/}" >> "$GITHUB_OUTPUT"
echo "SHORT_SHA=${GITHUB_SHA::7}" >> "$GITHUB_OUTPUT"
# 6. Build dev Docker image
- name: Build Docker image for tests
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.dev
tags: ${{ steps.meta.outputs.REPO_NAME }}-dev:latest
load: true # Load to local Docker daemon for testing
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache,mode=max
# 7. Run Vitest tests
- name: Run Vitest tests and generate report
run: |
docker run --rm \
--workdir /app \
--entrypoint "" \
${{ steps.meta.outputs.REPO_NAME }}-dev:latest \
sh -c "npx vitest run --reporter=verbose"
env:
CI: true
NODE_ENV: test
timeout-minutes: 10
# 8. Login to Docker Hub
- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
# 9. Build and push prod image
- name: Build and push production image
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: |
${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKERHUB_PROJECT_NAME }}:latest
${{ secrets.DOCKER_USERNAME }}/${{ secrets.DOCKERHUB_PROJECT_NAME }}:${{ steps.meta.outputs.SHORT_SHA }}
cache-from: type=local,src=/tmp/.buildx-cache