🔀 Merge pull request #371 from COS301-SE-2024/dev/fix/auto_import #31
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: 🚀 Deploy Dotnet UserApi | |
env: | |
DOTNET_ROOT: . | |
on: | |
push: | |
branches: | |
- main | |
- development | |
paths-ignore: | |
- 'doc/**' | |
- 'res/**' | |
- 'beakpeek/**' | |
- 'dotnet/BirdApi/**' | |
workflow_dispatch: | |
workflow_call: | |
jobs: | |
build: | |
name: 🏛️ Build UserApi | |
runs-on: ubuntu-latest | |
env: | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/userapi/packages | |
outputs: | |
artifact_url: ${{ steps.artifact-upload-step.outputs.artifact-url}} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up .NET Core | |
uses: actions/setup-dotnet@v4 | |
with: | |
dotnet-version: '8.x' | |
cache: true | |
cache-dependency-path: ./dotnet/UserApi/UserApi/packages.lock.json | |
- name: Get App Setting | |
run: | | |
cd ./dotnet/UserApi/UserApi | |
cp ../../../appsettings.json . | |
- name: Restore Dependencies | |
run: | | |
cd ./dotnet/UserApi/UserApi | |
dotnet restore --locked-mode | |
- name: Build with dotnet | |
run: dotnet build --configuration Release ./dotnet/UserApi/UserApi/UserApi.csproj | |
- name: dotnet publish | |
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/UserApi ./dotnet/UserApi/UserApi/UserApi.csproj | |
- name: Upload artifact for deployment job | |
id: artifact-upload-step | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dotnet-userapi | |
path: ${{env.DOTNET_ROOT}}/UserApi | |
deploy: | |
runs-on: ubuntu-latest | |
name: 🚀 Deploy UserApi | |
needs: [ build ] | |
environment: | |
name: 'Production' | |
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }} | |
permissions: | |
id-token: write #This is required for requesting the JWT | |
steps: | |
- name: Download artifact from build job | |
uses: actions/download-artifact@v4 | |
with: | |
name: dotnet-userapi | |
- name: Login to Azure | |
uses: azure/login@v2 | |
with: | |
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_B556361464624DEBB42BF2DC59698DCF }} | |
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_C8847AFCA0AA461FBC4F817E352AF220 }} | |
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_EE92CF8E523348EBBA87A7F4C8B0D4DA }} | |
- name: Deploy to Azure Web App | |
id: deploy-to-webapp | |
uses: azure/webapps-deploy@v3 | |
with: | |
app-name: 'BeakPeekUserApi' | |
slot-name: 'Production' | |
package: . | |
notify_discord: | |
name: 🔔 Send Discord notification about deployment | |
needs: [ deploy, build] | |
if: ${{ !cancelled() && (success() || failure()) }} | |
uses: ./.github/workflows/discord.yml | |
with: | |
content: "${{ contains(needs.deploy.result, 'success') && 'Successfully deployed' || 'Error during deployment of' }} ${{ github.ref_name }} for Azure" | |
title: "${{ contains(needs.deploy.result, 'success') && 'Successfully deployed' || 'Error during deployment of' }} ${{ github.ref_name }} for Azure" | |
url: ${{ needs.build.outputs.artifact_url }} | |
description: "${{ contains(needs.deploy.result, 'success') && 'Deployed:' || 'Deployment failed:' }} ${{ github.event.head_commit.message }}" | |
color: ${{ contains(needs.deploy.result, 'success') && 65280 || 16711680 }} | |
secrets: inherit |