Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"env": {
"browser": false,
"commonjs": true,
"es6": true,
"node": true,
"mocha": true
},
"extends": [
"eslint:recommended"
],
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module"
},
"rules": {
"no-console": "warn",
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-var": "error",
"prefer-const": "error",
"eqeqeq": "error",
"no-trailing-spaces": "error",
"semi": ["error", "always"],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"indent": ["error", 4],
"no-multiple-empty-lines": ["error", { "max": 2 }]
},
"ignorePatterns": [
"node_modules/",
"dist/",
"build/"
]
}
120 changes: 120 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: CI/CD Pipeline

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:13
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: test_db
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

strategy:
matrix:
node-version: [16.x, 18.x, 20.x]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Create test environment file
run: |
cat > config.env << EOF
POSTGRES_URI=postgresql://postgres:postgres@localhost:5432/test_db
ATLAS_URI_LOGS=mongodb://localhost:27017/test_logs
EOF

- name: Run linting (if eslint config exists)
run: |
if [ -f ".eslintrc.js" ] || [ -f ".eslintrc.json" ] || [ -f "package.json" ] && grep -q "eslint" package.json; then
npm run lint
else
echo "No ESLint configuration found, skipping linting"
fi
continue-on-error: true

- name: Run tests
run: npm run mocha
env:
NODE_ENV: test
POSTGRES_URI: postgresql://postgres:postgres@localhost:5432/test_db

- name: Run basic server test
run: npm test
env:
NODE_ENV: test
POSTGRES_URI: postgresql://postgres:postgres@localhost:5432/test_db

security:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run security audit
run: npm audit --audit-level=moderate

- name: Check for outdated packages
run: npm outdated
continue-on-error: true

build:
runs-on: ubuntu-latest
needs: [test, security]

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Check if server starts successfully
run: |
timeout 30s node server.js &
sleep 10
curl -f http://localhost:3000/app/ || exit 1
env:
NODE_ENV: production
POSTGRES_URI: postgresql://dummy:dummy@localhost:5432/dummy
103 changes: 103 additions & 0 deletions .github/workflows/quality.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
name: Code Quality & Dependencies

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
workflow_dispatch: # Allow manual triggering

jobs:
dependency-review:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Dependency Review
uses: actions/dependency-review-action@v4

update-dependencies:
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch'

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'

- name: Update dependencies
run: |
npm update
npm audit fix --force
continue-on-error: true

- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: update dependencies'
title: 'chore: automated dependency updates'
body: |
Automated dependency updates created by GitHub Actions.

Please review the changes before merging.
branch: chore/dependency-updates
delete-branch: true

code-quality:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Check for console.log statements
run: |
if grep -r "console\.log" --include="*.js" . --exclude-dir=node_modules --exclude-dir=.git; then
echo "Warning: Found console.log statements in code"
exit 1
else
echo "No console.log statements found"
fi
continue-on-error: true

- name: Check for TODO comments
run: |
echo "TODO items found in codebase:"
grep -r "TODO\|FIXME\|HACK" --include="*.js" . --exclude-dir=node_modules --exclude-dir=.git || echo "No TODO items found"
continue-on-error: true

- name: Check file structure
run: |
echo "Checking for proper file structure..."
if [ ! -f "package.json" ]; then
echo "Error: package.json not found"
exit 1
fi
if [ ! -f "server.js" ]; then
echo "Error: server.js not found"
exit 1
fi
if [ ! -d "routes" ]; then
echo "Warning: routes directory not found"
fi
echo "File structure check completed"
98 changes: 98 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Release & Deploy

on:
push:
tags:
- 'v*.*.*'
release:
types: [published]

jobs:
release:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
cache: 'npm'

- name: Install dependencies
run: npm ci

- name: Run tests
run: npm run mocha

- name: Create release notes
run: |
echo "# Release Notes" > release-notes.md
echo "" >> release-notes.md
echo "## Changes in this release:" >> release-notes.md
git log --pretty=format:"- %s" $(git describe --tags --abbrev=0 HEAD^)..HEAD >> release-notes.md

- name: Upload release notes
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release-notes.md

docker-build:
runs-on: ubuntu-latest
needs: release
if: github.event_name == 'release'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Create Dockerfile
run: |
cat > Dockerfile << 'EOF'
FROM node:18-alpine

WORKDIR /app

# Copy package files
COPY package*.json ./

# Install dependencies
RUN npm ci --only=production

# Copy source code
COPY . .

# Expose port
EXPOSE 3000

# Create non-root user
RUN addgroup -g 1001 -S nodejs
RUN adduser -S nodejs -u 1001

# Change ownership of the app directory
RUN chown -R nodejs:nodejs /app
USER nodejs

# Start the application
CMD ["node", "server.js"]
EOF

- name: Build Docker image
run: |
docker build -t polaris-api:${{ github.ref_name }} .
docker build -t polaris-api:latest .

# Uncomment and configure these steps if you want to push to a registry
# - name: Log in to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}

# - name: Push to Docker Hub
# run: |
# docker push polaris-api:${{ github.ref_name }}
# docker push polaris-api:latest
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# API
# Polaris API

The API backend, implemented with Node.js.
[![CI/CD Pipeline](https://github.com/polaris-maps/polaris-api/actions/workflows/ci.yml/badge.svg)](https://github.com/polaris-maps/polaris-api/actions/workflows/ci.yml)
[![Code Quality](https://github.com/polaris-maps/polaris-api/actions/workflows/quality.yml/badge.svg)](https://github.com/polaris-maps/polaris-api/actions/workflows/quality.yml)

Exposes the data in the database(s).
The API backend for Polaris Maps, implemented with Node.js and Express.

Exposes the data in the database(s) and provides accessibility-focused navigation services.
Loading
Loading