Skip to content

Provider-API-AzureFunction-CI #64

Provider-API-AzureFunction-CI

Provider-API-AzureFunction-CI #64

Workflow file for this run

name: Provider-API-AzureFunction-CI
on:
workflow_dispatch:
inputs:
application_name:
description: name_of_provider
required: true
default: 'SmartBearCoin-Payee-Provider'
demo_deploy:
description: skip deployment steps for demo
required: true
default: 'false'
# push:
# paths:
# - 'provider_azure_function/**'
# - '.github/workflows/ProviderCI.yml'
# - 'oas/**'
# pull_request:
# branches: ['main']
# paths:
# - '.github/workflows/ProviderCI.yml'
# - 'provider_azure_function/**'
# - 'oas/**'
env:
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'provider_azure_function' # set this to the path to your web app project, defaults to the repository root
DOTNET_VERSION: '7.0.302' # set this to the dotnet version to use
oas_file: oas/openapi-transformed.json
results_file: ReadyAPI_Tests/report.xml
PACT_BROKER_BASE_URL: https://smartbear.pactflow.io
PACT_BROKER_TOKEN: ${{ secrets.PACT_BROKER_TOKEN }}
application_name: ${{ github.event.inputs.application_name }}
application_name_default: SmartBearCoin-Payee-Provider
demo_deploy: ${{ github.event.inputs.demo_deploy }}
jobs:
setup:
name: 🏗️ setup
runs-on: ubuntu-latest
steps:
- run: echo "application_name=${application_name:-${application_name_default}}" >> $GITHUB_ENV
outputs:
application_name: ${{ env.application_name }}
test-local:
needs: setup
runs-on: ubuntu-latest
env:
application_name: ${{ needs.setup.outputs.application_name }}
steps:
- uses: actions/checkout@v3
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
- name: Install core tools
run: |
sudo apt-get update
sudo apt-get install azure-functions-core-tools-4
- name: get version of OAS
run: |
sudo snap install yq &&
OAS_VERSION=$(yq '.info.version' oas/openapi.yaml)
echo "OAS_VERSION=${OAS_VERSION}" >> $GITHUB_ENV
UNIQUE_VERSION=${OAS_VERSION}-${{ github.sha }}-service
echo "version=${UNIQUE_VERSION}" >> $GITHUB_ENV
- name: merge openapi spec
run: |
npx -y oas-merge ./oas/openapi.yaml
- name: Test
run: chmod ugo+rwx ReadyAPI_Tests && ./startServerAndTest.sh
env:
PROJECT_FOLDER: ReadyAPI_Tests
PROJECT_FILE: 'SmartBearCoin-Payee-Provider-readyapi-project.xml'
SLM_API_KEY: ${{ secrets.SLM_API_KEY }}
SERVER_DIR: provider_azure_function
SERVER_COMMAND: 'func start --csharp'
WAIT_FOR: 'http://localhost:7071'
ENDPOINT: http://localhost:7071/api
- uses: pactflow/actions/[email protected]
if: success()
- uses: pactflow/actions/[email protected]
if: failure()
env:
EXIT_CODE: 1
outputs:
version: ${{ env.version }}
can-i-deploy-acc:
needs: [setup, test-local]
runs-on: ubuntu-latest
env:
deploy_target: acceptance
application_name: ${{ needs.setup.outputs.application_name }}
steps:
- name: can-i-deploy ${{ env.application_name }} to ${{ env.deploy_target }}
uses: pactflow/actions/[email protected]
env:
to_environment: ${{ env.deploy_target }}
version: ${{ needs.test-local.outputs.version }}
# use ARM templates to set up the Azure Infra
deploy-infrastructure-acc:
runs-on: ubuntu-latest
environment: acc
needs: [test-local, can-i-deploy-acc]
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/mar2024-webinar-prep'
# set outputs needed by subsequent jobs
outputs:
azFunctionAppName: ${{ steps.armdeploy.outputs.functionAppName }}
steps:
# check out code
- uses: actions/checkout@main
# login to Azure
- uses: azure/login@v1
if: ${{ env.demo_deploy != 'true' }}
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# deploy ARM template to setup azure resources (group & sub defined in credentials)
- name: Run ARM deploy
if: ${{ env.demo_deploy != 'true' }}
id: armdeploy
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
resourceGroupName: ${{ secrets.AZURE_RG }}
template: ./provider_azure_function/azuredeploy.json
parameters: ./provider_azure_function/azuredeploy.acc.parameters.json
# use ARM templates to set up the Azure Infra
can-i-deploy-prd:
needs: [setup, test-local, test-acc]
runs-on: ubuntu-latest
env:
deploy_target: production
steps:
- name: can-i-deploy ${{ env.application_name }} to ${{ env.deploy_target }}
uses: pactflow/actions/[email protected]
env:
to_environment: ${{ env.deploy_target }}
version: ${{ needs.test-local.outputs.version }}
application_name: ${{ needs.setup.outputs.application_name }}
deploy-infrastructure-prd:
needs: [test-local, can-i-deploy-prd, record-deploy-acc]
runs-on: ubuntu-latest
environment: prd
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/mar2024-webinar-prep'
# set outputs needed by subsequent jobs
outputs:
azFunctionAppName: ${{ steps.armdeploy.outputs.functionAppName }}
steps:
# check out code
- uses: actions/checkout@main
# login to Azure
- uses: azure/login@v1
if: ${{ env.demo_deploy != 'true' }}
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# deploy ARM template to setup azure resources (group & sub defined in credentials)
- name: Run ARM deploy
if: ${{ env.demo_deploy != 'true' }}
id: armdeploy
uses: azure/arm-deploy@v1
with:
subscriptionId: ${{ secrets.AZURE_SUBSCRIPTION }}
resourceGroupName: ${{ secrets.AZURE_RG }}
template: ./provider_azure_function/azuredeploy.json
parameters: ./provider_azure_function/azuredeploy.prd.parameters.json
# build and deploy our Azure functions for Fintech Webinar
build-and-deploy-acc:
needs: [test-local, can-i-deploy-acc, deploy-infrastructure-acc]
runs-on: windows-latest
environment: acc
steps:
# check out code
- name: 'Checkout code'
uses: actions/checkout@main
# login to Azure
- uses: azure/login@v1
if: ${{ env.demo_deploy != 'true' }}
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
# get publish profile
- name: Get publish profile
if: ${{ env.demo_deploy != 'true' }}
id: fncapp
uses: azure/powershell@v1
with:
inlineScript: |
$profile = ""
$profile = Get-AzWebAppPublishingProfile -ResourceGroupName ${{ secrets.AZURE_RG }} -Name ${{ needs.deploy-infrastructure-acc.outputs.azFunctionAppName }}
$profile = $profile.Replace("`r", "").Replace("`n", "")
Write-Output "::set-output name=profile::$profile"
azPSVersion: 'latest'
# setup donet environments
- name: Setup DotNet Environments
if: ${{ env.demo_deploy != 'true' }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
6.0.x
${{ env.DOTNET_VERSION }}
# build project
- name: 'Resolve dependencies and build'
if: ${{ env.demo_deploy != 'true' }}
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet restore
dotnet build --configuration Release --output ./output
popd
# publish azure function
- name: 'Run Azure Functions Action'
if: ${{ env.demo_deploy != 'true' }}
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ needs.deploy-infrastructure-acc.outputs.azFunctionAppName }}
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ steps.fncapp.outputs.profile }}
# test our Azure functions for Fintech Webinar
test-acc:
needs: [record-deploy-acc]
runs-on: ubuntu-latest
environment: acc
steps:
# check out code
- name: 'Checkout code'
uses: actions/checkout@main
- name: Test
run: chmod ugo+rwx ReadyAPI_Tests && ./launchReadyAPITestRunner.sh
env:
PROJECT_FOLDER: ReadyAPI_Tests
PROJECT_FILE: 'SmartBearCoin-Payee-Provider-readyapi-project.xml'
SLM_API_KEY: ${{ secrets.SLM_API_KEY }}
ENDPOINT: https://sbdevrel-fua-smartbearcoin-acc1.azurewebsites.net/api
record-deploy-acc:
needs:
[
setup,
test-local,
deploy-infrastructure-acc,
can-i-deploy-acc,
build-and-deploy-acc
]
runs-on: ubuntu-latest
env:
deployed_env: acceptance
application_name: ${{ needs.setup.outputs.application_name }}
steps:
- name: record-deployment ${{ env.application_name }} to ${{ env.deployed_env }}
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/mar2024-webinar-prep'
uses: pactflow/actions/[email protected]
env:
environment: ${{ env.deployed_env }}
version: ${{ needs.test-local.outputs.version }}
# build and deploy our Azure functions for Fintech Webinar
build-and-deploy-prd:
needs:
[
test-local,
can-i-deploy-prd,
record-deploy-acc,
deploy-infrastructure-prd
]
runs-on: windows-latest
environment: prd
steps:
# check out code
- name: 'Checkout code'
uses: actions/checkout@main
# login to Azure
- uses: azure/login@v1
if: ${{ env.demo_deploy != 'true' }}
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
enable-AzPSSession: true
# get publish profile
- name: Get publish profile
if: ${{ env.demo_deploy != 'true' }}
id: fncapp
uses: azure/powershell@v1
with:
inlineScript: |
$profile = ""
$profile = Get-AzWebAppPublishingProfile -ResourceGroupName ${{ secrets.AZURE_RG }} -Name ${{ needs.deploy-infrastructure-prd.outputs.azFunctionAppName }}
$profile = $profile.Replace("`r", "").Replace("`n", "")
Write-Output "::set-output name=profile::$profile"
azPSVersion: 'latest'
# setup donet environments
- name: Setup DotNet Environments
if: ${{ env.demo_deploy != 'true' }}
uses: actions/setup-dotnet@v1
with:
dotnet-version: |
7.0.x
${{ env.DOTNET_VERSION }}
# build project
- name: 'Resolve dependencies and build'
if: ${{ env.demo_deploy != 'true' }}
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet restore
dotnet build --configuration Release --output ./output
popd
# publish azure function
- name: 'Run Azure Functions Action'
if: ${{ env.demo_deploy != 'true' }}
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ needs.deploy-infrastructure-prd.outputs.azFunctionAppName }}
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ steps.fncapp.outputs.profile }}
record-deploy-prd:
needs:
[
setup,
test-local,
deploy-infrastructure-prd,
can-i-deploy-prd,
build-and-deploy-prd
]
runs-on: ubuntu-latest
env:
deployed_env: production
application_name: ${{ needs.setup.outputs.application_name }}
steps:
- name: record-deployment ${{ env.application_name }} to ${{ env.deployed_env }}
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/mar2024-webinar-prep'
uses: pactflow/actions/[email protected]
env:
environment: ${{ env.deployed_env }}
version: ${{ needs.test-local.outputs.version }}
# test our Azure functions for Fintech Webinar
test-prd:
needs: [record-deploy-prd]
runs-on: ubuntu-latest
environment: acc
steps:
# check out code
- name: 'Checkout code'
uses: actions/checkout@main
- name: Test
run: chmod ugo+rwx ReadyAPI_Tests && ./launchReadyAPITestRunner.sh
env:
PROJECT_FOLDER: ReadyAPI_Tests
PROJECT_FILE: 'SmartBearCoin-Payee-Provider-readyapi-project.xml'
SLM_API_KEY: ${{ secrets.SLM_API_KEY }}
ENDPOINT: https://sbdevrel-fua-smartbearcoin-prd1.azurewebsites.net/api