I would to create a project in github actions, but I am pretty new to it, how to create,…
- User
I would to create a project in github actions, but I am pretty new to it, how to create, repo, push, PRs ... Basically it would a pipeline to create azure infra using BICEP (1 single BICEP file for now), I want a function app in .net that zip a txt file every time a txt file is uploaded to the storage account so for the pipeline infra it would be a resource group app service plan B1 function app and its storage account and storage account, I mean another storagre account which function app mointors when a file is uploaded and another pipeline to create the build with the function app logic in .Net and injected in the function app. I am also new to Visual studio Code so please guide me how to create the function app in it I mean what should I do in the IDE can you help me to do that?
I want to run infra and build for function app on demand manually
Assistant
I'll help you create this project step by step. Let's break this down into manageable parts:
Part 1: Setting up GitHub and Repository
First, let's create your GitHub repository:
-
Create a GitHub account (if you don't have one):
- Go to https://github.com and sign up
-
Create a new repository:
- Click the "+" icon in the top right → "New repository"
- Name it something like
azure-function-zip-project - Make it public or private as you prefer
- Initialize with a README
- Click "Create repository"
-
Clone the repository locally:
git clone https://github.com/YOUR_USERNAME/azure-function-zip-project.git cd azure-function-zip-project
Part 2: Project Structure
Create this folder structure in your repository:
azure-function-zip-project/ ├── .github/ │ └── workflows/ │ ├── deploy-infrastructure.yml │ └── deploy-function.yml ├── infrastructure/ │ └── main.bicep ├── src/ │ └── FileZipperFunction/ │ ├── FileZipperFunction.csproj │ ├── FileZipTrigger.cs │ └── host.json └── README.mdPart 3: Create the Bicep Infrastructure File
Create
infrastructure/main.bicep:param location string = resourceGroup().location param functionAppName string = 'func-filezipper-${uniqueString(resourceGroup().id)}' param storageAccountName string = 'stfunc${uniqueString(resourceGroup().id)}' param monitoredStorageAccountName string = 'stmon${uniqueString(resourceGroup().id)}' param appServicePlanName string = 'asp-filezipper-${uniqueString(resourceGroup().id)}' // Storage Account for Function App resource functionStorageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = { name: storageAccountName location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' } // Storage Account to Monitor resource monitoredStorageAccount 'Microsoft.Storage/storageAccounts@2021-09-01' = { name: monitoredStorageAccountName location: location sku: { name: 'Standard_LRS' } kind: 'StorageV2' } // App Service Plan resource appServicePlan 'Microsoft.Web/serverfarms@2021-03-01' = { name: appServicePlanName location: location sku: { name: 'B1' tier: 'Basic' } } // Function App resource functionApp 'Microsoft.Web/sites@2021-03-01' = { name: functionAppName location: location kind: 'functionapp' properties: { serverFarmId: appServicePlan.id siteConfig: { netFrameworkVersion: 'v6.0' appSettings: [ { name: 'AzureWebJobsStorage' value: 'DefaultEndpointsProtocol=https;AccountName=${functionStorageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${functionStorageAccount.listKeys().keys[0].value}' } { name: 'FUNCTIONS_EXTENSION_VERSION' value: '~4' } { name: 'FUNCTIONS_WORKER_RUNTIME' value: 'dotnet' } { name: 'MonitoredStorageConnection' value: 'DefaultEndpointsProtocol=https;AccountName=${monitoredStorageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${monitoredStorageAccount.listKeys().keys[0].value}' } ] } } } output functionAppName string = functionApp.name output monitoredStorageAccountName string = monitoredStorageAccount.namePart 4: Create the Function App in Visual Studio Code
-
Install required tools:
- Install Visual Studio Code
- Install .NET 6.0 SDK or later
- Install Azure Functions Core Tools
- Install the Azure Functions extension in VS Code
-
Create the Function App project:
Create
src/FileZipperFunction/FileZipperFunction.csproj:<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>net6.0</TargetFramework> <AzureFunctionsVersion>v4</AzureFunctionsVersion> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage" Version="5.0.1" /> <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" /> <PackageReference Include="System.IO.Compression" Version="4.3.0" /> </ItemGroup> <ItemGroup> <None Update="host.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> </None> <None Update="local.settings.json"> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToPublishDirectory>Never</CopyToPublishDirectory> </None> </ItemGroup> </Project>Create
src/FileZipperFunction/FileZipTrigger.cs:using System; using System.IO; using System.IO.Compression; using System.Threading.Tasks; using Microsoft.Azure.WebJobs; using Microsoft.Extensions.Logging; using Azure.Storage.Blobs; namespace FileZipperFunction { public static class FileZipTrigger { [FunctionName("FileZipTrigger")] public static async Task Run( [BlobTrigger("uploads/{name}", Connection = "MonitoredStorageConnection")] Stream myBlob, string name, [Blob("zipped/{name}.zip", FileAccess.Write, Connection = "MonitoredStorageConnection")] Stream outputBlob, ILogger log) { log.LogInformation($"C# Blob trigger function processing blob\n Name:{name} \n Size: {myBlob.Length} Bytes"); try { // Create a zip archive in memory using (var zipArchive = new ZipArchive(outputBlob, ZipArchiveMode.Create, true)) { // Add the file to the zip var zipEntry = zipArchive.CreateEntry(name, CompressionLevel.Optimal); using (var zipStream = zipEntry.Open()) { await myBlob.CopyToAsync(zipStream); } } log.LogInformation($"Successfully zipped file: {name}"); } catch (Exception ex) { log.LogError($"Error zipping file {name}: {ex.Message}"); throw; } } } }Create
src/FileZipperFunction/host.json:{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } } }Part 5: Create GitHub Actions Workflows
Create
.github/workflows/deploy-infrastructure.yml:name: Deploy Infrastructure on: workflow_dispatch: env: AZURE_RESOURCEGROUP_NAME: rg-filezipper-function LOCATION: eastus jobs: deploy-infrastructure: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Azure Login uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Create Resource Group uses: azure/CLI@v1 with: inlineScript: | az group create --name ${{ env.AZURE_RESOURCEGROUP_NAME }} --location ${{ env.LOCATION }} - name: Deploy Bicep uses: azure/arm-deploy@v1 with: resourceGroupName: ${{ env.AZURE_RESOURCEGROUP_NAME }} template: ./infrastructure/main.bicep deploymentName: 'deploy-${{ github.run_number }}'Create
.github/workflows/deploy-function.yml:name: Deploy Function App on: workflow_dispatch: env: AZURE_RESOURCEGROUP_NAME: rg-filezipper-function DOTNET_VERSION: '6.0.x' jobs: build-and-deploy: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup .NET uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Azure Login uses: azure/login@v1 with: creds: ${{ secrets.AZURE_CREDENTIALS }} - name: Get Function App Name id: getfunctionapp uses: azure/CLI@v1 with: inlineScript: | functionAppName=$(az functionapp list -g ${{ env.AZURE_RESOURCEGROUP_NAME }} --query "[0].name" -o tsv) echo "FUNCTION_APP_NAME=$functionAppName" >> $GITHUB_OUTPUT - name: Build Function App run: | cd src/FileZipperFunction dotnet restore dotnet build --configuration Release dotnet publish -c Release -o ./publish - name: Deploy to Azure Functions uses: Azure/functions-action@v1 with: app-name: ${{ steps.getfunctionapp.outputs.FUNCTION_APP_NAME }} package: './src/FileZipperFunction/publish'Part 6: Setting up Azure Credentials
-
Create an Azure Service Principal:
az ad sp create-for-rbac --name "github-actions-sp" --role contributor --scopes /subscriptions/{subscription-id} --sdk-auth -
Copy the JSON output and add it as a GitHub secret:
- Go to your GitHub repository → Settings → Secrets and variables → Actions
- Click "New repository secret"
- Name:
AZURE_CREDENTIALS - Value: Paste the JSON output
Part 7: Pushing Code and Creating PRs
-
Add and commit your files:
git add . git commit -m "Initial project setup with infrastructure and function app" -
Push to GitHub:
git push origin main -
Creating Pull Requests (for future changes):
# Create a new branch git checkout -b feature/my-new-feature # Make your changes # Add and commit git add . git commit -m "Add new feature" # Push the branch git push origin feature/my-new-featureThen go to GitHub and you'll see a prompt to create a Pull Request.
Part 8: Running the Pipelines
- Go to your GitHub repository
- Click on "Actions" tab
- You'll see two workflows:
- "Deploy Infrastructure" - Run this first
- "Deploy Function App" - Run this after infrastructure is deployed
- Click on a workflow → "Run workflow" → "Run workflow"
Testing Your Function
After deployment:
- Go to Azure Portal
- Find your monitored storage account
- Create a container called "uploads"
- Create a container called "zipped"
- Upload a .txt file to the "uploads" container
- Check the "zipped" container for the zipped file
This setup gives you a complete CI/CD pipeline with manual triggers for both infrastructure and function app deployment. The function will automatically zip any text file uploaded to the monitored storage account.
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.