Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating yaml it breaks on main to deploy #7

Merged
merged 1 commit into from
Sep 21, 2024
Merged
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
156 changes: 77 additions & 79 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,116 +3,114 @@ name: CI/CD Pipeline
on:
push:
branches:
- main # Trigger deployment only on push to the main branch
- main # Trigger deployment only on push to the main branch
pull_request:
branches:
- main # Run checks (build only) on PRs
- main # Run checks (build only) on PRs

jobs:
# --- Build Frontend ---
build-frontend:
runs-on: ubuntu-latest

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

- name: Set up Node.js for frontend
uses: actions/setup-node@v3
with:
node-version: '20' # Specify the Node.js version
- name: Set up Node.js for frontend
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Install frontend dependencies
working-directory: ./frontend # Navigate to the frontend folder
run: npm install
- name: Install frontend dependencies
working-directory: ./frontend
run: npm install

- name: Build frontend
working-directory: ./frontend
run: npm run build
- name: Build frontend
working-directory: ./frontend
run: npm run build

- name: Upload frontend artifact
if: github.event_name == 'pull_request' # Only upload the artifact on PRs
uses: actions/upload-artifact@v4
with:
name: angular-build
path: ./frontend/dist/smetovi/ # Path to Angular build files
- name: Upload frontend artifact
uses: actions/upload-artifact@v4
with:
name: angular-build
path: ./frontend/dist/smetovi/ # Path to Angular build files

# --- Build Backend ---
build-backend:
runs-on: ubuntu-latest

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

- name: Set up Node.js for backend
uses: actions/setup-node@v3
with:
node-version: '20' # Specify the Node.js version
- name: Set up Node.js for backend
uses: actions/setup-node@v3
with:
node-version: "20"

- name: Install backend dependencies
working-directory: ./backend # Navigate to the backend folder
run: npm install
- name: Install backend dependencies
working-directory: ./backend
run: npm install

- name: Upload backend artifact
if: github.event_name == 'pull_request' # Only upload the artifact on PRs
uses: actions/upload-artifact@v4
with:
name: backend-artifact
path: ./backend # Upload the backend folder for deployment
- name: Upload backend artifact
uses: actions/upload-artifact@v4
with:
name: backend-artifact
path: ./backend/ # Upload backend folder for deployment

# --- Deploy Frontend ---
deploy-frontend:
runs-on: ubuntu-latest
needs: [build-frontend, build-backend] # Ensure both build jobs complete before deployment
if: github.ref == 'refs/heads/main' # Only deploy when merged into main branch
needs: [build-frontend, build-backend] # Ensure both build jobs complete before deployment
if: github.ref == 'refs/heads/main' # Only deploy if on the main branch

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

- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: angular-build
path: ./frontend/dist/smetovi/ # Ensure this is your Angular build folder

- name: Deploy frontend to cPanel via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./frontend/dist/smetovi/ # Deploy the actual files
server-dir: /public_html/ # Upload to the existing public_html folder
port: ${{ secrets.FTP_PORT }}
log-level: verbose
force: true # This will re-upload all files, even unchanged ones
- name: Checkout code
uses: actions/checkout@v3

- name: Download frontend artifact
uses: actions/download-artifact@v4
with:
name: angular-build
path: ./frontend/dist/smetovi/ # Ensure this is your Angular build folder

- name: Deploy frontend to cPanel via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./frontend/dist/smetovi/
server-dir: /public_html/
port: ${{ secrets.FTP_PORT }}
log-level: verbose
force: true # This will re-upload all files, even unchanged ones

# --- Deploy Backend ---
deploy-backend:
runs-on: ubuntu-latest
needs: build-backend # Ensure the backend build completes before deployment
if: github.ref == 'refs/heads/main' # Only deploy when merged into main branch
needs: build-backend
if: github.ref == 'refs/heads/main' # Only deploy if on the main branch

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

- name: Download backend artifact
uses: actions/download-artifact@v4
with:
name: backend-artifact
path: ./backend/ # Download the backend files

- name: Deploy backend to cPanel via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./backend/ # Path to your backend build
server-dir: /api/ # Deploy directly to /api/ folder
port: ${{ secrets.FTP_PORT }}
log-level: verbose
force: true # This will re-upload all files, even unchanged ones
- name: Checkout code
uses: actions/checkout@v3

- name: Download backend artifact
uses: actions/download-artifact@v4
with:
name: backend-artifact
path: ./backend/

- name: Deploy backend to cPanel via FTP
uses: SamKirkland/[email protected]
with:
server: ${{ secrets.FTP_SERVER }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
local-dir: ./backend/
server-dir: /api/
port: ${{ secrets.FTP_PORT }}
log-level: verbose
force: true
Loading