diff --git a/.vscode/settings.json b/.vscode/settings.json index b8e470a..dacccab 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -16,6 +16,7 @@ "cSpell.enabled": true, "cSpell.words": [ "Allman", + "amazonlinux", "APACHELICENSE", "Aperta", "appveyor", diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 89e8fdd..93bf148 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,32 +5,34 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [2.9.0] +## [2.10.0] - Catesta template module changes - CI/CD Changes: - - AWS: + - GitHub Actions with CodeBuild (***new***): + - Added support for new CI/CD option which leverages GitHub Actions that run on AWS CodeBuild. This option generates both GitHub Action workflows as well as CFN templates for deployment to AWS for creating CodeBuild projects that integrate with the actions of your GitHub project. + - AWS CodeBuild: - GitLab added as a supported source for CodeBuild projects - Each CodeBuild project now has its own `AWS::Logs::LogGroup` created with a configurable retention policy. - Minor changes to formatting in CFNs to satisfy new `cfn-lint` requirements. - Windows CodeBuild project containers upgraded to latest image: - `aws/codebuild/windows-base:2019-2.0` to `aws/codebuild/windows-base:2019-3.0` - - Linux CodeBuild project containers upgraded to latest images: - - Previously hard set to: `aws/codebuild/standard:7.0` - - Linux CodeBuild project image now parameterized and supports either: - - `aws/codebuild/standard:7.0` (default) - - `aws/codebuild/amazonlinux2-x86_64-standard:5.0` + - Linux CodeBuild project image now parameterized (Previously hard set to: `aws/codebuild/standard:7.0`) and supports either: + - `aws/codebuild/standard:7.0` (default) + - `aws/codebuild/amazonlinux2-x86_64-standard:5.0` - Updated CodeCommit based builds Lambda triggers from `python3.9` to `python3.12` runtime. - Buildspec updates: - `buildspec_pwsh_linux.yml` updated to dot net 8. - `buildspec_pwsh_windows.yml` updated to dot net 8. - AWS.Tools.Common bumped from `4.1.133` to `4.1.572` - - GitHub: + - GitHub Actions: - Workflow actions now include the module name in the action name - InvokeBuild bumped from `5.10.5` to `5.11.1` - PSScriptAnalyzer bumped from `1.21.0` to `1.22.0` - Catesta primary module changes - - Added additional tests for new AWS changes + - Added additional tests for: + - new AWS changes + - new GitHub Actions with Codebuild capabilities - InvokeBuild bumped from `5.10.5` to `5.11.1` - PSScriptAnalyzer bumped from `1.21.0` to `1.22.0` - Documentation updates diff --git a/docs/Catesta-Basics.md b/docs/Catesta-Basics.md index ff8474d..c7efb84 100644 --- a/docs/Catesta-Basics.md +++ b/docs/Catesta-Basics.md @@ -37,6 +37,7 @@ New-VaultProject -DestinationPath $outPutPath * [M] Module Only * [G] GitHub Actions * [C] AWS CodeBuild + * [S] GitHub Actions on AWS CodeBuild * [P] Appveyor * [L] GitLab CI/CD * [B] BitBucket Pipelines @@ -70,6 +71,7 @@ The options listed in the prompt represent the different CI/CD tools that Catest [M] Module Only [G] GitHub Actions [C] AWS CodeBuild +[S] GitHub Actions on AWS CodeBuild [P] Appveyor [L] GitLab CI/CD [B] BitBucket Pipelines @@ -84,11 +86,13 @@ It's important to note that the choice you make here will impact the setup and c If you need help with the options or are unsure which to choose, you can review additional Catesta documentation that covers the process of each CI/CD integration in depth: -* [Catesta - AWS Doc](catesta_cicd/Catesta-AWS.md) * [Catesta - GitHub Actions Doc](catesta_cicd/Catesta-GHActions.md) -* [Catesta - Azure Pipelines Doc](catesta_cicd/Catesta-Azure.md) -* [Catesta - Bitbucket Doc](catesta_cicd/Catesta-Bitbucket.md) +* [Catesta - AWS CodeBuild Doc](catesta_cicd/Catesta-AWS.md) +* [Catesta - GitHub Actions on AWS CodeBuild Doc](catesta_cicd/Catesta-GHActionsAWSCodeBuild.md) +* [Catesta - AppVeyor Doc](catesta_cicd/Catesta-AppVeyor.md) * [Catesta - GitLab Doc](catesta_cicd/Catesta-GitLab.md) +* [Catesta - Bitbucket Doc](catesta_cicd/Catesta-Bitbucket.md) +* [Catesta - Azure Pipelines Doc](catesta_cicd/Catesta-Azure.md) #### Understanding Build Configuration Selection diff --git a/docs/Catesta-ModuleSchema.md b/docs/Catesta-ModuleSchema.md index 7f67cd1..ec011c2 100644 --- a/docs/Catesta-ModuleSchema.md +++ b/docs/Catesta-ModuleSchema.md @@ -40,6 +40,8 @@ choices: help : CI/CD using GitHub Actions. value : CODEBUILD help : CI/CD using AWS CodeBuild + value : GHACODEBUILD + help : CI/CD using GitHub Actions running on AWS CodeBuild. value : APPVEYOR help : CI/CD using AWS Appveyor value : GITLAB @@ -56,7 +58,7 @@ choices: value : windows help : Adds a Windows PowerShell based Workflow action. value : pwshcore - help : Adds a Windows pwsh based pipeline job. + help : Adds a Windows pwsh based Workflow action. value : linux help : Adds a Linux based Workflow action. value : macos @@ -77,6 +79,17 @@ name : S3Bucket type : text default : PSGallery +name : GitHubACBOptions +type : multichoice +condition : $PLASTER_PARAM_CICD -eq 'GHACODEBUILD' +choices: + value : ps + help : Adds a Windows PowerShell based Workflow action powered by CodeBuild + value : pwshcore + help : Adds a Windows pwsh based Workflow action powered by CodeBuild. + value : pwsh + help : Adds a Linux based Workflow action powered by CodeBuild. + name : AppveyorOptions type : multichoice condition : $PLASTER_PARAM_CICD -eq 'APPVEYOR' @@ -236,28 +249,29 @@ The example below showcases all the available options for the `New-ModuleProject ```powershell $moduleParameters = @{ -VAULT = 'text' -ModuleName = 'text' -Description = 'text' -Version = '0.0.1' -FN = 'user full name' -CICD = 'GITHUB' -GitHubAOptions = 'windows','pwshcore','linux','macos' -AWSOptions = 'ps','pwshcore','pwsh' -AppveyorOptions = 'windows','pwshcore','linux','macos' -GitLabOptions = 'windows','pwshcore','linux' -AzureOptions = 'windows','pwshcore','linux','macos' -RepoType = 'GITHUB' -License = 'MIT' -Changelog = 'CHANGELOG' -COC = 'CONDUCT' -Contribute = 'CONTRIBUTING' -Security = 'SECURITY' -ReadtheDocs = 'READTHEDOCS' -RTDTheme = 'READTHEDOCSTHEME' -CodingStyle = 'Stroustrup' -Help = 'Yes' -Pester = '5' +VAULT = 'text' +ModuleName = 'text' +Description = 'text' +Version = '0.0.1' +FN = 'user full name' +CICD = 'GITHUB' +GitHubAOptions = 'windows','pwshcore','linux','macos' +AWSOptions = 'ps','pwshcore','pwsh' +GitHubACBOptions = 'ps','pwshcore','pwsh' +AppveyorOptions = 'windows','pwshcore','linux','macos' +GitLabOptions = 'windows','pwshcore','linux' +AzureOptions = 'windows','pwshcore','linux','macos' +RepoType = 'GITHUB' +License = 'MIT' +Changelog = 'CHANGELOG' +COC = 'CONDUCT' +Contribute = 'CONTRIBUTING' +Security = 'SECURITY' +ReadtheDocs = 'READTHEDOCS' +RTDTheme = 'READTHEDOCSTHEME' +CodingStyle = 'Stroustrup' +Help = 'Yes' +Pester = '5' } diff --git a/docs/Catesta.md b/docs/Catesta.md index f10bd6a..28e085c 100644 --- a/docs/Catesta.md +++ b/docs/Catesta.md @@ -2,7 +2,7 @@ Module Name: Catesta Module Guid: 6796b193-9013-468a-b022-837749af2d06 Download Help Link: NA -Help Version: 2.9.0 +Help Version: 2.10.0 Locale: en-US --- diff --git a/docs/assets/GHActionsCodeBuild/AWSCodeBuild_GitHub_Actions_Projects.png b/docs/assets/GHActionsCodeBuild/AWSCodeBuild_GitHub_Actions_Projects.png new file mode 100644 index 0000000..8fbcdaa Binary files /dev/null and b/docs/assets/GHActionsCodeBuild/AWSCodeBuild_GitHub_Actions_Projects.png differ diff --git a/docs/assets/GHActionsCodeBuild/PowerShell_GitHub_Actions_CodeBuild_CFN_Example.png b/docs/assets/GHActionsCodeBuild/PowerShell_GitHub_Actions_CodeBuild_CFN_Example.png new file mode 100644 index 0000000..fb89953 Binary files /dev/null and b/docs/assets/GHActionsCodeBuild/PowerShell_GitHub_Actions_CodeBuild_CFN_Example.png differ diff --git a/docs/assets/GHActionsCodeBuild/catesta_github_actions_aws_codebuild_diagram.png b/docs/assets/GHActionsCodeBuild/catesta_github_actions_aws_codebuild_diagram.png new file mode 100644 index 0000000..86e4bdd Binary files /dev/null and b/docs/assets/GHActionsCodeBuild/catesta_github_actions_aws_codebuild_diagram.png differ diff --git a/docs/assets/diagrams/catesta_github_actions_aws_codebuild.drawio b/docs/assets/diagrams/catesta_github_actions_aws_codebuild.drawio new file mode 100644 index 0000000..e0f7958 --- /dev/null +++ b/docs/assets/diagrams/catesta_github_actions_aws_codebuild.drawio @@ -0,0 +1,218 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/catesta_cicd/Catesta-AWS.md b/docs/catesta_cicd/Catesta-AWS.md index a42ee94..d80ce7b 100644 --- a/docs/catesta_cicd/Catesta-AWS.md +++ b/docs/catesta_cicd/Catesta-AWS.md @@ -20,7 +20,7 @@ CodeBuild Supported Builds: 1. Create your project using Catesta and select `[C] AWS CodeBuild` at the CICD prompt. *([Catesta Basics](../Catesta-Basics.md))* * *Note: You will see the following prompt unique to the AWS CodeBuild selection:* * **Enter S3 bucket name to download needed PS modules from S3 location. Leave blank to DL modules from PSGallery.** Your CodeBuild instance will need various modules to successfully build your PowerShell module project. By default, it does not contain them. Leaving this blank will default to having the CodeBuild instance download and install the needed modules from the PSGallery during each build. You can improve build times and performance by instead loading the required modules into an S3 bucket. If you choose to do so, you can specify the S3 bucket here. Don't forget to give your CodeBuild project permission to that S3 bucket. -1. Create your CodeBuild project in your AWS account. While you can do this manually, using the CloudFormation (CFN) template generated by Catesta is recommended. +1. Create your CodeBuild project(s) in your AWS account. While you can do this manually, using the CloudFormation (CFN) template generated by Catesta is recommended. * **GitHub** * Upload the CFN template to AWS CloudFormation to deploy the required resources automatically. The template adapts to include support for any build types you've chosen during the Catesta setup, such as Windows, Linux, or macOS. * CodeBuild projects currently use OATH to authenticate with GitHub. **You need to configure OATH for CodeBuild *before* you deploy the CFN template**. *Reference [Adding CodeBuild OATH to your Project Repository](#adding-codebuild-oath-to-your-project-repository) below for configuring this.* diff --git a/docs/catesta_cicd/Catesta-GHActionsAWSCodeBuild.md b/docs/catesta_cicd/Catesta-GHActionsAWSCodeBuild.md new file mode 100644 index 0000000..722b6e5 --- /dev/null +++ b/docs/catesta_cicd/Catesta-GHActionsAWSCodeBuild.md @@ -0,0 +1,89 @@ +# Catesta - GitHub Actions with AWS CodeBuild Integration + +## Synopsis + +Scaffolds a new PowerShell module or vault project intended for CI/CD workflow using [GitHub Actions](https://help.github.com/actions) running on [AWS CodeBuild](https://aws.amazon.com/about-aws/whats-new/2023/07/aws-codebuild-github-actions/). + +## Getting Started + +------------------- + +*Note: It is important to have a clear understanding of what your project should support before starting with Catesta. If your goal is to create a cross-platform solution or test multiple versions of PowerShell, consider running multiple build types to ensure proper functioning on various platforms and environments.* + +GitHub Actions Supported Builds: + +![Cross Platform](https://img.shields.io/badge/Builds-Windows%20PowerShell%20%7C%20Windows%20pwsh%20%7C%20Linux-lightgrey) + +------------------- + +1. You will [need an AWS Account](https://aws.amazon.com/premiumsupport/knowledge-center/create-and-activate-aws-account/). +1. You will [need a GitHub account](https://github.com/join). +1. Create a new repository and clone to your local dev device +1. Create your project using Catesta and select `[S] GitHub Actions on AWS CodeBuild` at the CICD prompt. *([Catesta Basics](../Catesta-Basics.md))* +1. Create your CodeBuild project(s) in your AWS account using the CloudFormation (CFN) template generated by Catesta. (*This is highly recommended as the naming convention of the projects must match your Action workflows exactly. Using the templates ensures this.*) + * Upload the CFN template to AWS CloudFormation to deploy the required resources automatically. The template adapts to include support for any build types you've chosen during the Catesta setup, such as Windows, Linux, or macOS. + * CodeBuild projects currently use OATH to authenticate with GitHub. **You need to configure OATH for CodeBuild *before* you deploy the CFN template**. *Reference [Adding CodeBuild OATH to your Project Repository](#adding-codebuild-oath-to-your-project-repository) below for configuring this.* +1. Write the logic for your module (the hardest part) + * All build testing can be done locally by navigating to `src` and running `Invoke-Build` + * By default, this runs all tasks in the build file. + * If you want to run a specific task from the build file you can provide the task name. For example, to just execute Pester tests for your project: `Invoke-Build -Task Test` + * If using VSCode as your primary editor you can use VSCode tasks to perform various local actions + * Open the VSCode Command palette + * Shift+Command+P (Mac) / Ctrl+Shift+P (Windows/Linux) or F1 + * Type `Tasks: Run Task` + * Select the task to run + * Examples: + * `task .` - Runs complete build (all tasks) + * `task Test` - Invokes all Pester Unit Tests + * `task Analyze` - Invokes Script Analyzer checks + * `task DevCC` - Generates generate xml file to graphically display code coverage in VSCode using [Coverage Gutters](https://marketplace.visualstudio.com/items?itemName=ryanluker.vscode-coverage-gutters) +1. Add any module dependencies to your CI/CD bootstrap file: `actions_bootstrap.ps1` +1. Upload to your GitHub repository which now has a triggered/monitored build action that runs in CodeBuild in your AWS account. +1. Evaluate results of your build and display your GitHub Actions badge proudly! + +### Test Reports + +GitHub Actions does not natively support Test reports. There are many Test Report solutions in the [Actions Marketplace](https://github.com/marketplace?type=actions) that can accomplish this however. + +By default, the build file will create a XML test report in `NUnitXml` but these can also be changed to `JUnitXml` if you are using a Test Report in Actions that prefers that format. + +## Notes + +Additional Reading: + +* [Set up self-hosted GitHub Actions runners in AWS CodeBuild](https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html) +* [Automating your workflow with GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions) +* [Using a specific shell](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#using-a-specific-shell) +* [Workflow syntax for GitHub Actions](https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions) + +### Deploying the CFN (CloudFormation) Template + +#### Adding CodeBuild OATH to your Project Repository + +AWS documentation for [ProjectSource](https://docs.aws.amazon.com/codebuild/latest/APIReference/API_ProjectSource.html) states that OAUTH should be set for GitHub. + +In order to accomplish [source provider access](https://docs.aws.amazon.com/codebuild/latest/userguide/access-tokens.html#access-tokens-github) to your project's repo using OATH, you will first need to configure CodeBuild in the AWS Console. + +This needs to be done **prior to deploying your CFN template**. + +Essentially, you just need to login to your AWS console, create a new CodeBuild project, and under source, add a source to your supported repository location. You will be prompted to enter your credentials to establish a link. Once complete, CodeBuild will be aware of this OATH link. You do not actually need to create the project in the console. Once you've created the OATH link, you can click Cancel on the new CodeBuild project creation page. + +The graphic below shows a Bitbucket example, but the same applies for GitHub, just select GitHub as your source provider. + +![Catesta AWS CodeBuild OATH Link Create](../assets/AWS/AWSCodeBuild_OAuth.png) + +#### Manual CFN upload example + +The following shows the GitHub CFN example: + +![Catesta PowerShell AWS CodeBuild CFN Example](../assets/GHActionsCodeBuild/PowerShell_GitHub_Actions_CodeBuild_CFN_Example.png) + +#### Final CFN Deployment Results example + +![AWS CodeBuild projects created by Catesta](../assets/GHActionsCodeBuild/AWSCodeBuild_GitHub_Actions_Projects.png) + +## Diagrams + +### GitHub Actions with AWS CodeBuild Integration + +![Catesta PowerShell GitHub Actions using AWS CodeBuild Diagram](../assets/GHActionsCodeBuild/catesta_github_actions_aws_codebuild_diagram.png) diff --git a/docs/catesta_cicd/Catesta-GitLab.md b/docs/catesta_cicd/Catesta-GitLab.md index db1cf81..029e1d5 100644 --- a/docs/catesta_cicd/Catesta-GitLab.md +++ b/docs/catesta_cicd/Catesta-GitLab.md @@ -2,7 +2,7 @@ ## Synopsis -Scaffolds a new PowerShell module or vault project intended for CI/CD workflow using [GitLab](https://gitlab.com/). +Scaffolds a new PowerShell module or vault project intended for CI/CD workflow using [GitLab](https://docs.gitlab.com/ee/ci/) . ## Getting Started diff --git a/docs/index.md b/docs/index.md index 38faa9b..8b12ffd 100644 --- a/docs/index.md +++ b/docs/index.md @@ -66,11 +66,13 @@ Catesta can build two types of projects: Selections * *[Selection]* CI/CD build integration: - * [AWS](https://aws.amazon.com/codebuild/) - * [GitHub Actions](https://help.github.com/actions) - * [Azure Pipelines](https://azure.microsoft.com/services/devops/) - * [AppVeyor](https://www.appveyor.com/) - * [Bitbucket Pipelines](https://bitbucket.org/) + * [GitHub Actions](catesta_cicd/Catesta-GHActions.md) + * [AWS CodeBuild](catesta_cicd/Catesta-AWS.md) + * [GitHub Actions on AWS CodeBuild](catesta_cicd/Catesta-GHActionsAWSCodeBuild.md) + * [AppVeyor](catesta_cicd/Catesta-AppVeyor.md) + * [GitLab CI/CD](catesta_cicd/Catesta-GitLab.md) + * [Bitbucket Pipelines](catesta_cicd/Catesta-Bitbucket.md) + * [Azure Pipelines](catesta_cicd/Catesta-Azure.md) * *[Selection]* Build types for easy cross-platform testing * Windows PowerShell * Windows pwsh diff --git a/mkdocs.yml b/mkdocs.yml index 605f682..a88cba9 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -97,12 +97,13 @@ nav: - New-ModuleProject: New-ModuleProject.md - New-VaultProject: New-VaultProject.md - Detailed Integrations: - - AppVeyor: catesta_cicd/Catesta-AppVeyor.md - - CodeBuild: catesta_cicd/Catesta-AWS.md - - Azure Pipelines: catesta_cicd/Catesta-Azure.md - GitHub Actions: catesta_cicd/Catesta-GHActions.md - - Bitbucket Pipelines: catesta_cicd/Catesta-Bitbucket.md + - AWS CodeBuild: catesta_cicd/Catesta-AWS.md + - GitHub Actions on AWS CodeBuild: Catesta-GHActionsAWSCodeBuild.md + - AppVeyor: catesta_cicd/Catesta-AppVeyor.md - GitLab CICD Pipelines: catesta_cicd/Catesta-GitLab.md + - Bitbucket Pipelines: catesta_cicd/Catesta-Bitbucket.md + - Azure Pipelines: catesta_cicd/Catesta-Azure.md - Vault Project: Catesta-Vault-Extension.md - FAQ: Catesta-FAQ.md - Change Log: CHANGELOG.md diff --git a/src/Catesta/Catesta.psd1 b/src/Catesta/Catesta.psd1 index 7665d77..a31b973 100644 --- a/src/Catesta/Catesta.psd1 +++ b/src/Catesta/Catesta.psd1 @@ -12,7 +12,7 @@ RootModule = 'Catesta.psm1' # Version number of this module. - ModuleVersion = '2.9.0' + ModuleVersion = '2.10.0' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/src/Catesta/Resources/GitHubActionsCodeBuild/CloudFormation/PowerShellGitHubActionsCodeBuild.yml b/src/Catesta/Resources/GitHubActionsCodeBuild/CloudFormation/PowerShellGitHubActionsCodeBuild.yml new file mode 100644 index 0000000..5759701 --- /dev/null +++ b/src/Catesta/Resources/GitHubActionsCodeBuild/CloudFormation/PowerShellGitHubActionsCodeBuild.yml @@ -0,0 +1,584 @@ +--- +AWSTemplateFormatVersion: "2010-09-09" +Description: 'PS CodeBuild for GitHub Actions Stack: <%=$PLASTER_PARAM_ModuleName%>' + +Parameters: + + ProjectName: + Description: name of PS Module. Used as project tag value for all resources. + Type: String + Default: <%=$PLASTER_PARAM_ModuleName%> + + ProjectDescription: + Description: short description of your PS module project. + Type: String + + RepositoryUrl: + Description: "HTTPS Clone URL of the repository in GitHub. Example: 'https://github.com/owner/repo.git'" + Type: String + + CodeBuildTimeoutInMinutes: + Type: Number + Default: 30 + Description: The number of minutes before a CodeBuild build will timeout. + +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html + LinuxCodeBuildImage: + Type: String + Default : aws/codebuild/standard:7.0 + Description: CodeBuild image to use for the build. + AllowedValues: + - aws/codebuild/standard:7.0 + - aws/codebuild/amazonlinux2-x86_64-standard:5.0 +'@ +} +%> + + LogRetentionInDays: + Type: Number + Default: 30 + Description: The number of days to retain the CodeBuild logs. + + # https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html + #CodeBuildEnvironment: + # Type: String + # Default: WINDOWS_CONTAINER + # Description: The type of build environment. + # AllowedValues: + # - WINDOWS_SERVER_2019_CONTAINER + # - LINUX_CONTAINER + + # https://docs.aws.amazon.com/codebuild/latest/userguide/create-project-cli.html + #CodeBuildComputeType: + # Type: String + # Default: BUILD_GENERAL1_MEDIUM + # Description: The size of the CodeBuild instance. (Windows Containers do NOT support small) + # AllowedValues: + # - BUILD_GENERAL1_SMALL + # - BUILD_GENERAL1_MEDIUM + # - BUILD_GENERAL1_LARGE + # - BUILD_GENERAL1_2XLARGE + + # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html + #CodeBuildImage: + # Type: String + # Default : ws/codebuild/windows-base:2019-2.0 + # Description: CodeBuild image to use for the build. + # AllowedValues: + # - aws/codebuild/windows-base:2019-3.0 + # - aws/codebuild/amazonlinux2-x86_64-standard:5.0 + # - aws/codebuild/standard:7.0 + + # BuildSpecFile: + # Type: String + # Default: buildspec_powershell_windows.yml + # Description: The build file to be run by CodeBuild. + # AllowedValues: + # - buildspec_powershell_windows.yml + # - buildspec_pwsh_windows.yml + # - buildspec_pwsh_linux.yml + + DeployEmailNotifications: + Type: String + Default: 'no' + Description: "CodeBuild will send email notifications of state changes." + AllowedValues: + - 'yes' + - 'no' + + EmailForNotifications: + Type: String + Default: ignored@doesnotexist.com + Description: Email Address for SNS Notifications + AllowedPattern: "^[\\x20-\\x45]?[\\w-\\+]+(\\.[\\w]+)*@[\\w-]+(\\.[\\w]+)*(\\.[a-z]{2,})$" + +Metadata: + AWS::CloudFormation::Interface: + ParameterGroups: + - Label: + default: Project and Tagging + Parameters: + - ProjectName + - ProjectDescription + - Label: + default: Specify Repository information + Parameters: + - RepositoryUrl + - Label: + default: CodeBuild + Parameters: + - CodeBuildTimeoutInMinutes +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + - LinuxCodeBuildImage +'@ +} +%> + - LogRetentionInDays + #- CodeBuildEnvironment + #- CodeBuildComputeType + # - BuildSpecFile + - Label: + default: Email Notifications + Parameters: + - DeployEmailNotifications + - EmailForNotifications + ParameterLabels: + ProjectName: + default: Module Name + ProjectDescription: + default: Module Description + RepositoryUrl: + default: Repository URL + CodeBuildTimeoutInMinutes: + default: Timeout in Minutes +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + LinuxCodeBuildImage: + default: Linux CodeBuild Image +'@ +} +%> + LogRetentionInDays: + default: Log Retention in Days + #CodeBuildEnvironment: + # default: Container Type + #CodeBuildComputeType: + # default: Container Size + # BuildSpecFile: + # default: Buildspec file + DeployEmailNotifications: + default: Deploy Email Notifications + EmailForNotifications: + default: Email Address + +#Mappings: + +Conditions: + + DeployEmailNotificationsCondition: + !Equals [!Ref DeployEmailNotifications, 'yes'] + # PSWindows: !Equals [!Ref BuildSpecFile, 'buildspec_powershell_windows.yml'] + # PWSHWindows: !Equals [!Ref BuildSpecFile, 'buildspec_pwsh_windows.yml'] + # WindowsImage: + # Fn::Or: + # - Condition: PSWindows + # - Condition: PWSHWindows + #LinuxImage: !Equals [!Ref BuildSpecFile, 'buildspec_pwsh_linux.yml'] + #WindowsImage: !Equals [!Ref CodeBuildEnvironment, 'WINDOWS_CONTAINER'] + +Resources: + + # The IAM Role CodeBuild will run the container as + # # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-iam-role.html + CodeBuildServiceRole: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Principal: + Service: codebuild.amazonaws.com + Action: + - sts:AssumeRole + Path: / + Policies: + - PolicyName: CBCloudWatchPublishing + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Action: + - logs:CreateLogGroup + - logs:CreateLogStream + - logs:PutLogEvents + Resource: +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'ps') { +@' + - Fn::GetAtt: + - CodeBuildpsProjectLogGroup + - Arn +'@ + } +%> + +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwshcore') { +@' + - Fn::GetAtt: + - CodeBuildpwshcoreProjectLogGroup + - Arn +'@ + } +%> + +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + - Fn::GetAtt: + - CodeBuildpwshProjectLogGroup + - Arn +'@ + } +%> + + - PolicyName: CBS3ArtifactAccess + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Action: + - s3:PutObject + - s3:GetObject + - s3:GetObjectVersion + Resource: + - !Sub arn:${AWS::Partition}:s3:::codepipeline-${AWS::Region}-* + - PolicyName: CBReportAccess + PolicyDocument: + Version: '2012-10-17' + Statement: + - Effect: Allow + Action: + - codebuild:CreateReport + - codebuild:CreateReportGroup + - codebuild:UpdateReportGroup + - codebuild:UpdateReport + - codebuild:DeleteReportGroup + - codebuild:DeleteReport + - codebuild:BatchPutCodeCoverages + - codebuild:BatchPutTestCases + Resource: + - !Sub "arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:report-group/<%=$PLASTER_PARAM_ModuleName%>*" + +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'ps') { +@' + + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html + CodeBuildpsProjectLogGroup: + Type: AWS::Logs::LogGroup + DeletionPolicy: Delete + UpdateReplacePolicy: Retain + Properties: + LogGroupName: !Sub ${ProjectName}-windows-powershell + RetentionInDays: !Ref LogRetentionInDays + Tags: + - Key: Service + Value: !Ref ProjectName + + # The CodeBuild Project configuration + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-webhookfilter.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environment.html + # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-source.html + CodeBuildpsProject: + Type: AWS::CodeBuild::Project + Properties: + Artifacts: + Type: NO_ARTIFACTS + # BadgeEnabled: !Ref CodeBuildBadgeEnabled + Description: !Ref ProjectDescription + Environment: + #ComputeType: !Ref CodeBuildComputeType + ComputeType: BUILD_GENERAL1_MEDIUM + Image: aws/codebuild/windows-base:2019-3.0 + # Type: !Ref CodeBuildEnvironment + Type: WINDOWS_SERVER_2019_CONTAINER + LogsConfig: + CloudWatchLogs: + GroupName: + Ref: CodeBuildpsProjectLogGroup + Status: ENABLED + Name: !Join + - '-' + - - !Ref ProjectName + - powershell_gha_cb_windows + ServiceRole: !GetAtt CodeBuildServiceRole.Arn + Source: + # SourceAuth is for use by the CodeBuild console only. Do not get or set it directly. + Type: GITHUB + Auth: + Type: OAUTH + Location: !Ref RepositoryUrl + BuildSpec: buildspec_powershell_windows.yml + Tags: + - Key: Service + Value: !Ref ProjectName + TimeoutInMinutes: !Ref CodeBuildTimeoutInMinutes + Triggers: + Webhook: true + FilterGroups: + - - Type: EVENT + Pattern: WORKFLOW_JOB_QUEUED +'@ + } +%> +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwshcore') { +@' + + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html + CodeBuildpwshcoreProjectLogGroup: + Type: AWS::Logs::LogGroup + DeletionPolicy: Delete + UpdateReplacePolicy: Retain + Properties: + LogGroupName: + Fn::Sub: ${ProjectName}-windows-pwsh + RetentionInDays: !Ref LogRetentionInDays + Tags: + - Key: Service + Value: !Ref ProjectName + + # The CodeBuild Project configuration + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-webhookfilter.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environment.html + # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-source.html + CodeBuildpwshcoreProject: + Type: AWS::CodeBuild::Project + Properties: + Artifacts: + Type: NO_ARTIFACTS + # BadgeEnabled: !Ref CodeBuildBadgeEnabled + Description: !Ref ProjectDescription + Environment: + #ComputeType: !Ref CodeBuildComputeType + ComputeType: BUILD_GENERAL1_MEDIUM + Image: aws/codebuild/windows-base:2019-3.0 + Type: WINDOWS_SERVER_2019_CONTAINER + # Type: !Ref CodeBuildEnvironment + LogsConfig: + CloudWatchLogs: + GroupName: + Ref: CodeBuildpwshcoreProjectLogGroup + Status: ENABLED + Name: !Join + - '-' + - - !Ref ProjectName + - pwsh_gha_cb_windows + ServiceRole: !GetAtt CodeBuildServiceRole.Arn + Source: + # SourceAuth is for use by the CodeBuild console only. Do not get or set it directly. + Type: GITHUB + Auth: + Type: OAUTH + Location: !Ref RepositoryUrl + BuildSpec: buildspec_pwsh_windows.yml + Tags: + - Key: Service + Value: !Ref ProjectName + TimeoutInMinutes: !Ref CodeBuildTimeoutInMinutes + Triggers: + Webhook: true + FilterGroups: + - - Type: EVENT + Pattern: WORKFLOW_JOB_QUEUED +'@ + } +%> +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-logs-loggroup.html + CodeBuildpwshProjectLogGroup: + Type: AWS::Logs::LogGroup + DeletionPolicy: Delete + UpdateReplacePolicy: Retain + Properties: + LogGroupName: + Fn::Sub: ${ProjectName}-linux-pwsh + RetentionInDays: !Ref LogRetentionInDays + Tags: + - Key: Service + Value: !Ref ProjectName + + # The CodeBuild Project configuration + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-codebuild-project.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-webhookfilter.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-environment.html + # https://docs.aws.amazon.com/codebuild/latest/userguide/build-env-ref-available.html + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codebuild-project-source.html + CodeBuildpwshProject: + Type: AWS::CodeBuild::Project + Properties: + Artifacts: + Type: NO_ARTIFACTS + # BadgeEnabled: !Ref CodeBuildBadgeEnabled + Description: !Ref ProjectDescription + Environment: + #ComputeType: !Ref CodeBuildComputeType + ComputeType: BUILD_GENERAL1_SMALL + Image: !Ref LinuxCodeBuildImage + #Type: !Ref CodeBuildEnvironment + Type: LINUX_CONTAINER + LogsConfig: + CloudWatchLogs: + GroupName: + Ref: CodeBuildpwshProjectLogGroup + Status: ENABLED + Name: !Join + - '-' + - - !Ref ProjectName + - pwsh_gha_cb_linux + ServiceRole: !GetAtt CodeBuildServiceRole.Arn + Source: + # SourceAuth is for use by the CodeBuild console only. Do not get or set it directly. + Type: GITHUB + Auth: + Type: OAUTH + Location: !Ref RepositoryUrl + BuildSpec: buildspec_pwsh_linux.yml + Tags: + - Key: Service + Value: !Ref ProjectName + TimeoutInMinutes: !Ref CodeBuildTimeoutInMinutes + Triggers: + Webhook: true + FilterGroups: + - - Type: EVENT + Pattern: WORKFLOW_JOB_QUEUED +'@ + } +%> + + # An SNS Topic used for CodeBuild status updates + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-topic.html + SNSTopicForCodeBuildUpdates: + Type: AWS::SNS::Topic + Properties: + Tags: + - Key: Service + Value: !Ref ProjectName + + # The SNS Topic Policy + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-sns-policy.html + SNSTopicPolicy: + Type: AWS::SNS::TopicPolicy + Properties: + PolicyDocument: + Id: SNSTopicPolicy + Version: '2012-10-17' + Statement: + - Sid: AllowEvents + Effect: Allow + Principal: + Service: + - events.amazonaws.com + Action: sns:Publish + Resource: !Ref SNSTopicForCodeBuildUpdates + Topics: + - !Ref SNSTopicForCodeBuildUpdates + + # The SNS Email Subscription + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-sns-subscription.html + SNSEmailSubscription: + Type: AWS::SNS::Subscription + Condition: DeployEmailNotificationsCondition + Properties: + Endpoint: !Ref EmailForNotifications + Protocol: email + TopicArn: !Ref SNSTopicForCodeBuildUpdates + + # The CodeBuild event for status updates + # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-events-rule.html + CodeBuildEventsRule: + Type: AWS::Events::Rule + Properties: + Description: Trigger notifications based on CodeBuild state changes + EventPattern: + source: + - aws.codebuild + detail-type: + - CodeBuild Build State Change + detail: + build-status: + - IN_PROGRESS + - SUCCEEDED + - FAILED + - STOPPED + project-name: +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'ps') { +@' + - !Ref CodeBuildpsProject +'@ + } +%> +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwshcore') { +@' + - !Ref CodeBuildpwshcoreProject +'@ + } +%> +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + - !Ref CodeBuildpwshProject +'@ + } +%> + State: ENABLED + Targets: + - Arn: !Ref SNSTopicForCodeBuildUpdates + Id: !Sub "${AWS::StackName}" + InputTransformer: + InputTemplate: '"The PowerShell solution build for is in state at ."' + InputPathsMap: + projectname: "$.detail.project-name" + status: "$.detail.build-status" + at: "$.time" + account: "$.account" + +Outputs: + + SNSTopic: + Description: The SNS Topic used for CodeBuild status updates + Value: !Ref SNSTopicForCodeBuildUpdates +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'ps') { +@' + CodeBuildpsProject: + Description: The name of the Windows PowerShell CodeBuild Project. + Value: !Ref CodeBuildpsProject + CodeBuildpsURL: + Description: Windows PowerShell CodeBuild URL + Value: !Sub "https://console.aws.amazon.com/codebuild/home?region=${AWS::Region}#/projects/${CodeBuildpsProject}/view" +'@ + } +%> +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwshcore') { +@' + CodeBuildpwshcoreProject: + Description: The name of the Windows pwsh CodeBuild Project. + Value: !Ref CodeBuildpwshcoreProject + CodeBuildpwshcoreURL: + Description: Windows pwsh CodeBuild URL + Value: !Sub "https://console.aws.amazon.com/codebuild/home?region=${AWS::Region}#/projects/${CodeBuildpwshcoreProject}/view" +'@ + } +%> +<% + if ($PLASTER_PARAM_GitHubACBOptions -eq 'pwsh') { +@' + CodeBuildpwshProject: + Description: The name of the Linux pwsh CodeBuild Project. + Value: !Ref CodeBuildpwshProject + CodeBuildpwshURL: + Description: Linux pwsh CodeBuild URL + Value: !Sub "https://console.aws.amazon.com/codebuild/home?region=${AWS::Region}#/projects/${CodeBuildpwshProject}/view" +'@ + } +%> diff --git a/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 b/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 new file mode 100644 index 0000000..83bbfb1 --- /dev/null +++ b/src/Catesta/Resources/GitHubActionsCodeBuild/actions_bootstrap.ps1 @@ -0,0 +1,79 @@ +# Bootstrap dependencies + +# https://docs.microsoft.com/powershell/module/packagemanagement/get-packageprovider +Get-PackageProvider -Name Nuget -ForceBootstrap | Out-Null + +# https://docs.microsoft.com/powershell/module/powershellget/set-psrepository +Set-PSRepository -Name PSGallery -InstallationPolicy Trusted + +# List of PowerShell Modules required for the build +$modulesToInstall = New-Object System.Collections.Generic.List[object] +<% +if ($PLASTER_PARAM_Pester-eq '4') { +@' +# https://github.com/pester/Pester +[void]$modulesToInstall.Add(([PSCustomObject]@{ + ModuleName = 'Pester' + ModuleVersion = '4.10.1' + })) +'@ +} +elseif ($PLASTER_PARAM_Pester-eq '5') { +@' +# https://github.com/pester/Pester +[void]$modulesToInstall.Add(([PSCustomObject]@{ + ModuleName = 'Pester' + ModuleVersion = '5.5.0' + })) +'@ +} +%> +# https://github.com/nightroman/Invoke-Build +[void]$modulesToInstall.Add(([PSCustomObject]@{ + ModuleName = 'InvokeBuild' + ModuleVersion = '5.11.1' + })) +# https://github.com/PowerShell/PSScriptAnalyzer +[void]$modulesToInstall.Add(([PSCustomObject]@{ + ModuleName = 'PSScriptAnalyzer' + ModuleVersion = '1.22.0' + })) +# https://github.com/PowerShell/platyPS +# older version used due to: https://github.com/PowerShell/platyPS/issues/457 +[void]$modulesToInstall.Add(([PSCustomObject]@{ + ModuleName = 'platyPS' + ModuleVersion = '0.12.0' + })) + +<% +if ($PLASTER_PARAM_VAULT -eq 'VAULT') { + @' +[void]$modulesToInstall.Add(([PSCustomObject]@{ + ModuleName = 'Microsoft.PowerShell.SecretManagement' + ModuleVersion = '1.1.2' + })) +'@ +} +%> + +'Installing PowerShell Modules' +foreach ($module in $modulesToInstall) { + $installSplat = @{ + Name = $module.ModuleName + RequiredVersion = $module.ModuleVersion + Repository = 'PSGallery' + SkipPublisherCheck = $true + Force = $true + ErrorAction = 'Stop' + } + try { + Install-Module @installSplat + Import-Module -Name $module.ModuleName -ErrorAction Stop + ' - Successfully installed {0}' -f $module.ModuleName + } + catch { + $message = 'Failed to install {0}' -f $module.ModuleName + " - $message" + throw + } +} diff --git a/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Linux.yml b/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Linux.yml new file mode 100644 index 0000000..6a4e852 --- /dev/null +++ b/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Linux.yml @@ -0,0 +1,58 @@ +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#using-a-specific-shell +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions +# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell +# https://github.com/actions/upload-artifact#where-does-the-upload-go +# https://docs.aws.amazon.com/codebuild/latest/userguide/action-runner.html +# https://docs.github.com/en/actions/learn-github-actions/contexts#github-context +# * NOTE: Make sure that your matches the name of the CB project that you created in your AWS account. +# * If you used the generated CFN template, the project name will be handled for you. +name: <%=$PLASTER_PARAM_ModuleName%>-Linux +on: + pull_request: + paths-ignore: + - '**.md' + - 'docs/**' + push: + paths-ignore: + - '**.md' + - 'docs/**' +jobs: + test: + name: Run Tests + runs-on: codebuild-<%=$PLASTER_PARAM_ModuleName%>-pwsh_gha_cb_linux-${{ github.run_id }}-${{ github.run_attempt }} + strategy: + fail-fast: false + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Display the path + shell: pwsh + run: echo ${env:PATH} + - name: Version Display + shell: pwsh + run: $PSVersionTable + # uncomment below to explore what modules/variables/env variables are available in the build image + # - name: Modules and Variables Display + # shell: pwsh + # run: Get-Module -ListAvailable; (Get-Variable).GetEnumerator() | Sort-Object Name | Out-String; (Get-ChildItem env:*).GetEnumerator() | Sort-Object Name | Out-String + - name: Bootstrap + shell: pwsh + run: ./actions_bootstrap.ps1 + - name: Test and Build + shell: pwsh + run: Invoke-Build -File .\src\<%=$PLASTER_PARAM_ModuleName%>.build.ps1 + - name: Upload pester results + uses: actions/upload-artifact@v3 + with: + name: pester-results + path: ./src/Artifacts/testOutput + if-no-files-found: warn + - name: Upload zip module archive build + uses: actions/upload-artifact@v3 + with: + name: zip-archive + path: ./src/Archive + if-no-files-found: warn diff --git a/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Windows.yml b/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Windows.yml new file mode 100644 index 0000000..c6b69ca --- /dev/null +++ b/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Windows.yml @@ -0,0 +1,62 @@ +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#using-a-specific-shell +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions +# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell +# https://github.com/actions/upload-artifact#where-does-the-upload-go +# * NOTE: Make sure that your matches the name of the CB project that you created in your AWS account. +# * If you used the generated CFN template, the project name will be handled for you. +name: <%=$PLASTER_PARAM_ModuleName%>-Windows-PowerShell +on: + pull_request: + paths-ignore: + - '**.md' + - 'docs/**' + push: + paths-ignore: + - '**.md' + - 'docs/**' +jobs: + test: + name: Run Tests + runs-on: codebuild-<%=$PLASTER_PARAM_ModuleName%>-powershell_gha_cb_windows-${{ github.run_id }}-${{ github.run_attempt }} + strategy: + fail-fast: false + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Display the path + shell: powershell + run: echo ${env:PATH} + - name: Version Display + shell: powershell + run: $PSVersionTable + # uncomment below to explore what modules/variables/env variables are available in the build image + # - name: Modules and Variables Display + # shell: powershell + # run: Get-Module -ListAvailable; (Get-Variable).GetEnumerator() | Sort-Object Name | Out-String; (Get-ChildItem env:*).GetEnumerator() | Sort-Object Name | Out-String + - name: NuGet Latest + shell: powershell + run: Install-PackageProvider -Name "NuGet" -Confirm:$false -Force -Verbose + - name: PowerShellGet Latest + shell: powershell + run: Install-Module -Name PowerShellGet -Repository PSGallery -Force + - name: Bootstrap + shell: powershell + run: ./actions_bootstrap.ps1 + - name: Test and Build + shell: powershell + run: Invoke-Build -File .\src\<%=$PLASTER_PARAM_ModuleName%>.build.ps1 + - name: Upload pester results + uses: actions/upload-artifact@v3 + with: + name: pester-results + path: .\src\Artifacts\testOutput + if-no-files-found: warn + - name: Upload zip module archive build + uses: actions/upload-artifact@v3 + with: + name: zip-archive + path: .\src\Archive + if-no-files-found: warn diff --git a/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Windows_Core.yml b/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Windows_Core.yml new file mode 100644 index 0000000..2502c97 --- /dev/null +++ b/src/Catesta/Resources/GitHubActionsCodeBuild/workflows/wf_Windows_Core.yml @@ -0,0 +1,56 @@ +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/virtual-environments-for-github-hosted-runners +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/software-installed-on-github-hosted-runners +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions#using-a-specific-shell +# https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions +# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-powershell +# https://github.com/actions/upload-artifact#where-does-the-upload-go +# * NOTE: Make sure that your matches the name of the CB project that you created in your AWS account. +# * If you used the generated CFN template, the project name will be handled for you. +name: <%=$PLASTER_PARAM_ModuleName%>-Windows-pwsh +on: + pull_request: + paths-ignore: + - '**.md' + - 'docs/**' + push: + paths-ignore: + - '**.md' + - 'docs/**' +jobs: + test: + name: Run Tests + runs-on: codebuild-<%=$PLASTER_PARAM_ModuleName%>-pwsh_gha_cb_windows-${{ github.run_id }}-${{ github.run_attempt }} + strategy: + fail-fast: false + steps: + - name: Check out repository + uses: actions/checkout@v3 + - name: Display the path + shell: pwsh + run: echo ${env:PATH} + - name: Version Display + shell: pwsh + run: $PSVersionTable + # uncomment below to explore what modules/variables/env variables are available in the build image + # - name: Modules and Variables Display + # shell: pwsh + # run: Get-Module -ListAvailable; (Get-Variable).GetEnumerator() | Sort-Object Name | Out-String; (Get-ChildItem env:*).GetEnumerator() | Sort-Object Name | Out-String + - name: Bootstrap + shell: pwsh + run: ./actions_bootstrap.ps1 + - name: Test and Build + shell: pwsh + run: Invoke-Build -File .\src\<%=$PLASTER_PARAM_ModuleName%>.build.ps1 + - name: Upload pester results + uses: actions/upload-artifact@v3 + with: + name: pester-results + path: .\src\Artifacts\testOutput + if-no-files-found: warn + - name: Upload zip module archive build + uses: actions/upload-artifact@v3 + with: + name: zip-archive + path: .\src\Archive + if-no-files-found: warn diff --git a/src/Catesta/Resources/Module/plasterManifest.xml b/src/Catesta/Resources/Module/plasterManifest.xml index 6c8f711..aee1d87 100644 --- a/src/Catesta/Resources/Module/plasterManifest.xml +++ b/src/Catesta/Resources/Module/plasterManifest.xml @@ -18,7 +18,7 @@ Catesta 258a61ba-566b-4c3a-8230-c2b6861a1a8d - 2.9.0 + 2.10.0 Catesta Scaffolds a new PowerShell module project Jake Morrison @@ -39,6 +39,7 @@ + @@ -48,7 +49,7 @@ - + @@ -59,6 +60,12 @@ + + + + + + @@ -296,6 +303,12 @@ + + + + + + @@ -324,11 +337,17 @@ Your new PowerShell module project '$PLASTER_PARAM_ModuleName' has been created. + Additional Catesta documentation can be found at https://www.catesta.dev/en/latest/ - + CloudFormation files have been generated for this project. You can find these in the CloudFormation folder. You can login to your AWS account and utilize these file to quickly create a stack for your project build. - More information: https://github.com/techthoughts2/Catesta/blob/main/docs/Catesta-AWS.md + + + More information: https://www.catesta.dev/en/latest/catesta_cicd/Catesta-AWS/ + + + More information: https://www.catesta.dev/en/latest/catesta_cicd/Catesta-GHActionsAWSCodeBuild diff --git a/src/Catesta/Resources/Vault/plasterManifest.xml b/src/Catesta/Resources/Vault/plasterManifest.xml index ceb21ce..2f8d8cc 100644 --- a/src/Catesta/Resources/Vault/plasterManifest.xml +++ b/src/Catesta/Resources/Vault/plasterManifest.xml @@ -6,7 +6,7 @@ Catesta d531e058-52b8-4dd2-8162-01c95d1eb8f7 - 2.9.0 + 2.10.0 Catesta Scaffolds a new PowerShell SecretManagement extension vault module project Jake Morrison diff --git a/src/Tests/Integration/FileChecks.Tests.ps1 b/src/Tests/Integration/FileChecks.Tests.ps1 index d933c80..6aa833e 100644 --- a/src/Tests/Integration/FileChecks.Tests.ps1 +++ b/src/Tests/Integration/FileChecks.Tests.ps1 @@ -25,6 +25,7 @@ Describe 'File Checks' { $gitFiles = Get-ChildItem -Path "$resourcePath\GitHubFiles\*" -Recurse $azureRepoFiles = Get-ChildItem -Path "$resourcePath\AzureRepoFiles\*" -Recurse $awsFiles = Get-ChildItem -Path "$resourcePath\AWS\*" -Recurse + $githubActionCodeBuildFiles = Get-ChildItem -Path "$resourcePath\GitHubActionsCodeBuild\*" -Recurse $githubFiles = Get-ChildItem -Path "$resourcePath\GitHubActions\*" -Recurse $azureFiles = Get-ChildItem -Path "$resourcePath\Azure\*" -Recurse $appVeyorFiles = Get-ChildItem -Path "$resourcePath\AppVeyor\*" -Recurse @@ -192,6 +193,7 @@ Describe 'File Checks' { It 'should have all workflow files' { $githubFiles.Name.Contains('wf_Linux.yml') | Should -BeExactly $true $githubFiles.Name.Contains('wf_MacOS.yml') | Should -BeExactly $true + $githubFiles.Name.Contains('wf_Windows_Core.yml') | Should -BeExactly $true $githubFiles.Name.Contains('wf_Windows.yml') | Should -BeExactly $true } #it @@ -201,6 +203,25 @@ Describe 'File Checks' { } #context_githubactions + Context 'GitHub Actions with CodeBuild' { + + It 'should have all workflow files' { + $githubActionCodeBuildFiles.Name.Contains('wf_Linux.yml') | Should -BeExactly $true + $githubActionCodeBuildFiles.Name.Contains('wf_MacOS.yml') | Should -BeExactly $false + $githubActionCodeBuildFiles.Name.Contains('wf_Windows_Core.yml') | Should -BeExactly $true + $githubActionCodeBuildFiles.Name.Contains('wf_Windows.yml') | Should -BeExactly $true + } #it + + It 'should have a actions bootstrap file' { + $githubActionCodeBuildFiles.Name.Contains('actions_bootstrap.ps1') | Should -BeExactly $true + } #it + + It 'should have all required CloudFormation files' { + $githubActionCodeBuildFiles.Name.Contains('PowerShellGitHubActionsCodeBuild.yml') | Should -BeExactly $true + } #it + + } #context_githubactionscb + Context 'Azure Pipelines' { It 'should have a pipelines file' { diff --git a/src/Tests/Integration/New-ModuleProject.Tests.ps1 b/src/Tests/Integration/New-ModuleProject.Tests.ps1 index d81c108..05088bb 100644 --- a/src/Tests/Integration/New-ModuleProject.Tests.ps1 +++ b/src/Tests/Integration/New-ModuleProject.Tests.ps1 @@ -806,6 +806,72 @@ Describe 'Module Integration Tests' { } #github_actions + Context 'GitHub Actions with CodeBuild' { + + It 'should generate a GitHub Actions based module stored on GitHub running on CodeBuild with all required elements' { + $moduleParameters = @{ + VAULT = 'text' + ModuleName = 'modulename' + Description = 'text' + Version = '0.0.1' + FN = 'user full name' + CICD = 'GHACODEBUILD' + GitHubACBOptions = 'ps', 'pwshcore', 'pwsh' + RepoType = 'GITHUB' + ReadtheDocs = 'NONE' + License = 'NONE' + Changelog = 'NONE' + COC = 'NONE' + Contribute = 'NONE' + Security = 'NONE' + CodingStyle = 'Stroustrup' + Help = 'Yes' + Pester = '5' + PassThru = $true + NoLogo = $true + } + $eval = New-ModuleProject -ModuleParameters $moduleParameters -DestinationPath $outPutPath + $eval | Should -Not -BeNullOrEmpty + + $ghaCBModuleFiles = Get-ChildItem -Path $outPutPathStar -Recurse -Force + + $ghaCBModuleFiles.Name.Contains('wf_Linux.yml') | Should -BeExactly $true + $ghaCBModuleFiles.Name.Contains('wf_MacOS.yml') | Should -BeExactly $false + $ghaCBModuleFiles.Name.Contains('wf_Windows_Core.yml') | Should -BeExactly $true + $ghaCBModuleFiles.Name.Contains('wf_Windows.yml') | Should -BeExactly $true + + $wfLinuxContentPath = [System.IO.Path]::Combine($outPutPath, '.github', 'workflows', 'wf_Linux.yml') + $wfLinuxContent = Get-Content -Path $wfLinuxContentPath -Raw + $wfLinuxContent | Should -BeLike '*modulename*' + $wfLinuxContent | Should -BeLike '*codebuild-*' + + $wfWindowsCoreContentPath = [System.IO.Path]::Combine($outPutPath, '.github', 'workflows', 'wf_Windows_Core.yml') + $wfWindowsCoreContent = Get-Content -Path $wfWindowsCoreContentPath -Raw + $wfWindowsCoreContent | Should -BeLike '*modulename*' + $wfWindowsCoreContent | Should -BeLike '*codebuild-*' + + $wfWindowsContentPath = [System.IO.Path]::Combine($outPutPath, '.github', 'workflows', 'wf_Windows.yml') + $wfWindowsContent = Get-Content -Path $wfWindowsContentPath -Raw + $wfWindowsContent | Should -BeLike '*modulename*' + $wfWindowsContent | Should -BeLike '*codebuild-*' + + $ghaCBModuleFiles.Name.Contains('PowerShellGitHubActionsCodeBuild.yml') | Should -BeExactly $true + + $cfnContentPath = [System.IO.Path]::Combine($outPutPath, 'CloudFormation', 'PowerShellGitHubActionsCodeBuild.yml') + $cfnContent = Get-Content -Path $cfnContentPath -Raw + $cfnContent | Should -BeLike "*CodeBuildpsProject*" + $cfnContent | Should -BeLike "*CodeBuildpwshcoreProject*" + $cfnContent | Should -BeLike "*CodeBuildpwshProject*" + $cfnContent | Should -BeLike "*CodeBuildpsProjectLogGroup*" + $cfnContent | Should -BeLike "*CodeBuildpwshcoreProjectLogGroup*" + $cfnContent | Should -BeLike "*CodeBuildpwshProjectLogGroup*" + $cfnContent | Should -BeLike "*GITHUB*" + $cfnContent | Should -BeLike "*WORKFLOW_JOB_QUEUED*" + + } #it + + } #github_actions_codebuild + Context 'Bitbucket Build' { It 'should generate a Bitbucket based module stored on Bitbucket with all required elements' {