🔀 Merge pull request #369 from COS301-SE-2024/dev/feat/devops #38
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 BirdApi | |
env: | |
# DOTNET_ROOT: ./dotnet/BeakPeekApi/ | |
DOTNET_ROOT: . | |
AZURE_SQL_CONNECTIONSTRING: ${{ secrets.AZURE_SQL_CONNECTIONSTRING }} | |
on: | |
push: | |
branches: | |
- main | |
- development | |
paths-ignore: | |
- 'doc/**' | |
- 'res/**' | |
- 'beakpeek/**' | |
- 'dotnet/UserApi/**' | |
workflow_dispatch: | |
workflow_call: | |
jobs: | |
test_dotnet: | |
name: 🧪 Test dotnet BirdApi | |
uses: ./.github/workflows/dotnet.yml | |
secrets: inherit | |
build: | |
name: 🏛️ Build BirdApi | |
runs-on: ubuntu-latest | |
needs: [ test_dotnet ] | |
env: | |
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/birdapi/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/BirdApi/BeakPeekApi/packages.lock.json | |
- name: Get App Setting | |
run: | | |
cd ./dotnet/BirdApi/BeakPeekApi | |
cp ../../../appsettings.json . | |
- name: Restore Dependencies | |
run: | | |
cd ./dotnet/BirdApi/BeakPeekApi | |
dotnet restore --locked-mode | |
- name: Build with dotnet | |
run: dotnet build --configuration Release ./dotnet/BirdApi/BeakPeekApi/BeakPeekApi.csproj | |
- name: dotnet publish | |
run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/BeakPeekApi ./dotnet/BirdApi/BeakPeekApi/BeakPeekApi.csproj | |
- name: Copy CSV files | |
run: | | |
mkdir -p ${{env.DOTNET_ROOT}}/BeakPeekApi/res/species | |
cp -r ./res/species/* ${{env.DOTNET_ROOT}}/BeakPeekApi/res/species/ | |
mkdir -p ${{env.DOTNET_ROOT}}/BeakPeekApi/res/species_list/ | |
cp -r ./res/species_list/* ${{env.DOTNET_ROOT}}/BeakPeekApi/res/species_list/ | |
- name: Upload artifact for deployment job | |
uses: actions/upload-artifact@v4 | |
id: artifact-upload-step | |
with: | |
name: dotnet-birdapi | |
path: ${{env.DOTNET_ROOT}}/BeakPeekApi | |
deploy: | |
runs-on: ubuntu-latest | |
name: 🚀 Deploy BirdApi | |
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-birdapi | |
- name: Login to Azure | |
uses: azure/login@v1 | |
with: | |
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_F91BBE34AB4B45898BF82BFADF359BE8 }} | |
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_F1EE328E09964C2EA0E92A6629C60647 }} | |
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_97F61458BB2B43A89AB06261472988FE }} | |
- name: Deploy to Azure Web App | |
id: deploy-to-webapp | |
uses: azure/webapps-deploy@v2 | |
with: | |
app-name: 'BeakPeekBirdApi' | |
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 |