Skip to content

Commit

Permalink
Cherry picked commits from main (#65)
Browse files Browse the repository at this point in the history
* Added issue template for health dashboard

* Added assignees

* Updated default label worlkflow for health dashboard

* Updated days-before-stale

* Added failOnStdError input

* Updated logic to use return code.

* Default case for failStdErr set to true

* Added negative tests

* Resolved comments

* Readme changes
  • Loading branch information
t-dedah authored Jun 30, 2021
1 parent dfd7836 commit baacacf
Show file tree
Hide file tree
Showing 15 changed files with 291 additions and 83 deletions.
10 changes: 10 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report---feature-request.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
name: Bug Report / Feature Request
about: Create a report to help us improve
title: ''
labels: need-to-triage
assignees: bishal-pdMSFT, t-dedah

---


28 changes: 28 additions & 0 deletions .github/workflows/ci-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@ jobs:
INPUT_PARAMETERS: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/webapp-basic-linux/azuredeploy.parameters.json
INPUT_DEPLOYMENTNAME: github-test-rg
INPUT_DEPLOYMENTMODE: Complete
EXPECTED_TO: pass
run: ts-node test/main.tests.ts

- name: Resource group scope test - Negative
env:
INPUT_SCOPE: resourcegroup
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_RESOURCEGROUPNAME: E2eTestResourceGroupForArmAction
INPUT_TEMPLATE: ./test/resourceGroup-Negative/template.json
INPUT_PARAMETERS: ./test/resourceGroup-Negative/parameters.json
INPUT_REGION: eastasia
INPUT_DEPLOYMENTNAME: github-test-rg
INPUT_DEPLOYMENTMODE: Complete
EXPECTED_TO: fail
run: ts-node test/main.tests.ts

- name: Management group scope test
Expand All @@ -37,6 +51,7 @@ jobs:
INPUT_TEMPLATE: ./test/template.json
INPUT_PARAMETERS: ./test/parameters.json
INPUT_DEPLOYMENTNAME: github-test-mg
EXPECTED_TO: pass
run: ts-node test/main.tests.ts

- name: Subscription scope test
Expand All @@ -47,6 +62,18 @@ jobs:
INPUT_TEMPLATE: https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/azure-resource-manager/emptyRG.json
INPUT_PARAMETERS: rgName=demoResourceGroup rgLocation=centralus
INPUT_DEPLOYMENTNAME: github-test-subs
EXPECTED_TO: pass
run: ts-node test/main.tests.ts

- name: Subscription scope test - Negative
env:
INPUT_SCOPE: subscription
INPUT_SUBSCRIPTIONID: ${{ secrets.SUBSCRIPTION_ID }}
INPUT_REGION: centralus
INPUT_TEMPLATE: ./test/subscription-Negative/template.json
INPUT_PARAMETERS: rgName=demoResourceGroup rgLocation=centralus
INPUT_DEPLOYMENTNAME: github-test-subs
EXPECTED_TO: fail
run: ts-node test/main.tests.ts

- name: Validate mode test
Expand All @@ -58,4 +85,5 @@ jobs:
INPUT_PARAMETERS: https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.web/webapp-basic-linux/azuredeploy.parameters.json
INPUT_DEPLOYMENTNAME: github-test-rg
INPUT_DEPLOYMENTMODE: Validate
EXPECTED_TO: pass
run: ts-node test/main.tests.ts
38 changes: 27 additions & 11 deletions .github/workflows/defaultLabel.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
name: Mark issues "default"
name: setting-default-labels

# Controls when the action will run.
on:
schedule:
- cron: "0 0/3 * * *"

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
stale:

build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is marked default for generating issues report.'
stale-issue-label: 'default'
days-before-stale: 0
days-before-close: -1
operations-per-run: 100

- uses: actions/stale@v3
name: Setting issue as idle
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'This issue is idle because it has been open for 14 days with no activity.'
stale-issue-label: 'idle'
days-before-stale: 7
days-before-close: -1
operations-per-run: 100
exempt-issue-labels: 'backlog'

- uses: actions/stale@v3
name: Setting PR as idle
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-pr-message: 'This PR is idle because it has been open for 14 days with no activity.'
stale-pr-label: 'idle'
days-before-stale: 5
days-before-close: -1
operations-per-run: 100
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ This action can be used to deploy Azure Resource Manager templates at different
* `parameters`: Specify the path or URL to the Azure Resource Manager deployment parameter values. Or local / remote value file.
* `deploymentMode`: `Incremental`(default) (only add resources to resource group) or `Complete` (remove extra resources from resource group) or `Validate` (only validates the template).
* `deploymentName`: Specifies the name of the resource group deployment to create.


* `failOnStdErr`: Specify whether to fail the action if some data is written to stderr stream of az cli. Valid values are: true, false. Default value set to true.

## Outputs
Every template output will be exported as output.
Expand Down Expand Up @@ -140,6 +139,25 @@ If we now add a Shell script with a simple echo from that value, we can see that

ARM Deploy Actions is supported for the Azure public cloud as well as Azure government clouds ('AzureUSGovernment' or 'AzureChinaCloud') and Azure Stack ('AzureStack') Hub. Before running this action, login to the respective Azure Cloud using [Azure Login](https://github.com/Azure/login) by setting appropriate value for the `environment` parameter.

## Example on how to use failOnStdErr
In this example, we are setting `failOnStdErr` to false.

```yaml
- uses: azure/arm-deploy@v1
id: deploy
with:
resourceGroupName: azurearmaction
template: examples/template/template.json
parameters: examples/template/parameters.json
deploymentName: github-advanced-test
failOnStdErr: false
```
`failOnStdErr` equals true implied that if some data is written to stdErr and exit code from az-cli is 0, then action execution will fail.

`failOnStdErr` equals false implies that if some data is written to stdErr and return code from az-cli is 0, then action will continue execution. This input is added to support cases where stdErr is being used to stream warning or progress info.

Non zero Exit code will always lead to failure of action irrespective the value of `failOnStdErr`.

For more examples, refer : [Example Guide](https://github.com/Azure/arm-deploy/blob/main/examples/exampleGuide.md)

# Contributing
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ inputs:
parameters:
description: "Supply deployment parameter values."
required: false
failOnStdErr:
description: "Specify whether to fail the action if some data is written to stderr stream of az cli. Valid values are: true, false"
required: false
default: true
branding:
color: orange
icon: package
Expand Down
18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
"typescript": "^3.8.3"
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.3",
"@actions/io": "^1.0.2",
"@actions/core": "^1.4.0",
"@actions/exec": "^1.1.0",
"@actions/io": "^1.1.1",
"@types/assert": "^1.4.7",
"@types/node": "^13.9.1"
}
Expand Down
32 changes: 18 additions & 14 deletions src/deploy/scope_managementgroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecOptions } from '@actions/exec/lib/interfaces';
import { ParseOutputs, Outputs } from '../utils/utils';
import * as core from '@actions/core';

export async function DeployManagementGroupScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, managementGroupId: string): Promise<Outputs> {
export async function DeployManagementGroupScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, managementGroupId: string, failOnStdErr: Boolean): Promise<Outputs> {
// Check if region is set
if (!region) {
throw Error("Region must be set.")
Expand All @@ -26,14 +26,19 @@ export async function DeployManagementGroupScope(azPath: string, region: string,

// configure exec to write the json output to a buffer
let commandOutput = '';
let commandStdErr = '';
let commandStdErr = false;
const deployOptions: ExecOptions = {
silent: true,
ignoreReturnCode: true,
failOnStdErr: false,
listeners: {
stderr: (data: BufferSource) => {
commandStdErr += data.toString();
let error = data.toString();
if(error && error.trim().length !== 0)
{
commandStdErr = true;
core.error(error);
}
},
stdout: (data: BufferSource) => {
commandOutput += data.toString();
Expand Down Expand Up @@ -66,18 +71,17 @@ export async function DeployManagementGroupScope(azPath: string, region: string,
// execute the deployment
core.info("Creating deployment...")
var deploymentCode = await exec(`"${azPath}" deployment mg create ${azDeployParameters} -o json`, [], deployOptions);
if (commandStdErr.trim().length !== 0) {
throw new Error(`Deployment process failed as some lines were written to stderr: ${commandStdErr}`)
} else {
if (deploymentCode != 0) {
core.error("Deployment failed.")
}
core.debug(commandOutput);

// Parse the Outputs
core.info("Parsing outputs...")
return ParseOutputs(commandOutput)

if (deploymentCode != 0) {
throw new Error("Deployment failed.")
}
if(commandStdErr && failOnStdErr) {
throw new Error("Deployment process failed as some lines were written to stderr");
}

core.debug(commandOutput);
core.info("Parsing outputs...")
return ParseOutputs(commandOutput)
}
return {}
}
32 changes: 18 additions & 14 deletions src/deploy/scope_resourcegroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { exec } from '@actions/exec';
import { ExecOptions } from '@actions/exec/lib/interfaces';
import { ParseOutputs, Outputs } from '../utils/utils';

export async function DeployResourceGroupScope(azPath: string, resourceGroupName: string, template: string, deploymentMode: string, deploymentName: string, parameters: string): Promise<Outputs> {
export async function DeployResourceGroupScope(azPath: string, resourceGroupName: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, failOnStdErr: Boolean): Promise<Outputs> {
// Check if resourceGroupName is set
if (!resourceGroupName) {
throw Error("ResourceGroup name must be set.")
Expand All @@ -28,14 +28,19 @@ export async function DeployResourceGroupScope(azPath: string, resourceGroupName

// configure exec to write the json output to a buffer
let commandOutput = '';
let commandStdErr = '';
let commandStdErr = false;
const deployOptions: ExecOptions = {
silent: true,
ignoreReturnCode: true,
failOnStdErr: false,
listeners: {
stderr: (data: BufferSource) => {
commandStdErr += data.toString();
let error = data.toString();
if(error && error.trim().length !== 0)
{
commandStdErr = true;
core.error(error);
}
},
stdout: (data: BufferSource) => {
commandOutput += data.toString();
Expand Down Expand Up @@ -68,18 +73,17 @@ export async function DeployResourceGroupScope(azPath: string, resourceGroupName
// execute the deployment
core.info("Creating deployment...")
var deploymentCode = await exec(`"${azPath}" deployment group create ${azDeployParameters} -o json`, [], deployOptions);
if (commandStdErr.trim().length !== 0) {
throw new Error(`Deployment process failed as some lines were written to stderr: ${commandStdErr}`)
} else {
if (deploymentCode != 0) {
core.error("Deployment failed.")
}
core.debug(commandOutput);

// Parse the Outputs
core.info("Parsing outputs...")
return ParseOutputs(commandOutput)

if (deploymentCode != 0) {
throw new Error("Deployment failed.")
}
if(commandStdErr && failOnStdErr) {
throw new Error("Deployment process failed as some lines were written to stderr");
}

core.debug(commandOutput);
core.info("Parsing outputs...")
return ParseOutputs(commandOutput)
}
return {}
}
32 changes: 18 additions & 14 deletions src/deploy/scope_subscription.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExecOptions } from '@actions/exec/lib/interfaces';
import { ParseOutputs, Outputs } from '../utils/utils';
import * as core from '@actions/core';

export async function DeploySubscriptionScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string): Promise<Outputs> {
export async function DeploySubscriptionScope(azPath: string, region: string, template: string, deploymentMode: string, deploymentName: string, parameters: string, failOnStdErr: Boolean): Promise<Outputs> {
// Check if region is set
if (!region) {
throw Error("Region must be set.")
Expand All @@ -26,14 +26,19 @@ export async function DeploySubscriptionScope(azPath: string, region: string, te

// configure exec to write the json output to a buffer
let commandOutput = '';
let commandStdErr = '';
let commandStdErr = false;
const deployOptions: ExecOptions = {
silent: true,
ignoreReturnCode: true,
failOnStdErr: false,
listeners: {
stderr: (data: BufferSource) => {
commandStdErr += data.toString();
let error = data.toString();
if(error && error.trim().length !== 0)
{
commandStdErr = true;
core.error(error);
}
},
stdout: (data: BufferSource) => {
commandOutput += data.toString();
Expand Down Expand Up @@ -66,18 +71,17 @@ export async function DeploySubscriptionScope(azPath: string, region: string, te
// execute the deployment
core.info("Creating deployment...")
var deploymentCode = await exec(`"${azPath}" deployment sub create ${azDeployParameters} -o json`, [], deployOptions);
if (commandStdErr.trim().length !== 0) {
throw new Error(`Deployment process failed as some lines were written to stderr: ${commandStdErr}`)
} else {
if (deploymentCode != 0) {
core.error("Deployment failed.")
}
core.debug(commandOutput);

// Parse the Outputs
core.info("Parsing outputs...")
return ParseOutputs(commandOutput)

if (deploymentCode != 0) {
throw new Error("Deployment failed.")
}
if(commandStdErr && failOnStdErr) {
throw new Error("Deployment process failed as some lines were written to stderr");
}

core.debug(commandOutput);
core.info("Parsing outputs...")
return ParseOutputs(commandOutput)
}
return {}
}
Loading

0 comments on commit baacacf

Please sign in to comment.