From 88418aae308008eda24476327576a31524cc5313 Mon Sep 17 00:00:00 2001 From: Utsav Pandey Date: Tue, 26 May 2020 11:05:01 -0700 Subject: [PATCH 1/4] Update azure-pipelines.yml for Azure Pipelines --- azure-pipelines.yml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index beed15dfb..d726a76bc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -31,15 +31,15 @@ jobs: - script: npm run test-staging && node helpers/integration-tests/index.js displayName: 'Analyze staging with webhint' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - - bash: | - az login --service-principal -u $AZURE_SERVICE_PRINCIPAL -p $AZURE_SERVICE_PRINCIPAL_PASSWORD --tenant $AZURE_TENANT - az webapp deployment slot swap -g webhint-web -n sonarwhal --slot staging + - task: AzureAppServiceManage@0 displayName: 'Swap into production' condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - env: - AZURE_SERVICE_PRINCIPAL: $(AZURE_SERVICE_PRINCIPAL) - AZURE_SERVICE_PRINCIPAL_PASSWORD: $(AZURE_SERVICE_PRINCIPAL_PASSWORD) - AZURE_TENANT: $(AZURE_TENANT) + inputs: + azureSubscription: 'webhint-web' + Action: 'Swap Slots' + WebAppName: 'sonarwhal' + ResourceGroupName: 'webhint-web' + SourceSlot: 'staging' - bash: | curl https://www.google.com/ping?sitemap=https://webhint.io/sitemap.xml curl https://www.bing.com/ping?sitemap=https://webhint.io/sitemap.xml From 4356f9293deb955e241b6fbb8912c3e887eb5dad Mon Sep 17 00:00:00 2001 From: Utsav Pandey Date: Tue, 26 May 2020 11:08:10 -0700 Subject: [PATCH 2/4] Update azure-pipelines.yml for Azure Pipelines Disabling conditions to validate changes --- azure-pipelines.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index d726a76bc..2e0b30a9b 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -20,7 +20,7 @@ jobs: displayName: 'Test' - script: ./helpers/update-site.sh displayName: 'Deploy' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) env: GIT_USER_EMAIL: $(GIT_USER_EMAIL) GIT_USER_NAME: $(GIT_USER_NAME) @@ -30,10 +30,10 @@ jobs: BRANCH: variables['Build.SourceBranch'] - script: npm run test-staging && node helpers/integration-tests/index.js displayName: 'Analyze staging with webhint' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - task: AzureAppServiceManage@0 displayName: 'Swap into production' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + #condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: azureSubscription: 'webhint-web' Action: 'Swap Slots' @@ -44,7 +44,7 @@ jobs: curl https://www.google.com/ping?sitemap=https://webhint.io/sitemap.xml curl https://www.bing.com/ping?sitemap=https://webhint.io/sitemap.xml displayName: 'Update sitemaps' - condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - job: 'Algolia' pool: From f9e4f7725f6e850c14630a9e0994d364f0690c71 Mon Sep 17 00:00:00 2001 From: utsavized Date: Tue, 26 May 2020 13:12:04 -0700 Subject: [PATCH 3/4] Add basic exponential backoff to failing puppeteer integration tests --- helpers/integration-tests/index.js | 4 ++-- helpers/integration-tests/scanner.js | 2 +- helpers/integration-tests/staticUrls.js | 23 ++++++++++++++++++----- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/helpers/integration-tests/index.js b/helpers/integration-tests/index.js index 71848292d..afb2c052f 100644 --- a/helpers/integration-tests/index.js +++ b/helpers/integration-tests/index.js @@ -8,9 +8,9 @@ const runIntegrationTests = async () => { try { for (const test of [runStaticTests, runScannerTest]) { - const errorFound = await test(); + const success = await test(); - if (errorFound) { + if (!success) { error = true; } } diff --git a/helpers/integration-tests/scanner.js b/helpers/integration-tests/scanner.js index 4a2612c12..5c0a10225 100644 --- a/helpers/integration-tests/scanner.js +++ b/helpers/integration-tests/scanner.js @@ -22,7 +22,7 @@ const runScannerTest = async () => { }! => Status: ${response.status()}` ); - return response.status() !== 200; + return response.status() === 200; } catch (error) { console.error('🚨 Something went wrong while executing Puppeteer: ', error); await browser.close(); diff --git a/helpers/integration-tests/staticUrls.js b/helpers/integration-tests/staticUrls.js index 1f574ce66..9067652f4 100644 --- a/helpers/integration-tests/staticUrls.js +++ b/helpers/integration-tests/staticUrls.js @@ -7,6 +7,13 @@ const staticURLsToVerify = [ 'https://sonarwhal-staging.azurewebsites.net/docs/user-guide/hints/' ]; +const backOffTime = 5000; +const maxRetries = 3; + +const delay = (ms) => { + return new Promise(resolve => setTimeout(resolve, ms)); +}; + const runPuppeteer = async (url) => { const browser = await puppeteer.launch(); @@ -32,17 +39,23 @@ const runPuppeteer = async (url) => { }; const runStaticTests = async () => { - let errorFound = false; + let success = true; + let retryCount = 0; + let resultStatus = null; for (const url of staticURLsToVerify) { - const resultStatus = await runPuppeteer(url); + resultStatus = await runPuppeteer(url); - if (resultStatus !== 200) { - errorFound = true; + while(resultStatus !== 200 && retryCount < maxRetries) { + console.log('Test failed, retrying... Attempt #' + (++retryCount)); + await delay(backOffTime * retryCount); + resultStatus = await runPuppeteer(url); } + + success = success && resultStatus === 200; } - return errorFound; + return success; }; module.exports = { runStaticTests }; From a513b736e34f3eb2f88788a2d7003d9feaec419a Mon Sep 17 00:00:00 2001 From: utsavized Date: Tue, 26 May 2020 13:26:41 -0700 Subject: [PATCH 4/4] Uncomment conditionals that were commented out to validate build --- azure-pipelines.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 2e0b30a9b..d726a76bc 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -20,7 +20,7 @@ jobs: displayName: 'Test' - script: ./helpers/update-site.sh displayName: 'Deploy' - # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) env: GIT_USER_EMAIL: $(GIT_USER_EMAIL) GIT_USER_NAME: $(GIT_USER_NAME) @@ -30,10 +30,10 @@ jobs: BRANCH: variables['Build.SourceBranch'] - script: npm run test-staging && node helpers/integration-tests/index.js displayName: 'Analyze staging with webhint' - # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - task: AzureAppServiceManage@0 displayName: 'Swap into production' - #condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) inputs: azureSubscription: 'webhint-web' Action: 'Swap Slots' @@ -44,7 +44,7 @@ jobs: curl https://www.google.com/ping?sitemap=https://webhint.io/sitemap.xml curl https://www.bing.com/ping?sitemap=https://webhint.io/sitemap.xml displayName: 'Update sitemaps' - # condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) + condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master')) - job: 'Algolia' pool: