Skip to content

Commit 37165b0

Browse files
jesshill99HowardvanRooijenMikeEvansLarahJamesDawsonJessica Hill
authored
Add GitHub Actions build (#449)
--------- Co-authored-by: Howard van Rooijen <Howard.vanRooijen@endjin.com> Co-authored-by: Mike Evans-Larah <mike.evans-larah@endjin.com> Co-authored-by: James Dawson <james.dawson@endjin.com> Co-authored-by: Jessica Hill <Jessica.Hill@endjin.com>
1 parent 95d02bc commit 37165b0

File tree

5 files changed

+132
-4
lines changed

5 files changed

+132
-4
lines changed

.github/workflows/build.yml

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
name: build
2+
on:
3+
push:
4+
branches:
5+
- main
6+
tags:
7+
- '*'
8+
pull_request:
9+
branches:
10+
- main
11+
workflow_dispatch:
12+
inputs:
13+
forcePublish:
14+
description: When true the Publish stage will always be run, otherwise it only runs for tagged versions.
15+
required: false
16+
default: false
17+
type: boolean
18+
skipCleanup:
19+
description: When true the pipeline clean-up stage will not be run. For example, the cache used between pipeline stages will be retained.
20+
required: false
21+
default: false
22+
type: boolean
23+
24+
concurrency:
25+
group: ${{ github.workflow }}-${{ github.ref }}
26+
cancel-in-progress: true
27+
28+
permissions:
29+
actions: write # enable cache clean-up
30+
checks: write # enable test result annotations
31+
contents: write # enable creating releases
32+
issues: read
33+
packages: write # enable publishing packages
34+
pull-requests: write # enable test result annotations
35+
36+
jobs:
37+
prepareConfig:
38+
name: Prepare Configuration
39+
runs-on: ubuntu-latest
40+
outputs:
41+
RESOLVED_ENV_VARS: ${{ steps.prepareEnvVarsAndSecrets.outputs.environmentVariablesYamlBase64 }}
42+
RESOLVED_SECRETS: ${{ steps.prepareEnvVarsAndSecrets.outputs.secretsYamlBase64 }}
43+
steps:
44+
# Declare any environment variables and/or secrets that need to be available inside the build process
45+
- uses: endjin/Endjin.RecommendedPractices.GitHubActions/actions/prepare-env-vars-and-secrets@main
46+
id: prepareEnvVarsAndSecrets
47+
with:
48+
# BUILDVAR_NuGetPublishSource:
49+
# When publishing NuGet packages only tagged versions get pushed to nuget.org, otherwise
50+
# they are pushed to GitHub Packages
51+
# BUILDVAR_UseAcrTasks:
52+
# Due to the build phases running as separate jobs the container images built via 'docker build'
53+
# in the Package phase are not available to the Publish phase. Therefore, we use ACR Tasks to
54+
# build the images instead.
55+
environmentVariablesYaml: |
56+
BUILDVAR_NuGetPublishSource: "${{ startsWith(github.ref, 'refs/tags/') && 'https://api.nuget.org/v3/index.json' || 'https://nuget.pkg.github.com/endjin/index.json' }}"
57+
BUILDVAR_ContainerRegistryFqdn: endjin.azurecr.io
58+
BUILDVAR_UseAcrTasks: true
59+
secretsYaml: |
60+
NUGET_API_KEY: "${{ startsWith(github.ref, 'refs/tags/') && secrets.ENDJIN_NUGET_APIKEY || secrets.ENDJIN_GITHUB_PUBLISHER_PAT }}"
61+
62+
build:
63+
needs: prepareConfig
64+
uses: endjin/Endjin.RecommendedPractices.GitHubActions/.github/workflows/scripted-build-matrix-pipeline.yml@main
65+
with:
66+
netSdkVersion: '8.x'
67+
# workflow_dispatch inputs are always strings, the type property is just for the UI
68+
forcePublish: ${{ github.event.inputs.forcePublish == 'true' }}
69+
skipCleanup: ${{ github.event.inputs.skipCleanup == 'true' }}
70+
71+
# These pass arbitrary environment variables to each of the build pipeline phases,
72+
# as defined in the 'environmentVariablesYaml' property above.
73+
compilePhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }}
74+
testPhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }}
75+
testPhaseMatrixJson: |
76+
{
77+
"os": ["ubuntu-latest", "windows-latest"],
78+
"dotnetFramework": ["net8.0"],
79+
"exclude": []
80+
}
81+
packagePhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }}
82+
publishPhaseEnv: ${{ needs.prepareConfig.outputs.RESOLVED_ENV_VARS }}
83+
secrets:
84+
# Ensures the build pipeline has access to pull images from the ACR and write SBOMs to storage
85+
compilePhaseAzureCredentials: ${{ secrets.ENDJIN_PROD_ACR_READER_CREDENTIALS }}
86+
# Ensures the build pipeline has access to run ACR Tasks
87+
packagePhaseAzureCredentials: ${{ secrets.ENDJIN_PROD_ACR_PUBLISH_CREDENTIALS }}
88+
# Ensures the build pipeline has access to push/re-tag images to the ACR
89+
publishPhaseAzureCredentials: ${{ secrets.ENDJIN_PROD_ACR_PUBLISH_CREDENTIALS }}
90+
91+
# Uncomment the following to pass arbitrary secrets to the required build pipeline phases,
92+
# as defined in the 'secretsYaml' property above. They will be available to the
93+
# scripted build process as environment variables.
94+
#
95+
# compilePhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }}
96+
# testPhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }}
97+
packagePhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }}
98+
publishPhaseSecrets: ${{ needs.prepareConfig.outputs.RESOLVED_SECRETS }}

Solutions/Corvus.Testing.AzureFunctions.DemoFunction.InProcess/SampleFunction.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,4 @@ public async Task<IActionResult> SampleGetHandler(
6060
: new BadRequestObjectResult("Please pass a name on the query string or in the request body");
6161
}
6262
}
63-
}
63+
}

Solutions/Corvus.Testing.AzureFunctions.DemoFunctions.Isolated/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
.ConfigureFunctionsWorkerDefaults()
55
.Build();
66

7-
host.Run();
7+
host.Run();

Solutions/Corvus.Testing.AzureFunctions.SpecFlow.Demo/AzureFunctionsTesting/DemoFunctionConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ public static void SetupTestConfig(SpecFlowContext context)
2929
functionConfiguration.CopyToEnvironmentVariables(config);
3030
}
3131
}
32-
}
32+
}

build.ps1

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#Requires -Version 7
12
<#
23
.SYNOPSIS
34
Runs a .NET flavoured build process.
@@ -133,6 +134,11 @@ $SkipPackage = $false
133134
$SkipPublish = $false
134135

135136

137+
# NOTE: Install the 'Endjin.RecommendedPractices.Build' VS Code extension to get handy
138+
# snippets for enabling & configuring features in this build script.
139+
# Once installed <CTRL-ALT-J> will open the snippet picker and you can type 'build'
140+
# to see the available snippets.
141+
136142
#
137143
# Build process configuration
138144
#
@@ -152,6 +158,30 @@ $NuSpecFilesToPackage = @(
152158
#
153159
$ExcludeFilesFromCodeCoverage = ""
154160

161+
# Bump version to one that supports installing on .NET 8.0
162+
$covenantVersion = "0.19.0"
163+
164+
task Install-AzureFunctionsSDK {
165+
166+
$existingVersion = ""
167+
if ((Get-Command func -ErrorAction Ignore)) {
168+
$existingVersion = exec { & func --version }
169+
}
170+
171+
if (!$existingVersion -or $existingVersion -notlike "4.*") {
172+
Write-Build White "Installing/updating Azure Functions Core Tools..."
173+
if ($IsWindows) {
174+
exec { & npm install -g azure-functions-core-tools@ --unsafe-perm true }
175+
}
176+
else {
177+
Write-Build Yellow "NOTE: May require 'sudo' on Linux/MacOS"
178+
exec { & sudo npm install -g azure-functions-core-tools@ --unsafe-perm true }
179+
}
180+
}
181+
}
182+
183+
task PreTest Init, Install-AzureFunctionsSDK
184+
155185
# Synopsis: Build, Test and Package
156186
task . FullBuild
157187

@@ -164,7 +194,7 @@ task PreVersion {}
164194
task PostVersion {}
165195
task PreBuild {}
166196
task PostBuild {}
167-
task PreTest {}
197+
task PreTest Init, Install-AzureFunctionsSDK, {}
168198
task PostTest {}
169199
task PreTestReport {}
170200
task PostTestReport {}

0 commit comments

Comments
 (0)