Skip to content

Merge pull request #135 from kubapoke/feat/client-return-api #78

Merge pull request #135 from kubapoke/feat/client-return-api

Merge pull request #135 from kubapoke/feat/client-return-api #78

Workflow file for this run

name: Build and deploy Car Search API
on:
push:
branches:
- development # Trigger build on development for testing changes
- main # Trigger build and deploy on main for production
paths:
- 'car-search/backend/**'
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
if: github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4
- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.x'
- name: Create the .env file for Car Search API
working-directory: car-search/backend/CarSearchAPI/CarSearchAPI
run: |
echo "ALLOWED_ORIGINS=${{ secrets.SEARCHAPI_ALLOWED_ORIGINS }}" > .env
echo "DATABASE_CONNECTION_STRING=${{ secrets.SEARCHAPI_DATABASE_CONNECTION_STRING }}" >> .env
echo "JWT_TOKEN_SECRET_KEY=${{ secrets.SEARCHAPI_JWT_TOKEN_SECRET_KEY }}" >> .env
echo "SENDGRID_API_KEY=${{ secrets.SEARCHAPI_SENDGRID_API_KEY }}" >> .env
echo "CAR_RENTAL_API_URL=${{ secrets.SEARCHAPI_CAR_RENTAL_API_URL }}" >> .env
echo "COMPANY_EMAIL=${{ secrets.SEARCHAPI_COMPANY_EMAIL }}" >> .env
echo "JWT_CONFIRMATION_TOKEN_SECRET_KEY=${{ secrets.SEARCHAPI_JWT_CONFIRMATION_TOKEN_SECRET_KEY }}" >> .env
echo "MY_ADDRESS=${{ secrets.SEARCHAPI_MY_ADDRESS }}" >> .env
echo "CAR_RENTAL_SECRET_KEY=${{ secrets.SEARCHAPI_CAR_RENTAL_SECRET_KEY }}" >> .env
- name: Update database
run: |
dotnet tool install --global dotnet-ef --version 8.*
dotnet tool restore
dotnet ef --project car-search/backend/CarSearchAPI/CarSearchAPI/CarSearchAPI.csproj database update
env:
ConnectionStrings__DefaultConnection: ${{ secrets.SEARCHAPI_DATABASE_CONNECTION_STRING }}
- name: Build with dotnet
run: dotnet build car-search/backend/CarSearchAPI --configuration Release
- name: dotnet publish
run: dotnet publish car-search/backend/CarSearchAPI -c Release -o "${{env.DOTNET_ROOT}}/myapp"
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v4
with:
name: .net-app
path: "${{env.DOTNET_ROOT}}/myapp"
deploy:
runs-on: windows-latest
needs: build
if: github.ref == 'refs/heads/main' # Only run deployment if push is on main
environment:
name: 'Production'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
permissions:
id-token: write # Required for requesting the JWT
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v4
with:
name: .net-app
- name: Login to Azure
uses: azure/login@v2
with:
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_5DA27A1EC070421EAC9CFE9A5DD9B63D }}
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_391FFE1FFACC4024ACBD0D511E01A2B4 }}
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_20574EF43DE540898AD4C2F77D7812D8 }}
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v3
with:
app-name: 'carsearchapi'
slot-name: 'Production'
package: .