Skip to content

Create build-and-deploy.yml #1

Create build-and-deploy.yml

Create build-and-deploy.yml #1

name: Build, deploy to Azure Web App, promote to production
env:
AZURE_WEBAPP_NAME: steeltoe-mainsite
AZURE_WEBAPP_PACKAGE_PATH: '.'
DOTNET_VERSION: '8.0'
SLOT_NAME: staging
RESOURCE_GROUP: Steeltoe
on:
push:
branches: [ "main" ]
workflow_dispatch:
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up .NET Core
uses: actions/setup-dotnet@v2
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Set up dependency caching for faster builds
uses: actions/cache@v3
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: |
${{ runner.os }}-nuget-
- name: Build with dotnet
run: dotnet build src/Client --configuration Release
- name: dotnet publish
run: dotnet publish src/Client -c Release -o ${{env.DOTNET_ROOT}}/mainsite
- name: Upload artifact for deployment job
uses: actions/upload-artifact@v3
with:
name: Steeltoe-MainSite
path: ${{env.DOTNET_ROOT}}/mainsite
deploy-to-staging:
permissions:
contents: none
runs-on: ubuntu-latest
needs: build
environment:
name: 'Staging'
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3
with:
name: Steeltoe-MainSite
- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}
slot-name: ${{ env.SLOT_NAME }}
# promote-to-production:
# name: Promote to production
# needs: deploy-to-staging
# runs-on: ubuntu-latest
# environment:
# name: 'Production'
# url: 'https://${{ env.AZURE_WEBAPP_NAME }}.azurewebsites.net/'
# steps:
# - name: Log into Azure CLI with service principal
# uses: azure/[email protected]
# with:
# creds: ${{ secrets.AZURE_CREDENTIALS }}
# - name: Swap slots
# run: az webapp deployment slot swap -s ${{ env.SLOT_NAME }} -n ${{ env.AZURE_WEBAPP_NAME }} -g ${{ env.RESOURCE_GROUP }}