Skip to content

Commit

Permalink
Feat: reusable lighthouse image (#23)
Browse files Browse the repository at this point in the history
* chore: initial commit from template

* chore: rename step

* chore: sonar container with param

* chore: param the lighthouse steps

* feat: docker lighthouse step

* fix: param changes

* fix: linting

* chore: try remove the other array

* chore: define as multivalue

* chore: debug

* chore: indentation

* chore: indentation

* fix: linting

* feat: remove redundent param

* fix: iterate through urls

* fix: linting indentation and parenthesis

* chore: publish results regardless of outcome

* chore: refactor uploading to blob

* fix: relative to step

* fix: working dir

* fix: reference param

* chore: add in target

* fix: linting

* chore: target container

* chore: check current dir

* chore: silly me figuring out devops

* fix: remove container

* chore: upload results blob

* chore: remove old code

* chore: remove blob as step of step

* chore: add back in upload to blob

* chore: debug file contents

* chore: remve debugging
  • Loading branch information
estherthetesteramido authored Jun 16, 2020
1 parent c99243f commit f838bce
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 27 deletions.
10 changes: 3 additions & 7 deletions azDevOps/azure/templates/v2/steps/build-node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ parameters:
# Static Code Analysis
static_code_analysis: false
static_code_analysis_build_path: ""
Sonar_serviceConnection: ""
Sonar_organization: ""
Sonar_scannerMode: ""
Sonar_projectKey: ""
Sonar_projectName: ""
Sonar_projectVersion: ""
sonar_container: ""
# Linting and formatting validation
lint_formatting: ""
shared_eslint_config: ""
Expand Down Expand Up @@ -92,7 +87,8 @@ steps:
- ${{ if eq(parameters.static_code_analysis, true) }}:
- template: ./test-static-code-sonar.yml
parameters:
workingDirectory: ${{ parameters.project_root_dir }}
working_directory: ${{ parameters.project_root_dir }}
target_container: ${{ parameters.sonar_container }}

# Consumer driven contract tests
- ${{ if eq(parameters.contract_test, true) }}:
Expand Down
30 changes: 30 additions & 0 deletions azDevOps/azure/templates/v2/steps/test-profiling-lighthouse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
############################################################################################################
# desc: Runs the lighthouse ci in a docker container.
# return:
# inputs:
# - working_directory
# - target_container (see amidostacks/lhci)
# - lighthouse_config_filename: name of the lighthouse config file, eg. lighthouserc.json
# - lighthouse_command: commands to run as configured in the config file, e.g. collect, assert, server
# - lighthouse_urls: list/array of urls to run on, overiding defaults in config file. eg. - google.com
# pre-reqs: Deployed webapp on a given URL
############################################################################################################

parameters:
working_directory: ''
target_container: ''
lighthouse_config_filename: ''
lighthouse_commands: []
lighthouse_urls: []

steps:
- ${{ each url in parameters.lighthouse_urls }}:
- ${{ each lhcommand in parameters.lighthouse_commands }}:
- bash: |
lhci ${{ lhcommand }} --config=${{ parameters.lighthouse_config_filename }}
target:
container: ${{ parameters.target_container }}
displayName: "Lighthouse Audit: lhci ${{ lhcommand }}"
workingDirectory: ${{ parameters.working_directory }}
env:
LHCI_URL: ${{ url }}
30 changes: 30 additions & 0 deletions azDevOps/azure/templates/v2/steps/test-publish-blob.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
############################################################################################################
# desc: Publishes reports and converts and uploads to specified blob container
# params: test tool (eg, cypress, testcafe, selenium, lighthouse), working dir, blob storage account, storage container
# tests results path, blob prefix
# return:
# pre-reqs:
############################################################################################################

parameters:
test_tool_name: ''
working_directory: ''
test_results_storage: ''
test_results_blob_prefix: ''
test_results_container: 'testresults'
test_results_path: $(working_directory)

steps:
# Upload single or directory of reports to blob storage
- bash: |
az login --service-principal --username $azure_client_id --password $azure_client_secret --tenant $azure_tenant_id
az account set -s $azure_subscription_id
az storage copy -s ${{ parameters.test_results_path }} -d https://${{ parameters.test_results_storage }}.blob.core.windows.net/${{ parameters.test_results_container }}/${{ parameters.test_results_blob_prefix }} --recursive
az logout --username $azure_client_id
displayName: 'Copy: ${{ parameters.test_tool_name }} Reports Blob Storge '
workingDirectory: ${{ parameters.working_directory }}
env:
azure_client_id: $(azure_client_id)
azure_client_secret: $(azure_client_secret)
azure_subscription_id: $(azure_subscription_id)
azure_tenant_id: $(azure_tenant_id)
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,10 @@ steps:
workingDirectory: ${{ parameters.working_directory }}
displayName: 'Generate ${{ parameters.test_tool_name }} HTML Report'
# Upload html report to blob storage
- bash: |
az login --service-principal --username $azure_client_id --password $azure_client_secret --tenant $azure_tenant_id
az account set -s $azure_subscription_id
az storage copy -s ${{ parameters.test_tool_name }}-xunit-test-results.html -d https://${{ parameters.test_results_storage }}.blob.core.windows.net/${{ parameters.test_results_container }}/${{ parameters.test_results_blob_prefix }} --recursive
az logout --username $azure_client_id
displayName: 'Copy: ${{ parameters.test_tool_name }} HTML Report Blob Storge '
workingDirectory: ${{ parameters.working_directory }}
env:
azure_client_id: $(azure_client_id)
azure_client_secret: $(azure_client_secret)
azure_subscription_id: $(azure_subscription_id)
azure_tenant_id: $(azure_tenant_id)
# Upload test results in pipeline, as artifacts, and html report to blob storage
- template: ../steps/test-publish-blob.yml
parameters:
test_tool_name: ${{ parameters.test_tool_name }}
working_directory: ${{ parameters.working_directory }}
test_results_storage: ${{ parameters.test_results_storage }}
test_results_path: ${{ parameters.test_results_path }}/${{ parameters.test_tool_name }}-xunit-test-results.html
14 changes: 7 additions & 7 deletions azDevOps/azure/templates/v2/steps/test-static-code-sonar.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
############################################################################################################
# desc: Performs static code analysis using code coverage from Jest unit tests and SonarCloud
# params: Working directory
# params: Working directory, container to run in
# return:
# pre-reqs: dependency installation
############################################################################################################

parameters:
workingDirectory: ""
working_directory: ""
target_container: ""

steps:
# SonarCloud Start
- bash: |
sonar-scanner -v
sonar-scanner
${{ parameters.target_container }} -v
${{ parameters.target_container }}
displayName: "Static Analysis: SonarScanner Run"
# TOD: remove this! all target/container definitions should be handled at a job/caller level
target:
container: sonar_scanner
container: ${{ parameters.target_container }}
env:
SONAR_HOST_URL: https://sonarcloud.io
SONAR_TOKEN: $SONAR_TOKEN
SONAR_PROJECT_KEY: $SONAR_PROJECT_KEY
SONAR_ORGANIZATION: $SONAR_ORGANIZATION
BUILD_NUMBER: $(Build.BuildNumber)
workingDirectory: ${{ parameters.workingDirectory }}
workingDirectory: ${{ parameters.working_directory }}

0 comments on commit f838bce

Please sign in to comment.