92 lines
3.2 KiB
YAML
92 lines
3.2 KiB
YAML
name: Build and Deploy to Production
|
|
run-name: Deploying commit ${{ gitea.sha_short }} by @${{ gitea.actor }}
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: website-deploy-runner
|
|
env:
|
|
DOTNET_INSTALL_DIR: "$HOME/.dotnet"
|
|
|
|
steps:
|
|
- name: Checkout Code
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET 8 SDK
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: '8.0.x'
|
|
|
|
- name: Cache NuGet packages
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.nuget/packages
|
|
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-nuget-
|
|
|
|
- name: Cache Node.js modules
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: frontend/node_modules
|
|
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-node-
|
|
|
|
- name: Create Backend appsettings.Production.json
|
|
run: |
|
|
echo "Creating backend appsettings.Production.json file..."
|
|
mkdir -p backend
|
|
cat <<EOF > backend/appsettings.Production.json
|
|
{
|
|
"SmtpSettings": {
|
|
"Host": "${{ vars.SMTP_HOST }}",
|
|
"Port": ${{ vars.SMTP_PORT }},
|
|
"User": "${{ secrets.SMTP_USER }}",
|
|
"Pass": "${{ secrets.SMTP_PASS }}",
|
|
"FromEmail": "${{ vars.SMTP_FROM_EMAIL }}",
|
|
"ReceivingEmail": "${{ vars.YOUR_RECEIVING_EMAIL }}"
|
|
},
|
|
"CorsOrigins": "${{ vars.FRONTEND_URL }}"
|
|
}
|
|
EOF
|
|
|
|
- name: Create Frontend .env.local file
|
|
run: |
|
|
echo "Creating frontend .env.local file..."
|
|
mkdir -p frontend
|
|
cat <<EOF > frontend/.env.local
|
|
NEXT_PUBLIC_GITHUB_URL=${{ vars.NEXT_PUBLIC_GITHUB_URL }}
|
|
NEXT_PUBLIC_LINKEDIN_URL=${{ vars.NEXT_PUBLIC_LINKEDIN_URL }}
|
|
EOF
|
|
|
|
- name: Install Dependencies and Build
|
|
run: |
|
|
echo "Restoring backend NuGet packages..."
|
|
dotnet restore backend/JoaoLoureiro.Portfolio.Api/JoaoLoureiro.Portfolio.Api.csproj
|
|
|
|
echo "Building and publishing backend..."
|
|
dotnet publish backend/JoaoLoureiro.Portfolio.Api/JoaoLoureiro.Portfolio.Api.csproj --configuration Release --output ./publish
|
|
|
|
echo "Installing frontend dependencies..."
|
|
cd frontend && npm install
|
|
|
|
echo "Building frontend application..."
|
|
npm run build
|
|
|
|
- name: Sync Files to Production Directory
|
|
run: |
|
|
echo "Syncing files to production directory..."
|
|
rsync -a --delete ./publish/ /var/www/website.joaoloureiro.dev.br/backend/
|
|
rsync -a --delete ./frontend/.next/ /var/www/website.joaoloureiro.dev.br/frontend/
|
|
rsync -a --delete ./frontend/public/ /var/www/website.joaoloureiro.dev.br/frontend/
|
|
rsync -a ./frontend/package.json /var/www/website.joaoloureiro.dev.br/frontend/
|
|
rsync -a ./frontend/ecosystem.config.json /var/www/website.joaoloureiro.dev.br/frontend/
|
|
|
|
- name: Restart Applications with PM2
|
|
run: |
|
|
echo "Restarting applications with PM2..."
|
|
restart-portfolio |