Skip to content

Commit

Permalink
Add reusable workflow to staging
Browse files Browse the repository at this point in the history
  • Loading branch information
jackreimers committed Aug 23, 2023
1 parent e3924b1 commit 51a9699
Show file tree
Hide file tree
Showing 2 changed files with 130 additions and 102 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/deploy-reusable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Reusable Build and Deploy

on:
workflow_call:
inputs:
# The environment to deploy to (Staging or Production)
EnvironmentName:
required: true
type: string
# The name of the resource in Azure
AzureWebAppName:
required: true
type: string
# The URL for the relevant API
ApiBaseUrl:
required: true
type: string

secrets:
AzureWebAppSecret:
required: true
AzureStaticWebAppsApiToken:
required: true
GithubRepoToken:
required: true

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3.3.0

- name: Set up .NET Core
uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: '7.x'

# https://stackoverflow.com/questions/60521929/change-variables-in-appsettings-when-deploying-with-github-actions
# This will fail if done before the build step
- name: App Settings Variable Substitution
uses: microsoft/variable-substitution@v1
with:
files: './src/WebUI/wwwroot/appsettings.json'
env:
ApiBaseUrl: ${{ github.event.inputs['ApiBaseUrl'] }}

- name: Build with dotnet
run: dotnet build --configuration Release

- name: dotnet publish WebAPI
run: dotnet publish ./src/WebAPI -c Release -o ./publish/api

- name: dotnet publish WebUI
run: dotnet publish ./src/WebUI -c Release -o ./publish/ui

- name: Upload API artifact for deployment job
uses: actions/upload-artifact@v3.1.2
with:
name: .net-app-api
path: ./publish/api

- name: Upload WebUI artifact for deployment job
uses: actions/upload-artifact@v3.1.2
with:
name: .net-app-webui
path: ./publish/ui

deploy-api:
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ github.event.inputs['EnvironmentName'] }}
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3.0.2
with:
name: .net-app-api

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: "${{ github.event.inputs['AzureWebAppName'] }}"
slot-name: 'Production' # The environment in Azure, Production is just the name of the slot
publish-profile: ${{ secrets.AzureWebAppSecret }}
package: .

deploy-webui:
runs-on: ubuntu-latest
needs: build
environment:
name: ${{ github.event.inputs['EnvironmentName'] }}
url: ${{ steps.deploy-to-staticwebapp.outputs.static_web_app_url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3.0.2
with:
name: .net-app-webui

- name: Deploy Static Web App
id: deploy-to-staticwebapp
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ secrets.AzureStaticWebAppsApiToken }}
repo_token: ${{ secrets.GithubRepoToken }} # Used for Github integrations (i.e. PR comments)
skip_app_build: true
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "./wwwroot" # App source code path
config_file_location: "./"
api_location: '' # Api source code path - optional
output_location: '' # Built app content directory - optional
###### End of Repository/Build Configurations ######
112 changes: 10 additions & 102 deletions .github/workflows/ssw-rulesgpt-stage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,111 +9,19 @@ on:
- main
workflow_dispatch:

env:
# DeploymentEnvironment: 'Staging'
AzureWebAppName: 'ssw-rulesgpt-api-stage' # The name of the resource in Azure
AzureWebAppSecret: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_706C909B7DCB4379927A9D3AF3D8B5EF }}
AzureStaticWebAppsApiToken: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ASHY_MEADOW_0A2BAD900 }}
GithubRepoToken: ${{ secrets.GITHUB_TOKEN }}
ApiBaseUrl: ${{ vars.API_BASE_URL }}

jobs:
build:
runs-on: ubuntu-latest
environment:
name: 'Staging'
url: ${{ steps.deploy-to-staticwebapp.outputs.static_web_app_url }}


steps:
- uses: actions/checkout@v3.3.0

- name: Set up .NET Core
uses: actions/setup-dotnet@v3.0.3
with:
dotnet-version: '7.x'

# https://stackoverflow.com/questions/60521929/change-variables-in-appsettings-when-deploying-with-github-actions
# This will fail if done before the build step
- name: App Settings Variable Substitution
uses: microsoft/variable-substitution@v1
- name: Call Reusable Build and Deploy
uses: ./.github/workflows/deploy-reusable.yml
with:
files: './src/WebUI/wwwroot/appsettings.json'
EnvironmentName: 'Staging'
AzureWebAppName: 'ssw-rulesgpt-api-stage'
ApiBaseUrl: ${{ vars.API_BASE_URL }}

env:
ApiBaseUrl: ${{ env.ApiBaseUrl }}

- name: Build with dotnet
run: dotnet build --configuration Release

- name: dotnet publish WebAPI
run: dotnet publish ./src/WebAPI -c Release -o ./publish/api

- name: dotnet publish WebUI
run: dotnet publish ./src/WebUI -c Release -o ./publish/ui

# TODO: Build and run unit tests

# Changes the base-tag in index.html from '/' to 'rulesgpt' to match SSW subdirectory
# - name: Change base-tag in index.html from / to rulesgpt
# run: sed -i 's/<base href="\/" \/>/<base href="\/rulesgpt\/" \/>/g' ${{env.DOTNET_ROOT}}/myapp/webui/wwwroot/index.html

- name: Upload API artifact for deployment job
uses: actions/upload-artifact@v3.1.2
with:
name: .net-app-api
path: ./publish/api

- name: Upload WebUI artifact for deployment job
uses: actions/upload-artifact@v3.1.2
with:
name: .net-app-webui
path: ./publish/ui

deploy-api:
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.0.2
with:
name: .net-app-api

- name: Deploy to Azure Web App
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: "${{ env.AzureWebAppName }}"
slot-name: 'Production' # The environment in Azure, Production is just the name of the slot
publish-profile: ${{ env.AzureWebAppSecret }}
package: .

deploy-webui:
runs-on: ubuntu-latest
needs: build
environment:
name: 'Staging'
url: ${{ steps.deploy-to-staticwebapp.outputs.static_web_app_url }}
steps:
- name: Download artifact from build job
uses: actions/download-artifact@v3.0.2
with:
name: .net-app-webui

- name: Deploy Static Web App
id: deploy-to-staticwebapp
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ env.AzureStaticWebAppsApiToken }}
repo_token: ${{ env.GithubRepoToken }} # Used for Github integrations (i.e. PR comments)
skip_app_build: true
action: "upload"
###### Repository/Build Configurations - These values can be configured to match your app requirements. ######
# For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
app_location: "./wwwroot" # App source code path
config_file_location: "./"
api_location: '' # Api source code path - optional
output_location: '' # Built app content directory - optional
###### End of Repository/Build Configurations ######
AzureWebAppSecret: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_706C909B7DCB4379927A9D3AF3D8B5EF }}
AzureStaticWebAppsApiToken: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_ASHY_MEADOW_0A2BAD900 }}
GithubRepoToken: ${{ secrets.GITHUB_TOKEN }}

0 comments on commit 51a9699

Please sign in to comment.