Files
portfolio-app/.gitea/workflows/deploy.yml

93 lines
3.3 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'
cache: true
dotnet-solution: 'backend/JoaoLoureiro.Portfolio.slnx'
- name: Create Backend appsettings.Production.json
run: |
echo "Creating backend appsettings.Production.json file..."
# This creates the JSON file by mapping your Gitea secrets/vars
# to the structure you provided.
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..."
cd frontend
echo "NEXT_PUBLIC_GITHUB_URL=${{ vars.NEXT_PUBLIC_GITHUB_URL }}" >> .env.local
echo "NEXT_PUBLIC_LINKEDIN_URL=${{ vars.NEXT_PUBLIC_LINKEDIN_URL }}" >> .env.local
- name: Cache Dependencies
uses: actions/cache@v4
with:
path: |
~/.nuget/packages
frontend/node_modules
frontend/.next/cache
key: ${{ runner.os }}-${{ hashFiles('**/*.csproj') }}-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-
- name: Install Dependencies and Build
run: |
echo "Restoring backend NuGet packages..."
dotnet restore backend
echo "Building and publishing backend..."
# This compiles the app and places the output in the 'publish' folder
dotnet publish backend --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: |
# Sync the published backend from the './publish' directory
rsync -a --delete ./publish/ /var/www/website.joaoloureiro.dev.br/
# Sync the built frontend from the 'frontend' directory
rsync -a --delete ./frontend/.next /var/www/website.joaoloureiro.dev.br/
rsync -a --delete ./frontend/public /var/www/website.joaoloureiro.dev.br/
rsync -a ./frontend/package.json /var/www/website.joaoloureiro.dev.br/
rsync -a ./frontend/ecosystem.config.js /var/www/website.joaoloureiro.dev.br/
- name: Restart Applications with PM2
run: |
# This command on your server should handle restarting both processes
# Ensure your PM2 ecosystem file now has entries for both the .NET app
# and the Next.js app.
restart-portfolio