Merge pull request #198 from ckekula/develop #61
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: Node.js CI Backend | |
on: | |
push: | |
branches: ["main"] | |
jobs: | |
build: | |
name: Build Backend | |
runs-on: self-hosted | |
strategy: | |
matrix: | |
node-version: [20.18.0] | |
env: | |
DATABASE_URL: ${{ secrets.DATABASE_URL }} | |
GOOGLE_MAPS_API_KEY: ${{ secrets.GOOGLE_MAPS_API_KEY }} | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_S3_REGION: ${{ secrets.AWS_S3_REGION }} | |
AWS_S3_BUCKET_NAME: ${{ secrets.AWS_S3_BUCKET_NAME }} | |
UPLOAD_RATE_TTL: ${{ secrets.UPLOAD_RATE_TTL }} | |
UPLOAD_RATE_LIMIT: ${{ secrets.UPLOAD_RATE_LIMIT }} | |
COOKIE_SECURE: ${{ secrets.COOKIE_SECURE }} | |
COOKIE_SAMESITE: ${{secrets.COOKIE_SAMESITE}} | |
TYPEORM_SYNC: ${{ secrets.TYPEORM_SYNC }} | |
CORS_ORIGIN: ${{ secrets.CORS_ORIGIN }} | |
steps: | |
# Checkout the code from GitHub repository | |
- uses: actions/checkout@v4 | |
# Set up Node.js with the specified version | |
- name: Set up Node.js ${{ matrix.node-version }} | |
uses: actions/setup-node@v4 | |
with: | |
node-version: ${{ matrix.node-version }} | |
# Stop pm2 | |
- name: Stop pm2 | |
run: | | |
pm2 stop 1 | |
# Install dependencies in the backend directory | |
- name: Install Dependencies | |
run: | | |
cd backend | |
npm ci | |
# Copy files to the production backend directory | |
- name: Copy files to production backend directory | |
run: | | |
rm -rf /home/janitha/production/backend/* | |
cp -R backend/* /home/janitha/production/backend/ | |
# Delete existing .env file from backend production directory | |
- name: Remove old .env file from backend | |
run: | | |
rm -f /home/janitha/production/backend/.env | |
# Set up environmental variables | |
- name: Add Environmental Variables | |
run: | | |
cd /home/janitha/production/backend | |
touch .env | |
echo "DATABASE_URL=${{ secrets.DATABASE_URL }}" >> .env | |
echo "GOOGLE_MAPS_API_KEY=${{ secrets.GOOGLE_MAPS_API_KEY }}" >> .env | |
echo "AWS_ACCESS_KEY_ID=${{ secrets.AWS_ACCESS_KEY_ID }}" >> .env | |
echo "AWS_SECRET_ACCESS_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> .env | |
echo "AWS_S3_REGION=${{ secrets.AWS_S3_REGION }}" >> .env | |
echo "AWS_S3_BUCKET_NAME=${{ secrets.AWS_S3_BUCKET_NAME }}" >> .env | |
echo "UPLOAD_RATE_TTL=${{ secrets.UPLOAD_RATE_TTL }}" >> .env | |
echo "UPLOAD_RATE_LIMIT=${{ secrets.UPLOAD_RATE_LIMIT }}" >> .env | |
echo "COOKIE_SAMESITE=${{secrets.COOKIE_SAMESITE}}" >> .env | |
echo "COOKIE_SECURE=${{ secrets.COOKIE_SECURE }}" >> .env | |
echo "TYPEORM_SYNC=${{ secrets.TYPEORM_SYNC }}" >> .env | |
echo "CORS_ORIGIN=${{ secrets.CORS_ORIGIN }}" >> .env | |
# Build the backend in the production directory | |
- name: Build the backend | |
run: | | |
cd /home/janitha/production/backend | |
npm run build --if-present | |
- name: Generate the schema.gql | |
run: | | |
cd /home/janitha/production/backend | |
npm run generate-schema --if-present | |
- name: Restart pm2 | |
run: | | |
pm2 restart 1 |