refactor #248
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
push: | |
branches: [main] | |
pull_request: | |
env: | |
PORT: 80 | |
ENV: 'testing' | |
MONGODB_URI: 'mongodb://username:password@mongodb:27017/close-powerlifting?authSource=admin' | |
FRONTEND_ORIGIN: 'http://localhost:8080' | |
PASSWORD_SALT: 5 | |
JWT_SECRET: 'yeahhhhhhhhhhh' | |
ADMIN_EMAIL: '[email protected]' | |
ADMIN_NAME: 'jaw' | |
COOKIE_EXPIRATION: 60000 | |
COOKIE_PASSWORD: 'cookie password' | |
COOKIE_NAME: 'what is this cookie name' | |
SESSION_SECRET: 'something someting' | |
SESSION_NAME: 'something cool' | |
API_URL: 'https://www.openpowerlifting.org/api' | |
BASE_URL: 'https://www.openpowerlifting.org/' | |
X_API_KEY: '' | |
EMAIL_HOST: 'mailhot' # docker | |
EMAIL_PORT: 1025 # docker | |
EMAIL_AUTH_EMAIL: '' | |
EMAIL_AUTH_PASS: '' | |
jobs: | |
format: | |
name: Prettier format | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [19.x] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm i | |
- name: Format codes | |
run: npm run format | |
lint: | |
name: ESLint | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [19.x] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm i | |
- name: Lint codes | |
run: npm run lint | |
test: | |
name: Unit tests | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
node-version: [19.x] | |
services: | |
mongodb: | |
image: mongo:latest | |
ports: | |
- 27017:27017 | |
redis: | |
image: redis:latest | |
ports: | |
- 6379:6379 | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v3 | |
with: | |
node-version: ${{ matrix.node-version }} | |
cache: 'npm' | |
- name: Install dependencies | |
run: npm i | |
- name: Test codes | |
run: npm run test | |
deploy: | |
needs: [format, test, lint] | |
name: Deploy to production | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
environment: | |
name: production | |
url: https://close-powerlifting.jaw.dev/ | |
steps: | |
- name: Check out repository | |
uses: actions/checkout@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v2 | |
- name: Login to Container Registry | |
uses: docker/login-action@v2 | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GH_TOKEN }} | |
- name: Preset Image Name | |
run: echo "IMAGE_URL=$(echo ghcr.io/${{ github.repository_owner }}/${{ github.event.repository.name }}:$(echo ${{ github.sha }} | cut -c1-7) | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV | |
- name: Build and push Docker Image | |
uses: docker/build-push-action@v4 | |
with: | |
context: . | |
file: ./Dockerfile.prod | |
push: true | |
tags: ${{ env.IMAGE_URL }} | |
- name: Deploy Image to Production | |
uses: caprover/[email protected] | |
with: | |
server: '${{ secrets.CAPROVER_SERVER }}' | |
app: '${{ secrets.APP_NAME }}' | |
token: '${{ secrets.APP_TOKEN }}' | |
image: ${{ env.IMAGE_URL }} |