Merge pull request #120 from kubapoke/feat/redis-enjoyment #78
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and deploy Car Rent API | |
on: | |
push: | |
branches: | |
- development # Trigger build on development for testing changes | |
- main # Trigger build and deploy on main for production | |
paths: | |
- 'car-rental/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 Rental API | |
working-directory: car-rental/backend/CarRentalAPI/CarRentalAPI | |
run: | | |
echo "ALLOWED_ORIGINS=${{ secrets.RENTALAPI_ALLOWED_ORIGINS }}" > .env | |
echo "DATABASE_CONNECTION_STRING=${{ secrets.RENTALAPI_DATABASE_CONNECTION_STRING }}" >> .env | |
echo "CAR_RENTAL_SECRET_KEY=${{ secrets.RENTALAPI_CAR_RENTAL_SECRET_KEY }}" >> .env | |
echo "REDIS_DATABASE_CONNECTION=${{ secrets.RENTALAPI_REDIS_DATABASE_CONNECTION }}" >> .env | |
- name: Update database | |
run: | | |
dotnet tool install --global dotnet-ef --version 8.* | |
dotnet tool restore | |
dotnet ef --project car-rental/backend/CarRentalAPI/CarRentalAPI/CarRentalAPI.csproj database update | |
env: | |
ConnectionStrings__DefaultConnection: ${{ secrets.SEARCHAPI_DATABASE_CONNECTION_STRING }} | |
- name: Build with dotnet | |
run: dotnet build car-rental/backend/CarRentalAPI --configuration Release | |
- name: dotnet publish | |
run: dotnet publish car-rental/backend/CarRentalAPI -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_7682ECE7E38E420B9A2792F48DC92B52 }} | |
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_6166A5C7588645BB93AF144AE0D65CD0 }} | |
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_D2DBAAAE1F7B4852928C575796831D20 }} | |
- name: Deploy to Azure Web App | |
id: deploy-to-webapp | |
uses: azure/webapps-deploy@v3 | |
with: | |
app-name: 'carrentapi' | |
slot-name: 'Production' | |
package: . |