|
| 1 | +name: Deploy Azure Functions |
| 2 | + |
| 3 | +env: |
| 4 | + AZURE_FUNCTIONAPP_NAME: nfderpidlfunc |
| 5 | + AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' |
| 6 | + DOTNET_VERSION: '6.*' |
| 7 | + Location: 'southcentralus' |
| 8 | + ResourceGroupName: 'nf-derpidl-dev' |
| 9 | + DEV_ResourceGroupName: 'nf-derpidl-dev' |
| 10 | + PRD_ResourceGroupName: 'nf-derpidl-new-prd' |
| 11 | + |
| 12 | +on: |
| 13 | + push: |
| 14 | + paths: |
| 15 | + - 'bicep/**' |
| 16 | + - 'src/**' |
| 17 | + - 'tests/**' |
| 18 | + |
| 19 | +jobs: |
| 20 | + build: |
| 21 | + runs-on: ubuntu-latest |
| 22 | + steps: |
| 23 | + - uses: actions/checkout@v3 |
| 24 | + with: |
| 25 | + fetch-depth: 0 |
| 26 | + - name: Setup .NET |
| 27 | + uses: actions/setup-dotnet@v2 |
| 28 | + with: |
| 29 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 30 | + - name: Setup dependency caching for faster builds |
| 31 | + uses: actions/cache@v3 |
| 32 | + with: |
| 33 | + path: ~/.nuget/packages |
| 34 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} |
| 35 | + restore-keys: | |
| 36 | + ${{ runner.os }}-nuget- |
| 37 | + - name: Build with .NET |
| 38 | + run: dotnet build --configuration Release |
| 39 | + - name: dotnet publish |
| 40 | + run: dotnet publish -c Release -o ${{ env.DOTNET_ROOT }}/myapp |
| 41 | + - name: Upload artifact for deployment job |
| 42 | + uses: actions/upload-artifact@v3 |
| 43 | + with: |
| 44 | + name: .net-app |
| 45 | + path: ${{ env.DOTNET_ROOT }}/myapp |
| 46 | + |
| 47 | + bicep-development: |
| 48 | + runs-on: ubuntu-latest |
| 49 | + environment: development |
| 50 | + outputs: |
| 51 | + functionAppName: ${{ steps.bicep.outputs.functionAppName }} |
| 52 | + functionAppUrl: ${{ steps.bicep.outputs.functionAppUrl }} |
| 53 | + steps: |
| 54 | + - uses: actions/checkout@v3 |
| 55 | + with: |
| 56 | + fetch-depth: 0 |
| 57 | + |
| 58 | + - name: Login via Azure CLI |
| 59 | + uses: azure/login@v1 |
| 60 | + with: |
| 61 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 62 | + |
| 63 | + - name: Create Resource Group |
| 64 | + run: az group create --location ${{ env.Location }} --resource-group ${{ env.ResourceGroupName }} |
| 65 | + |
| 66 | + - id: bicep |
| 67 | + uses: azure/arm-deploy@v1 |
| 68 | + with: |
| 69 | + scope: resourcegroup |
| 70 | + resourceGroupName: ${{ env.ResourceGroupName }} |
| 71 | + region: ${{ env.Location }} |
| 72 | + template: bicep/deploy.bicep |
| 73 | + |
| 74 | + deploy-development: |
| 75 | + runs-on: ubuntu-latest |
| 76 | + environment: |
| 77 | + name: development |
| 78 | + url: ${{ needs.bicep-development.outputs.functionAppUrl }} |
| 79 | + needs: [build, bicep-development] |
| 80 | + steps: |
| 81 | + - name: Download artifact from build job |
| 82 | + uses: actions/download-artifact@v3 |
| 83 | + with: |
| 84 | + name: .net-app |
| 85 | + |
| 86 | + - name: Login via Azure CLI |
| 87 | + uses: azure/login@v1 |
| 88 | + with: |
| 89 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 90 | + |
| 91 | + - name: Deploy to Azure Function App |
| 92 | + id: fa |
| 93 | + uses: azure/functions-action@v1 |
| 94 | + with: |
| 95 | + app-name: ${{ needs.bicep-development.outputs.functionAppName }} |
| 96 | + package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} |
| 97 | + |
| 98 | + clean-development: |
| 99 | + runs-on: ubuntu-latest |
| 100 | + environment: clean |
| 101 | + needs: deploy-development |
| 102 | + steps: |
| 103 | + - name: Login via Azure CLI |
| 104 | + uses: azure/login@v1 |
| 105 | + with: |
| 106 | + creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 107 | + |
| 108 | + - name: Delete Resource Group |
| 109 | + run: az group delete --resource-group ${{ env.ResourceGroupName }} --yes |
| 110 | + |
| 111 | + # bicep-production: |
| 112 | + # runs-on: ubuntu-latest |
| 113 | + # environment: production |
| 114 | + # needs: [deploy-development] |
| 115 | + # outputs: |
| 116 | + # functionAppName: ${{ steps.bicep.outputs.functionAppName }} |
| 117 | + # functionAppUrl: ${{ steps.bicep.outputs.functionAppUrl }} |
| 118 | + # steps: |
| 119 | + # - uses: actions/checkout@v3 |
| 120 | + # with: |
| 121 | + # fetch-depth: 0 |
| 122 | + |
| 123 | + # - name: Login via Azure CLI |
| 124 | + # uses: azure/login@v1 |
| 125 | + # with: |
| 126 | + # creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 127 | + |
| 128 | + # - name: Create Resource Group |
| 129 | + # run: az group create --location ${{ env.Location }} --resource-group ${{ env.PRD_ResourceGroupName }} |
| 130 | + |
| 131 | + # - id: bicep |
| 132 | + # uses: azure/arm-deploy@v1 |
| 133 | + # with: |
| 134 | + # scope: resourcegroup |
| 135 | + # resourceGroupName: ${{ env.PRD_ResourceGroupName }} |
| 136 | + # region: ${{ env.Location }} |
| 137 | + # template: bicep/deploy.bicep |
| 138 | + |
| 139 | + # deploy-production: |
| 140 | + # runs-on: ubuntu-latest |
| 141 | + # environment: |
| 142 | + # name: production |
| 143 | + # url: ${{ needs.bicep-production.outputs.functionAppUrl }} |
| 144 | + # needs: [build, bicep-production] |
| 145 | + # steps: |
| 146 | + # - name: Download artifact from build job |
| 147 | + # uses: actions/download-artifact@v3 |
| 148 | + # with: |
| 149 | + # name: .net-app |
| 150 | + |
| 151 | + # - name: Login via Azure CLI |
| 152 | + # uses: azure/login@v1 |
| 153 | + # with: |
| 154 | + # creds: ${{ secrets.AZURE_CREDENTIALS }} |
| 155 | + |
| 156 | + # - name: Deploy to Azure Function App |
| 157 | + # id: fa |
| 158 | + # uses: azure/functions-action@v1 |
| 159 | + # with: |
| 160 | + # app-name: ${{ needs.bicep-production.outputs.functionAppName }} |
| 161 | + # package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }} |
0 commit comments