fix: update deploy workflow to improve caching and streamline environment file creation

This commit is contained in:
2025-10-29 21:04:08 -03:00
parent dff77d42c6
commit 81e915d155

View File

@@ -19,14 +19,27 @@ jobs:
uses: actions/setup-dotnet@v4 uses: actions/setup-dotnet@v4
with: with:
dotnet-version: '8.0.x' dotnet-version: '8.0.x'
cache: true
dotnet-solution: 'backend/JoaoLoureiro.Portfolio.slnx' - 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 - name: Create Backend appsettings.Production.json
run: | run: |
echo "Creating backend appsettings.Production.json file..." echo "Creating backend appsettings.Production.json file..."
# This creates the JSON file by mapping your Gitea secrets/vars mkdir -p backend
# to the structure you provided.
cat <<EOF > backend/appsettings.Production.json cat <<EOF > backend/appsettings.Production.json
{ {
"SmtpSettings": { "SmtpSettings": {
@@ -44,20 +57,11 @@ jobs:
- name: Create Frontend .env.local file - name: Create Frontend .env.local file
run: | run: |
echo "Creating frontend .env.local file..." echo "Creating frontend .env.local file..."
cd frontend mkdir -p frontend
echo "NEXT_PUBLIC_GITHUB_URL=${{ vars.NEXT_PUBLIC_GITHUB_URL }}" >> .env.local cat <<EOF > frontend/.env.local
echo "NEXT_PUBLIC_LINKEDIN_URL=${{ vars.NEXT_PUBLIC_LINKEDIN_URL }}" >> .env.local NEXT_PUBLIC_GITHUB_URL=${{ vars.NEXT_PUBLIC_GITHUB_URL }}
NEXT_PUBLIC_LINKEDIN_URL=${{ vars.NEXT_PUBLIC_LINKEDIN_URL }}
- name: Cache Dependencies EOF
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 - name: Install Dependencies and Build
run: | run: |
@@ -65,7 +69,6 @@ jobs:
dotnet restore backend dotnet restore backend
echo "Building and publishing 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 dotnet publish backend --configuration Release --output ./publish
echo "Installing frontend dependencies..." echo "Installing frontend dependencies..."
@@ -76,18 +79,14 @@ jobs:
- name: Sync Files to Production Directory - name: Sync Files to Production Directory
run: | run: |
# Sync the published backend from the './publish' directory echo "Syncing files to production directory..."
rsync -a --delete ./publish/ /var/www/website.joaoloureiro.dev.br/ rsync -a --delete ./publish/ /var/www/website.joaoloureiro.dev.br/
rsync -a --delete ./frontend/.next/ /var/www/website.joaoloureiro.dev.br/
# Sync the built frontend from the 'frontend' directory rsync -a --delete ./frontend/public/ /var/www/website.joaoloureiro.dev.br/
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/package.json /var/www/website.joaoloureiro.dev.br/
rsync -a ./frontend/ecosystem.config.js /var/www/website.joaoloureiro.dev.br/ rsync -a ./frontend/ecosystem.config.js /var/www/website.joaoloureiro.dev.br/
- name: Restart Applications with PM2 - name: Restart Applications with PM2
run: | run: |
# This command on your server should handle restarting both processes echo "Restarting applications with PM2..."
# Ensure your PM2 ecosystem file now has entries for both the .NET app
# and the Next.js app.
restart-portfolio restart-portfolio