PowerShell Test / GitHub Actions Workflow Docs Update (#29)

* integrate BicepTranspileService (#23)

* doc update

* small changes

* FileNotFoundException test added

* transpile bicep test mokc refactoring

Co-authored-by: jessica-ern <107070686+jessica-ern@users.noreply.github.com>
This commit is contained in:
Dilmurod Makhamadaliev 2022-11-11 10:59:27 -05:00 коммит произвёл GitHub
Родитель 9b853fa996
Коммит 479f542ea6
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 67 добавлений и 55 удалений

Просмотреть файл

@ -1,6 +1,6 @@
# Github Actions Lint Workflow
Current repo has three linting workflows in the `.github/workflows`. Each workflow uses specific Megalinter flavor to lint specific folders when new code gets pushed. All configuration files are located under `config/megalinter` directory
Current repo has three linting workflows in the `.github/workflows` directory. Each workflow uses specific Megalinter flavor to lint specific folders when new code gets pushed. All configuration files are located under `config/megalinter` directory
- pr_dotnet - uses `oxsecurity/megalinter/flavors/dotnet@v6.12.0` to lint dotnet code in the `framework/` and `samples/` directories
- pr_python - uses `oxsecurity/megalinter/flavors/python@v6.12.0` to lint python code in the `framework/` and `samples/` directories
@ -29,25 +29,44 @@ Rather than having to commit/push every time you want to test out the changes yo
This is an example of running `.github/workflows/pr_dotnet.yml` file to lint dotnet specific folders locally using `act` command
Run the workflow locally using `act` command
```sh
act pull_request --workflows .\.github\workflows\pr_docs.yaml
```
```yaml
name: pr_dotnet
on:
pull_request:
paths-ignore:
paths:
- "framework/dotnet/**"
- "samples/dotnet/**"
- "engine/**"
- "protos/**"
- ".github/workflows/pr_dotnet.yaml"
branches:
- main
env:
DOTNET_VERSION: '6.0.x'
jobs:
lint:
runs-on: ubuntu-latest
name: lint-${{matrix.os}}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest ]
steps:
- name: Checkout code
- name: Checkout repository and submodules
uses: actions/checkout@v3
with:
token: ${{ secrets.PAT || secrets.GITHUB_TOKEN }}
fetch-depth: 0
submodules: recursive
- name: MegaLinter dotnet flavor
uses: oxsecurity/megalinter/flavors/dotnet@v6.12.0
@ -57,42 +76,18 @@ jobs:
PRINT_ALL_FILES: true
DISABLE: SPELL,COPYPASTE,YAML
DISABLE_LINTERS: REPOSITORY_CHECKOV,REPOSITORY_TRIVY
FILTER_REGEX_EXCLUDE: '(BenchPress/|engine/|examples/|/docs|\.github/workflows|\.devcontainer|\.editorconfig|\.gitmodules|\.sln|\.md|LICENSE|/framework/python|samples/python)'
FILTER_REGEX_INCLUDE: "(framework/dotnet|samples/dotnet)"
FILTER_REGEX_INCLUDE: '(framework/dotnet|samples/dotnet|engine/)'
FILTER_REGEX_EXCLUDE: '(examples/|/docs|\.devcontainer|\.editorconfig|\.gitmodules|\.sln|\.md|LICENSE|/framework/python|samples/python)'
REPORT_OUTPUT_FOLDER: ${GITHUB_WORKSPACE}/megalinter-reports
```
Run workflow using `act` command
```sh
act pull_request --workflows .\.github\workflows\pr_docs.yaml
```
#### Linting overview
When pull_request is created, following directories gets skipped from linting to allow the merge
```yaml
pull_request:
paths-ignore:
- "framework/dotnet/**"
- "samples/dotnet/**"
branches:
- main
```
In this pr_dotnet workflow, we are using Megalinter flavor for dotnet
```yaml
- name: MegaLinter dotnet flavor
uses: oxsecurity/megalinter/flavors/dotnet@v6.12.0
```
Finally, using Megalinter env variables to exclude and include directories for linting, and disable linters for this pr_dotnet
```yaml
env:
DISABLE_LINTERS: REPOSITORY_CHECKOV,REPOSITORY_TRIVY
FILTER_REGEX_EXCLUDE: '(BenchPress/|engine/|examples/|/docs|\.github/workflows|\.devcontainer|\.editorconfig|\.gitmodules|\.sln|\.md|LICENSE|/framework/python|samples/python)'
FILTER_REGEX_INCLUDE: "(framework/dotnet|samples/dotnet)"
- name: Setup dotnet
uses: actions/setup-dotnet@v3
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Install dependencies
run: dotnet restore
- name: Build
run: dotnet build --configuration Release --no-restore
```

Просмотреть файл

@ -1,19 +1,38 @@
# How to test PowerShell Test Sample Code
# PowerShell How To Test Example
Following instruction shows how to run StorageAccount.Tests.ps1 file
Following instructions shows how to run StorageAccount.Tests.ps1 test.
File is located under following directory: `/samples/dotnet/samples/pwsh/Test`
`StorageAccount.Test.ps1`:
Login to Azure Subscription `Connect-AzAccount`
if you are using docker container `Connect-AzAccount -UseDeviceAuthentication` and follow additional login instruction on the terminal
- Deploys Azure resources to the Azure Cloud
- tests deployed resource properties
- Finally deletes deployed resources.
Run the test `.\StorageAccount.Tests.ps1`
## Prerequisites
- Azure Subscription
- Azure CLI
- Pester [Pester Install Guide](https://pester.dev/docs/introduction/installation)
- Optional: Docker
Test files are located under the following directory: `/samples/dotnet/samples/pwsh/Test`
## Step by Step Guide
### Auth to Azure
Login to Azure Subscription `Connect-AzAccount` from Azure CLI
if you are using docker container `Connect-AzAccount -UseDeviceAuthentication` and follow additional login instructions prompted by terminal
### Running the Test
Storage Account deployment uses two bicep files:
- `storageAccountDeploy.bicep` - to deploy resource group and storage account module. This is an actual deployment file
- `storageAccount.bicep` - storage account bicep file which is called by `storageAccountDeploy.bicep` as a module file
To run the test simply navigate to the `StorageAccount.Tests.ps1` in CLI and execute the PowerShell test file `.\StorageAccount.Tests.ps1`
`StorageAccount.Tests.ps1` - Content.
```powershell
@ -79,5 +98,4 @@ Describe 'Spin up , Tear down Storage Account' {
Remove-BicepFeature $resourceGroupName
}
}
#EOF
```

Просмотреть файл

@ -224,7 +224,7 @@ public class DeploymentServiceTests
.ReturnsAsync(operation);
}
private void SetUpFailedGroupDeployment(string reason)
private void SetUpFailedGroupDeployment(string reason)
{
var operation = SetupDeploymentOperation(false, reason);
armDeploymentMock.Setup(x => x.DeployArmToResourceGroupAsync(
@ -244,11 +244,10 @@ public class DeploymentServiceTests
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<Azure.WaitUntil>()))
.ThrowsAsync(ex);
.ThrowsAsync(ex);
}
private void VerifyGroupDeployment(DeploymentGroupRequest request, string templatePath)
{
private void VerifyGroupDeployment(DeploymentGroupRequest request, string templatePath) {
armDeploymentMock.Verify(x => x.DeployArmToResourceGroupAsync(
request.SubscriptionNameOrId,
request.ResourceGroupName,
@ -270,7 +269,7 @@ public class DeploymentServiceTests
.ReturnsAsync(operation);
}
private void SetUpFailedSubDeployment(string reason)
private void SetUpFailedSubDeployment(string reason)
{
var operation = SetupDeploymentOperation(false, reason);
armDeploymentMock.Setup(x => x.DeployArmToSubscriptionAsync(
@ -290,7 +289,7 @@ public class DeploymentServiceTests
It.IsAny<string>(),
It.IsAny<string>(),
It.IsAny<Azure.WaitUntil>()))
.ThrowsAsync(ex);
.ThrowsAsync(ex);
}
private void VerifySubDeployment(DeploymentSubRequest request, string templatePath)
@ -322,4 +321,4 @@ public class DeploymentServiceTests
It.IsAny<Azure.WaitUntil>()),
Times.Never);
}
}
}