From 605e523716ead7a1af9dccaba33cafd0dd4ab715 Mon Sep 17 00:00:00 2001 From: Jack Thorley Date: Fri, 25 Jun 2021 09:06:09 +0100 Subject: [PATCH 1/3] Refactor and adjust CircleCi build --- .circleci/config.yml | 91 +++++++++++++++++-- Dockerfile | 14 --- UD.Lambda.Templates.csproj | 31 +++++++ UD.Lambda.Templates.nuspec | 18 ---- UD.Lambda.Templates.sln | 15 ++- build/UD.Lambda.Templates.csproj | 24 ----- .../.template.config/template.json | 6 +- .../FunctionProject/FunctionProject.csproj | 22 ++--- .../FunctionProject.Tests.csproj | 14 +-- .../.template.config/template.json | 2 +- .../FunctionProject/FunctionProject.csproj | 26 +++--- .../FunctionProject.Tests.csproj | 13 +-- 12 files changed, 161 insertions(+), 115 deletions(-) delete mode 100644 Dockerfile create mode 100644 UD.Lambda.Templates.csproj delete mode 100644 UD.Lambda.Templates.nuspec delete mode 100644 build/UD.Lambda.Templates.csproj diff --git a/.circleci/config.yml b/.circleci/config.yml index 75489f1..9d83869 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,21 +1,92 @@ version: 2.1 + jobs: + pack-and-publish-nuget: + docker: + - image: mcr.microsoft.com/dotnet/sdk:3.1 + parameters: + template-path: + description: Path of the template Project that needs building + type: string + nuget-output-path: + description: Output location of Nuget NUPKG + type: string + default: nupk_output + pre-release: + description: Is Pre-release? + type: boolean + default: true + steps: + - run: + if [ -z "$CIRCLE_TAG" ] + then + echo "No Git tag present, will do nothing" + else + VERSION="${CIRCLE_TAG//v/}" + dotnet pack -c Release --no-build -p:PackageVersion=$VERSION<<#parameters.pre-release>>-beta<> -o $HOME/<> <> + for f in $HOME/<>/*.nupkg; do dotnet nuget push $f -s https://www.myget.org/F/unidays-release/api/v2/package -k $NUGET_APIKEY; done + fi + build-templates: docker: - - image: unidays/dotnet-core-sdk-nuget:2.2 + - image: mcr.microsoft.com/dotnet/sdk:3.1 + parameters: + template-path: + description: Path of Project/Solution that houses the templates + type: string + workspace_root: + type: string + default: . steps: - checkout - run: - name: Build and test templates - command: dotnet test -c Release + name: Create Environment + command: | + cd << parameters.workspace_root >> + dotnet tool install --tool-path . trx2junit - run: - name: Package templates - command: nuget pack ./UD.Lambda.Templates.nuspec + name: Build and test + working_directory: << parameters.workspace_root >> + command: | + dotnet test -c Release -l trx -r ./artifacts + dotnet publish UD.Lambda.Templates.csproj -c Release -o ./publish + - persist_to_workspace: + root: << parameters.workspace_root >> + paths: + - UD.Lambda.Templates.csproj + - publish - run: - name: Push package to MyGet - command: find . -iname "*.nupkg" -exec dotnet nuget push '{}' -s https://www.myget.org/F/unidays-release/api/v2/package -k $MYGET_API_KEY \; + name: Convert test results + working_directory: << parameters.workspace_root >> + command: ./trx2junit ./artifacts/*.trx + when: always + - store_test_results: + path: << parameters.workspace_root >>/artifacts/ + workflows: - version: 2 - build-publish: + version: 2.1 + build-templates-prerelease: + jobs: + - build-templates: + template-path: UD.Lambda.Templates.csproj + filters: + branches: + ignore: master + - pack-and-publish-nuget: + template-path: UD.Lambda.Templates.csproj + pre-release: true + requires: + - build-templates + + build-templates-release: jobs: - - build-templates + - build-templates: + template-path: UD.Lambda.Templates.csproj + filters: + branches: + only: master + - pack-and-publish-nuget: + template-path: UD.Lambda.Templates.csproj + pre-release: false + requires: + - build-templates diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 89540cb..0000000 --- a/Dockerfile +++ /dev/null @@ -1,14 +0,0 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.2 - -# Install Mono -RUN apt update && \ - apt install -y apt-transport-https dirmngr gnupg ca-certificates && \ - apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF && \ - echo "deb https://download.mono-project.com/repo/debian stable-stretch main" | tee /etc/apt/sources.list.d/mono-official-stable.list && \ - apt update && \ - apt install -y mono-devel && \ - rm -rf /var/lib/apt/lists/* - -# Install nuget executable -RUN curl -o /usr/local/bin/nuget.exe https://dist.nuget.org/win-x86-commandline/latest/nuget.exe && \ - echo '#!/bin/bash\nmono /usr/local/bin/nuget.exe "$@"' > /usr/local/bin/nuget && chmod u+x /usr/local/bin/nuget diff --git a/UD.Lambda.Templates.csproj b/UD.Lambda.Templates.csproj new file mode 100644 index 0000000..cd50dd8 --- /dev/null +++ b/UD.Lambda.Templates.csproj @@ -0,0 +1,31 @@ + + + + Template + 1.0 + UD.AWS.Lambda.Templates + UNiDAYS AWS Lambda Templates + UNiDAYS + UNiDAYS AWS Lambda Templates + dotnet-new;templates;contoso + + netstandard2.1 + + true + false + content + $(NoWarn);NU5128 + + + + + + + + + + + + + + diff --git a/UD.Lambda.Templates.nuspec b/UD.Lambda.Templates.nuspec deleted file mode 100644 index 047b85d..0000000 --- a/UD.Lambda.Templates.nuspec +++ /dev/null @@ -1,18 +0,0 @@ - - - - UD.Lambda.Templates - 1.0.0 - UD - false - MIT - https://github.com/MyUNiDAYS/LambdaTemplate - Templates for AWS Lambda - - - - - - - - diff --git a/UD.Lambda.Templates.sln b/UD.Lambda.Templates.sln index b158a20..b4ca746 100644 --- a/UD.Lambda.Templates.sln +++ b/UD.Lambda.Templates.sln @@ -3,8 +3,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.28307.421 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "build", "build", "{08E96C36-CDEE-45F3-BB50-8DE04E5A8C58}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "templates", "templates", "{F384A961-D8B7-4E95-A949-3E7302F90886}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "LambdaFunction", "LambdaFunction", "{DC74BE0A-8629-45CF-A7AA-476CF7C737F1}" @@ -20,8 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{B54E5C78-9 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionProject.Tests", "templates\LambdaFunction\test\FunctionProject.Tests\FunctionProject.Tests.csproj", "{21F2D09D-D998-4B4D-9380-1F7EC59A6BD4}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UD.Lambda.Templates", "build\UD.Lambda.Templates.csproj", "{6192DFD1-5A71-46F8-9D22-FA0CD342CBD7}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ApiFunction", "ApiFunction", "{711205CA-D423-4C35-9AA3-F980D0ED36CA}" ProjectSection(SolutionItems) = preProject templates\ApiFunction\.template.config\template.json = templates\ApiFunction\.template.config\template.json @@ -35,6 +31,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionProject", "template EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FunctionProject.Tests", "templates\ApiFunction\test\FunctionProject.Tests\FunctionProject.Tests.csproj", "{F2B2B0EA-348D-4166-982F-D98BEB2A5135}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UD.Lambda.Templates", "UD.Lambda.Templates.csproj", "{B649AF74-EFA7-4F3C-8C77-4366C887A33B}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -49,10 +47,6 @@ Global {21F2D09D-D998-4B4D-9380-1F7EC59A6BD4}.Debug|Any CPU.Build.0 = Debug|Any CPU {21F2D09D-D998-4B4D-9380-1F7EC59A6BD4}.Release|Any CPU.ActiveCfg = Release|Any CPU {21F2D09D-D998-4B4D-9380-1F7EC59A6BD4}.Release|Any CPU.Build.0 = Release|Any CPU - {6192DFD1-5A71-46F8-9D22-FA0CD342CBD7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {6192DFD1-5A71-46F8-9D22-FA0CD342CBD7}.Debug|Any CPU.Build.0 = Debug|Any CPU - {6192DFD1-5A71-46F8-9D22-FA0CD342CBD7}.Release|Any CPU.ActiveCfg = Release|Any CPU - {6192DFD1-5A71-46F8-9D22-FA0CD342CBD7}.Release|Any CPU.Build.0 = Release|Any CPU {301BDD24-C417-4648-88C9-D4FF410CC834}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {301BDD24-C417-4648-88C9-D4FF410CC834}.Debug|Any CPU.Build.0 = Debug|Any CPU {301BDD24-C417-4648-88C9-D4FF410CC834}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -61,6 +55,10 @@ Global {F2B2B0EA-348D-4166-982F-D98BEB2A5135}.Debug|Any CPU.Build.0 = Debug|Any CPU {F2B2B0EA-348D-4166-982F-D98BEB2A5135}.Release|Any CPU.ActiveCfg = Release|Any CPU {F2B2B0EA-348D-4166-982F-D98BEB2A5135}.Release|Any CPU.Build.0 = Release|Any CPU + {B649AF74-EFA7-4F3C-8C77-4366C887A33B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B649AF74-EFA7-4F3C-8C77-4366C887A33B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B649AF74-EFA7-4F3C-8C77-4366C887A33B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B649AF74-EFA7-4F3C-8C77-4366C887A33B}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -71,7 +69,6 @@ Global {D5680F23-8678-4D57-8F26-25F64FF63009} = {BB552E0C-24AE-48A3-8370-BC3718AF31B2} {B54E5C78-933E-4BD3-B619-67F34D358398} = {DC74BE0A-8629-45CF-A7AA-476CF7C737F1} {21F2D09D-D998-4B4D-9380-1F7EC59A6BD4} = {B54E5C78-933E-4BD3-B619-67F34D358398} - {6192DFD1-5A71-46F8-9D22-FA0CD342CBD7} = {08E96C36-CDEE-45F3-BB50-8DE04E5A8C58} {711205CA-D423-4C35-9AA3-F980D0ED36CA} = {F384A961-D8B7-4E95-A949-3E7302F90886} {779D8E98-30A3-419E-B2A5-EE93E0854C46} = {711205CA-D423-4C35-9AA3-F980D0ED36CA} {98E30D9E-FF89-4095-A25C-5CC3FFDD84AB} = {711205CA-D423-4C35-9AA3-F980D0ED36CA} diff --git a/build/UD.Lambda.Templates.csproj b/build/UD.Lambda.Templates.csproj deleted file mode 100644 index 715ce9b..0000000 --- a/build/UD.Lambda.Templates.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - Template - 1.0.0 - UD.Lambda.Templates - UD - Templates for AWS Lambda - https://github.com/MyUNiDAYS/LambdaTemplates - - content - true - false - true - netstandard2.0 - - - - - - - - - - diff --git a/templates/ApiFunction/.template.config/template.json b/templates/ApiFunction/.template.config/template.json index c8c6988..ff0e492 100644 --- a/templates/ApiFunction/.template.config/template.json +++ b/templates/ApiFunction/.template.config/template.json @@ -1,15 +1,15 @@ { "$schema": "http://json.schemastore.org/template", - "author": "UD", + "author": "UNiDAYS", "classifications": [ "AWS", "Lambda", "Function" ], - "name": "Api Function", + "name": "API Function", "identity": "UD.Lambda.Template.ApiFunction", "groupIdentity": "UD.Lambda.Template.ApiFunction.CSharp", - "shortName": "ud.ApiFunction", + "shortName": "UD.ApiFunction", "tags": { "language": "C#", "type": "project" diff --git a/templates/ApiFunction/src/FunctionProject/FunctionProject.csproj b/templates/ApiFunction/src/FunctionProject/FunctionProject.csproj index 84cfa4f..c7ed429 100644 --- a/templates/ApiFunction/src/FunctionProject/FunctionProject.csproj +++ b/templates/ApiFunction/src/FunctionProject/FunctionProject.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.1 linux-x64 true Lambda @@ -12,16 +12,16 @@ - - - - - - - - - - + + + + + + + + + + diff --git a/templates/ApiFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj b/templates/ApiFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj index 6b21539..ff0fdd0 100644 --- a/templates/ApiFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj +++ b/templates/ApiFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj @@ -1,18 +1,20 @@ - netcoreapp2.1 + netcoreapp3.1 + 8 + Library - - - - + + + + - + runtime; build; native; contentfiles; analyzers all diff --git a/templates/LambdaFunction/.template.config/template.json b/templates/LambdaFunction/.template.config/template.json index d622a9e..e8d6b85 100644 --- a/templates/LambdaFunction/.template.config/template.json +++ b/templates/LambdaFunction/.template.config/template.json @@ -9,7 +9,7 @@ "name": "Lambda Function", "identity": "UD.Lambda.Template.LambdaFunction", "groupIdentity": "UD.Lambda.Template.LambdaFunction.CSharp", - "shortName": "ud.LambdaFunction", + "shortName": "UD.LambdaFunction", "tags": { "language": "C#", "type": "project" diff --git a/templates/LambdaFunction/src/FunctionProject/FunctionProject.csproj b/templates/LambdaFunction/src/FunctionProject/FunctionProject.csproj index 51e6dfc..268a05f 100644 --- a/templates/LambdaFunction/src/FunctionProject/FunctionProject.csproj +++ b/templates/LambdaFunction/src/FunctionProject/FunctionProject.csproj @@ -1,7 +1,7 @@  - + - netcoreapp2.1 + netcoreapp3.1 linux-x64 true Lambda @@ -12,16 +12,16 @@ - - - - - - - - - - + + + + + + + + + + @@ -33,4 +33,4 @@ - \ No newline at end of file + diff --git a/templates/LambdaFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj b/templates/LambdaFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj index b19cae9..258fc60 100644 --- a/templates/LambdaFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj +++ b/templates/LambdaFunction/test/FunctionProject.Tests/FunctionProject.Tests.csproj @@ -1,18 +1,19 @@ - netcoreapp2.1 + netcoreapp3.1 + Library - - - - + + + + - + runtime; build; native; contentfiles; analyzers all From e54742cf7e5688b079448a0f214bd9c7bcc4a5c5 Mon Sep 17 00:00:00 2001 From: Jack Thorley Date: Fri, 25 Jun 2021 09:40:21 +0100 Subject: [PATCH 2/3] Add Pre-Release date to prevent package overwrite --- .circleci/config.yml | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 9d83869..bb64c8a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -22,9 +22,10 @@ jobs: then echo "No Git tag present, will do nothing" else + VERSION_SUFFIX_TIMESTAMP="$(date '+%Y%m%d%H%M%S')" VERSION="${CIRCLE_TAG//v/}" - dotnet pack -c Release --no-build -p:PackageVersion=$VERSION<<#parameters.pre-release>>-beta<> -o $HOME/<> <> - for f in $HOME/<>/*.nupkg; do dotnet nuget push $f -s https://www.myget.org/F/unidays-release/api/v2/package -k $NUGET_APIKEY; done + dotnet pack -c Release --no-build -p:PackageVersion=$VERSION<<#parameters.pre-release>>-beta.$VERSION_SUFFIX_TIMESTAMP<> -o ./<> <> + for f in ./<>/*.nupkg; do dotnet nuget push $f -s https://www.myget.org/F/unidays-release/api/v2/package -k $NUGET_APIKEY; done fi build-templates: @@ -49,12 +50,13 @@ jobs: working_directory: << parameters.workspace_root >> command: | dotnet test -c Release -l trx -r ./artifacts - dotnet publish UD.Lambda.Templates.csproj -c Release -o ./publish + dotnet build << parameters.template-path >> -c Release - persist_to_workspace: root: << parameters.workspace_root >> paths: - - UD.Lambda.Templates.csproj - - publish + - << parameters.template-path >> + - obj + - bin - run: name: Convert test results working_directory: << parameters.workspace_root >> From 7dc4e0ccfcddde12e26e77be697f01c6bb091f9a Mon Sep 17 00:00:00 2001 From: Jack Thorley Date: Fri, 25 Jun 2021 09:52:05 +0100 Subject: [PATCH 3/3] Reorganise Dotnet commands --- .circleci/config.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index bb64c8a..8816de6 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -48,9 +48,9 @@ jobs: - run: name: Build and test working_directory: << parameters.workspace_root >> - command: | - dotnet test -c Release -l trx -r ./artifacts + command: | dotnet build << parameters.template-path >> -c Release + dotnet test -c Release -l trx -r ./artifacts - persist_to_workspace: root: << parameters.workspace_root >> paths: