|
| 1 | +name: Deploy .NET API to Azure App Service |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + paths: |
| 8 | + - 'ApiResources/TalentManagement-API/**' |
| 9 | + - '.github/workflows/deploy-api.yml' |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: |
| 13 | + id-token: write # Required for OIDC token request |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + DOTNET_VERSION: '10.x' |
| 18 | + PROJECT_PATH: 'ApiResources/TalentManagement-API/TalentManagementAPI.WebApi/TalentManagementAPI.WebApi.csproj' |
| 19 | + SOLUTION_PATH: 'ApiResources/TalentManagement-API/TalentManagementAPI.slnx' |
| 20 | + PUBLISH_DIR: '${{ github.workspace }}/publish/api' |
| 21 | + APP_SERVICE_NAME: 'app-talent-api-dev' |
| 22 | + RESOURCE_GROUP: 'rg-talent-dev' |
| 23 | + |
| 24 | +jobs: |
| 25 | + build-and-deploy: |
| 26 | + name: Build, Test, and Deploy API |
| 27 | + runs-on: ubuntu-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout repository (with submodules) |
| 31 | + uses: actions/checkout@v4 |
| 32 | + with: |
| 33 | + submodules: recursive |
| 34 | + |
| 35 | + - name: Set up .NET ${{ env.DOTNET_VERSION }} |
| 36 | + uses: actions/setup-dotnet@v4 |
| 37 | + with: |
| 38 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 39 | + |
| 40 | + - name: Restore dependencies |
| 41 | + run: dotnet restore ${{ env.SOLUTION_PATH }} |
| 42 | + |
| 43 | + - name: Build |
| 44 | + run: dotnet build ${{ env.SOLUTION_PATH }} --configuration Release --no-restore |
| 45 | + |
| 46 | + - name: Run unit tests |
| 47 | + run: dotnet test ${{ env.SOLUTION_PATH }} --configuration Release --no-build --verbosity normal |
| 48 | + |
| 49 | + - name: Publish |
| 50 | + run: | |
| 51 | + dotnet publish ${{ env.PROJECT_PATH }} \ |
| 52 | + --configuration Release \ |
| 53 | + --no-build \ |
| 54 | + --output ${{ env.PUBLISH_DIR }} |
| 55 | +
|
| 56 | + - name: Log in to Azure |
| 57 | + uses: azure/login@v2 |
| 58 | + with: |
| 59 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 60 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 61 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 62 | + |
| 63 | + - name: Configure App Service settings |
| 64 | + run: | |
| 65 | + az webapp config appsettings set \ |
| 66 | + --resource-group ${{ env.RESOURCE_GROUP }} \ |
| 67 | + --name ${{ env.APP_SERVICE_NAME }} \ |
| 68 | + --settings \ |
| 69 | + "ConnectionStrings__DefaultConnection=${{ secrets.API_DB_CONNECTION_STRING }}" \ |
| 70 | + "Sts__ServerUrl=${{ secrets.IDENTITY_SERVER_URL }}" \ |
| 71 | + "Sts__ValidIssuer=${{ secrets.IDENTITY_SERVER_URL }}" \ |
| 72 | + "Sts__Audience=app.api.talentmanagement" \ |
| 73 | + "JWTSettings__Key=${{ secrets.JWT_KEY }}" \ |
| 74 | + "JWTSettings__Issuer=CoreIdentity" \ |
| 75 | + "JWTSettings__Audience=CoreIdentityUser" \ |
| 76 | + "JWTSettings__DurationInMinutes=60" \ |
| 77 | + "FeatureManagement__AuthEnabled=true" \ |
| 78 | + "ASPNETCORE_ENVIRONMENT=Production" |
| 79 | +
|
| 80 | + - name: Deploy to Azure App Service |
| 81 | + uses: azure/webapps-deploy@v3 |
| 82 | + with: |
| 83 | + app-name: ${{ env.APP_SERVICE_NAME }} |
| 84 | + package: ${{ env.PUBLISH_DIR }} |
0 commit comments