Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions .github/workflows/main_sxcicdfunc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Deploy DotNet project to Azure Function App

on:
[push]

# CONFIGURATION
# For help, go to https://github.com/Azure/Actions
#
# 1. Set up the following secrets in your repository:
# AZURE_FUNCTIONAPP_PUBLISH_PROFILE_77cf0f680355469b96c98d7748b87d23
#
# 2. Change these variables for your configuration:
env:
AZURE_FUNCTIONAPP_NAME: 'sxcicdfunc' # set this to your function app name on Azure
AZURE_FUNCTIONAPP_PACKAGE_PATH: 'labs/functions/cicd/ChainedFunctions' # set this to the path to your function app project, defaults to the repository root
DOTNET_VERSION: '6.0.x' # set this to the dotnet version to use (e.g. '2.1.x', '3.1.x', '5.0.x')

jobs:
build-and-deploy:
runs-on: windows-latest
environment: dev
steps:
- name: 'Checkout GitHub Action'
uses: actions/checkout@v3

- name: Setup DotNet ${{ env.DOTNET_VERSION }} Environment
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}

- name: 'Resolve Project Dependencies Using Dotnet'
shell: pwsh
run: |
pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
dotnet build --configuration Release --output ./output
popd

- name: 'Run Azure Functions Action'
uses: Azure/functions-action@v1
id: fa
with:
app-name: ${{ env.AZURE_FUNCTIONAPP_NAME }}
package: '${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}/output'
publish-profile: ${{ secrets.AZURE_FUNCTIONAPP_PUBLISH_PROFILE_77cf0f680355469b96c98d7748b87d23 }}

# For more samples to get started with GitHub Action workflows to deploy to Azure, refer to https://github.com/Azure/actions-workflow-samples
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using System;

namespace ChainedFunctions
{
public class HeartbeatCreatedMessage
{
public string BlobName {get; set;}
}
}
11 changes: 11 additions & 0 deletions labs/functions/cicd/ChainedFunctions/HeartbeatLogEntity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace ChainedFunctions
{
public class HeartbeatLogEntity
{
public string PartitionKey { get; set; }
public string RowKey { get; set; }
public string BlobName {get; set;}
}
}
31 changes: 31 additions & 0 deletions labs/functions/cicd/ChainedFunctions/NotifySubscribers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace ChainedFunctions
{
public class NotifySubscribers
{
[FunctionName("NotifySubscribers")]
[StorageAccount("StorageConnectionString")]
public async Task Run(
[BlobTrigger("heartbeat/{name}")] Stream uploadedBlob,
[ServiceBus("HeartbeatCreated", Connection = "ServiceBusConnectionString")] IAsyncCollector<dynamic> messages,
string name, ILogger log
)
{
log.LogInformation($"New heartbeat blob uploaded:{name}");

var message = new HeartbeatCreatedMessage
{
BlobName = name
};
await messages.AddAsync(message);

log.LogInformation("Published heartbeat message");
}
}
}
32 changes: 32 additions & 0 deletions labs/functions/cicd/ChainedFunctions/WriteLog.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Extensions.Logging;

namespace ChainedFunctions
{
public class UploadLog
{
[FunctionName("WriteLog")]
[StorageAccount("StorageConnectionString")]
public async Task Run(
[BlobTrigger("heartbeat/{name}")] Stream uploadedBlob,
[Table("heartbeats")] IAsyncCollector<HeartbeatLogEntity> entities,
string name, ILogger log)
{
log.LogInformation($"New heartbeat blob uploaded:{name}");

var entity = new HeartbeatLogEntity
{
PartitionKey = Guid.NewGuid().ToString().Substring(0,1),
RowKey = Guid.NewGuid().ToString(),
BlobName = name
};
await entities.AddAsync(entity);

log.LogInformation("Recorded heartbeat in Table Storage");
}
}
}