-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: improve error handlings for built-in code build flows (node-npm…
…, python-pip and java-mvn)
- Loading branch information
Showing
14 changed files
with
408 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,137 @@ | ||
# Powershell script for ask-cli code build for java-mvn flow. | ||
# Script Usage: build.ps1 <OUT_FILE> <DO_DEBUG> | ||
|
||
# OUT_FILE is the file name for the output (required) | ||
# DO_DEBUG is boolean value for debug logging | ||
#requires -version 3 | ||
<# | ||
.SYNOPSIS | ||
PowerShell script for ask-cli's Java-mvn code building flow. | ||
.DESCRIPTION | ||
This is the PowerShell version of the build script, for building the AWS Lambda deployable skill code that is written in Java language. This script is only run by the ask-cli whenever a 'pom.xml' file is found alongside the skill code. The dependencies are installed and packaged using 'mvn'. | ||
.EXAMPLE | ||
build.ps1 archive.zip | ||
This example showcases how to run the build script, to create an AWS Lambda deployable package called 'archive.zip'. | ||
.EXAMPLE | ||
build.ps1 archive.zip $true | ||
This example showcases how to run the previous example, with additional debug information. | ||
#> | ||
#----------------[ Parameters ]---------------------------------------------------- | ||
param( | ||
[Parameter(Mandatory = $false, | ||
ValueFromPipelineByPropertyName = $true, | ||
HelpMessage = "Name for the AWS Lambda deployable archive")] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$script:OutFile = "upload.zip", | ||
|
||
# Run this script whenever a pom.xml is defined | ||
|
||
param( | ||
[string] $OUT_FILE, | ||
[bool] $DO_DEBUG = $False, | ||
# Provide additional debug information during script run | ||
[Parameter(Mandatory = $false, | ||
ValueFromPipelineByPropertyName = $true, | ||
HelpMessage = "Enable verbose output")] | ||
[bool] | ||
$script:Verbose = $false | ||
) | ||
|
||
function install_dependencies () { | ||
Invoke-Expression "mvn clean org.apache.maven.plugins:maven-assembly-plugin:2.6:assembly -DdescriptorId=jar-with-dependencies package" 2>&1 | Out-Null | ||
$EXEC_RESULT = $? | ||
return $EXEC_RESULT | ||
#----------------[ Declarations ]---------------------------------------------------- | ||
$ErrorActionPreference = "Stop" | ||
|
||
#----------------[ Functions ]---------------------------------------------------- | ||
function Show-Log() { | ||
<# | ||
.SYNOPSIS | ||
Function to log information/error messages to output | ||
.EXAMPLE | ||
Show-Log "Test" | ||
This will log the message as an Information, only if the script is run in Verbose mode | ||
Show-Log "Test" "Error" | ||
This will log the message as an Error and STOP the script execution | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$Message, | ||
|
||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[ValidateSet('Info','Error')] | ||
[string] | ||
$Severity = 'Info' | ||
) | ||
|
||
begin {} | ||
process { | ||
if ($Severity -eq 'Info') { | ||
if ($Verbose) { | ||
Write-Host $Message | ||
} | ||
} else { | ||
Write-Error $Message | ||
} | ||
} | ||
end {} | ||
} | ||
|
||
if ($DO_DEBUG) { | ||
Write-Output "###########################" | ||
Write-Output "####### Build Code ########" | ||
Write-Output "###########################" | ||
function Build-SkillArtifacts() { | ||
<# | ||
.SYNOPSIS | ||
Function to compile the skill project, aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable jar | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([bool])] | ||
param() | ||
|
||
begin { | ||
Show-Log "Building skill artifacts based on pom.xml." | ||
} | ||
process { | ||
$DepCmd = "mvn clean org.apache.maven.plugins:maven-assembly-plugin:2.6:assembly -DdescriptorId=jar-with-dependencies package" | ||
if (-not $Verbose) { | ||
$DepCmd += " --quiet" | ||
} | ||
Invoke-Expression -Command $DepCmd | Out-String | Tee-Object -Variable 'result' | ||
if(!($LASTEXITCODE -eq 0)) { | ||
Show-Log "$result `n Failed to build the skill artifacts in the project." "Error" | ||
} | ||
return $true | ||
} | ||
end {} | ||
} | ||
|
||
if (install_dependencies) { | ||
Move-Item -Path ./target/*jar-with-dependencies.jar -Destination $OUT_FILE | ||
if ($DO_DEBUG) { | ||
Write-Output "Codebase built successfully." | ||
function Rename-Archive() { | ||
<# | ||
.SYNOPSIS | ||
Function to rename the build archive into cli format. | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([bool])] | ||
param() | ||
|
||
begin { | ||
Show-Log "Renaming build archive to $OutFile." | ||
} | ||
} else { | ||
if ($DO_DEBUG) { | ||
Write-Output "There was a problem installing the dependencies." | ||
process { | ||
Move-Item -Path ./target/*jar-with-dependencies.jar -Destination $OutFile | ||
return $? | ||
} | ||
exit 1 | ||
end {} | ||
|
||
} | ||
|
||
#----------------[ Main Execution ]---------------------------------------------------- | ||
|
||
Show-Log "###########################" | ||
Show-Log "####### Build Code ########" | ||
Show-Log "###########################" | ||
|
||
if (Build-SkillArtifacts) { | ||
Show-Log "Skill artifacts built successfully." | ||
} | ||
if ($DO_DEBUG) { | ||
Write-Output "###########################" | ||
|
||
if (-Not (Rename-Archive)) { | ||
Show-Log "Failed to rename build archive to $OutFile" "Error" | ||
} | ||
|
||
Show-Log "###########################" | ||
Show-Log "Codebase built successfully" | ||
Show-Log "###########################" | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,137 @@ | ||
# Powershell script for ask-cli code build for nodejs-npm flow. | ||
# Script Usage: build.ps1 <OUT_FILE> <DO_DEBUG> | ||
|
||
# OUT_FILE is the file name for the output (required) | ||
# DO_DEBUG is boolean value for debug logging | ||
#requires -version 3 | ||
<# | ||
.SYNOPSIS | ||
PowerShell script for ask-cli's Nodejs-npm code building flow. | ||
.DESCRIPTION | ||
This is the PowerShell version of the build script, for building the AWS Lambda deployable skill code that is written in JS language. This script is only run by the ask-cli whenever a 'package.json' file is found alongside the skill code. The dependencies are installed using 'npm', and are packaged using 'zip'. | ||
.EXAMPLE | ||
build.ps1 archive.zip | ||
This example showcases how to run the build script, to create an AWS Lambda deployable package called 'archive.zip'. | ||
.EXAMPLE | ||
build.ps1 archive.zip $true | ||
This example showcases how to run the previous example, with additional debug information. | ||
#> | ||
#----------------[ Parameters ]---------------------------------------------------- | ||
param( | ||
[Parameter(Mandatory = $false, | ||
ValueFromPipelineByPropertyName = $true, | ||
HelpMessage = "Name for the AWS Lambda deployable archive")] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$script:OutFile = "upload.zip", | ||
|
||
# Run this script whenever a package.json is defined | ||
|
||
param( | ||
[string] $OUT_FILE, | ||
[bool] $DO_DEBUG = $False | ||
# Provide additional debug information during script run | ||
[Parameter(Mandatory = $false, | ||
ValueFromPipelineByPropertyName = $true, | ||
HelpMessage = "Enable verbose output")] | ||
[bool] | ||
$script:Verbose = $false | ||
) | ||
|
||
function install_dependencies () { | ||
Invoke-Expression "npm install" 2>&1 | Out-Null | ||
$EXEC_RESULT = $? | ||
return $EXEC_RESULT | ||
#----------------[ Declarations ]---------------------------------------------------- | ||
$ErrorActionPreference = "Stop" | ||
|
||
#----------------[ Functions ]---------------------------------------------------- | ||
function Show-Log() { | ||
<# | ||
.SYNOPSIS | ||
Function to log information/error messages to output | ||
.EXAMPLE | ||
Show-Log "Test" | ||
This will log the message as an Information, only if the script is run in Verbose mode | ||
Show-Log "Test" "Error" | ||
This will log the message as an Error and STOP the script execution | ||
#> | ||
[CmdletBinding()] | ||
param( | ||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[string] | ||
$Message, | ||
|
||
[Parameter()] | ||
[ValidateNotNullOrEmpty()] | ||
[ValidateSet('Info','Error')] | ||
[string] | ||
$Severity = 'Info' | ||
) | ||
|
||
begin {} | ||
process { | ||
if ($Severity -eq 'Info') { | ||
if ($Verbose) { | ||
Write-Host $Message | ||
} | ||
} else { | ||
Write-Error $Message | ||
} | ||
} | ||
end {} | ||
} | ||
|
||
if ($DO_DEBUG) { | ||
Write-Output "###########################" | ||
Write-Output "####### Build Code ########" | ||
Write-Output "###########################" | ||
function Install-Dependencies() { | ||
<# | ||
.SYNOPSIS | ||
Function to install dependencies in package.json from npm. | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([bool])] | ||
param() | ||
|
||
begin { | ||
Show-Log "Installing skill dependencies based on package.json." | ||
} | ||
process { | ||
$DepCmd = "npm install --production" | ||
if (-not $Verbose) { | ||
$DepCmd += " --quiet" | ||
} | ||
Invoke-Expression -Command $DepCmd | ||
if(!($LASTEXITCODE -eq 0)) { | ||
Show-Log "Failed to install the dependencies in the project" "Error" | ||
} | ||
return $true | ||
} | ||
end {} | ||
} | ||
|
||
if (install_dependencies) { | ||
Compress-Archive -Path ./* -DestinationPath $OUT_FILE | ||
if ($DO_DEBUG) { | ||
Write-Output "Codebase built successfully." | ||
function Compress-Dependencies() { | ||
<# | ||
.SYNOPSIS | ||
Function to compress source code and dependencies for lambda deployment. | ||
#> | ||
[CmdletBinding()] | ||
[OutputType([bool])] | ||
param() | ||
|
||
begin { | ||
Show-Log "Zipping source files and dependencies to $OutFile." | ||
} | ||
} else { | ||
if ($DO_DEBUG) { | ||
Write-Output "There was a problem installing the dependencies." | ||
process { | ||
Compress-Archive -Path ./* -DestinationPath $OutFile | ||
return $? | ||
} | ||
exit 1 | ||
end {} | ||
|
||
} | ||
|
||
#----------------[ Main Execution ]---------------------------------------------------- | ||
|
||
Show-Log "###########################" | ||
Show-Log "####### Build Code ########" | ||
Show-Log "###########################" | ||
|
||
if (Install-Dependencies) { | ||
Show-Log "npm install dependencies successfully." | ||
} | ||
if ($DO_DEBUG) { | ||
Write-Output "###########################" | ||
|
||
if (-Not (Compress-Dependencies)) { | ||
Show-Log "Failed to zip the artifacts to $OutFile" "Error" | ||
} | ||
|
||
Show-Log "###########################" | ||
Show-Log "Codebase built successfully" | ||
Show-Log "###########################" | ||
|
||
exit 0 |
Oops, something went wrong.