From 06faac8b5cb08cf838a39f2666ebf473f0f063ec Mon Sep 17 00:00:00 2001 From: Georgios Kalpakas Date: Thu, 3 Aug 2017 11:40:39 +0300 Subject: [PATCH] fix(aio): skip PWA test when redeploying non-public commit --- .../scripts-js/lib/upload-server/build-creator.ts | 3 ++- .../lib/verify-setup/upload-server.e2e.ts | 7 ++++--- .../test/upload-server/build-creator.spec.ts | 6 ++++-- .../dockerbuild/scripts-js/tslint.json | 2 +- .../docs/overview--http-status-codes.md | 7 ++++--- aio/scripts/deploy-preview.sh | 14 +++++++------- 6 files changed, 22 insertions(+), 17 deletions(-) diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/upload-server/build-creator.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/upload-server/build-creator.ts index 183bf9a196..cfb3ba616f 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/upload-server/build-creator.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/upload-server/build-creator.ts @@ -32,7 +32,8 @@ export class BuildCreator extends EventEmitter { then(() => Promise.all([this.exists(prDir), this.exists(shaDir)])). then(([prDirExisted, shaDirExisted]) => { if (shaDirExisted) { - throw new UploadError(409, `Request to overwrite existing directory: ${shaDir}`); + const publicOrNot = isPublic ? 'public' : 'non-public'; + throw new UploadError(409, `Request to overwrite existing ${publicOrNot} directory: ${shaDir}`); } dirToRemoveOnError = prDirExisted ? shaDir : prDir; diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/upload-server.e2e.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/upload-server.e2e.ts index 6191a495f4..002d93de3e 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/upload-server.e2e.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/lib/verify-setup/upload-server.e2e.ts @@ -110,6 +110,7 @@ describe('upload-server (on HTTP)', () => { const authorizationHeader2 = isPublic ? authorizationHeader : `--header "Authorization: ${c.BV_verify_verifiedNotTrusted}"`; const cmdPrefix = curl('', `${authorizationHeader2} ${xFileHeader}`); + const overwriteRe = RegExp(`^Request to overwrite existing ${isPublic ? 'public' : 'non-public'} directory`); it('should not overwrite existing builds', done => { @@ -120,7 +121,7 @@ describe('upload-server (on HTTP)', () => { expect(h.readBuildFile(pr, sha9, 'index.html', isPublic)).toBe('My content'); h.runCmd(`${cmdPrefix} http://${host}/create-build/${pr}/${sha9}`). - then(h.verifyResponse(409, /^Request to overwrite existing directory/)). + then(h.verifyResponse(409, overwriteRe)). then(() => expect(h.readBuildFile(pr, sha9, 'index.html', isPublic)).toBe('My content')). then(done); }); @@ -141,7 +142,7 @@ describe('upload-server (on HTTP)', () => { expect(h.readBuildFile(pr, sha9, 'index.html', isPublic)).toBe('My content'); h.runCmd(`${cmdPrefix} http://${host}/create-build/${pr}/${sha9Almost}`). - then(h.verifyResponse(409, /^Request to overwrite existing directory/)). + then(h.verifyResponse(409, overwriteRe)). then(() => expect(h.readBuildFile(pr, sha9, 'index.html', isPublic)).toBe('My content')). then(done); }); @@ -310,7 +311,7 @@ describe('upload-server (on HTTP)', () => { expect(h.buildExists(pr, sha0, isPublic)).toBe(false); uploadBuild(sha0). - then(h.verifyResponse(409, /^Request to overwrite existing directory/)). + then(h.verifyResponse(409, overwriteRe)). then(() => { checkPrVisibility(isPublic); expect(h.readBuildFile(pr, sha0, 'index.html', isPublic)).toContain(pr); diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/test/upload-server/build-creator.spec.ts b/aio/aio-builds-setup/dockerbuild/scripts-js/test/upload-server/build-creator.spec.ts index 6125205ba3..d5b1f91576 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/test/upload-server/build-creator.spec.ts +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/test/upload-server/build-creator.spec.ts @@ -153,7 +153,8 @@ describe('BuildCreator', () => { it('should abort and skip further operations if the build does already exist', done => { existsValues[shaDir] = true; bc.create(pr, sha, archive, isPublic).catch(err => { - expectToBeUploadError(err, 409, `Request to overwrite existing directory: ${shaDir}`); + const publicOrNot = isPublic ? 'public' : 'non-public'; + expectToBeUploadError(err, 409, `Request to overwrite existing ${publicOrNot} directory: ${shaDir}`); expect(shellMkdirSpy).not.toHaveBeenCalled(); expect(bcExtractArchiveSpy).not.toHaveBeenCalled(); expect(bcEmitSpy).not.toHaveBeenCalled(); @@ -169,7 +170,8 @@ describe('BuildCreator', () => { expect(bcExistsSpy(shaDir)).toBe(false); bc.create(pr, sha, archive, isPublic).catch(err => { - expectToBeUploadError(err, 409, `Request to overwrite existing directory: ${shaDir}`); + const publicOrNot = isPublic ? 'public' : 'non-public'; + expectToBeUploadError(err, 409, `Request to overwrite existing ${publicOrNot} directory: ${shaDir}`); expect(shellMkdirSpy).not.toHaveBeenCalled(); expect(bcExtractArchiveSpy).not.toHaveBeenCalled(); expect(bcEmitSpy).not.toHaveBeenCalled(); diff --git a/aio/aio-builds-setup/dockerbuild/scripts-js/tslint.json b/aio/aio-builds-setup/dockerbuild/scripts-js/tslint.json index d773f53668..59d3ff1d9f 100644 --- a/aio/aio-builds-setup/dockerbuild/scripts-js/tslint.json +++ b/aio/aio-builds-setup/dockerbuild/scripts-js/tslint.json @@ -6,7 +6,7 @@ "interface-name": [true, "never-prefix"], "max-classes-per-file": [true, 4], "no-consecutive-blank-lines": [true, 2], - "no-console": false, + "no-console": [false], "no-namespace": [true, "allow-declarations"], "no-string-literal": false, "quotemark": [true, "single"], diff --git a/aio/aio-builds-setup/docs/overview--http-status-codes.md b/aio/aio-builds-setup/docs/overview--http-status-codes.md index 54b06f66e8..1a041ffbcf 100644 --- a/aio/aio-builds-setup/docs/overview--http-status-codes.md +++ b/aio/aio-builds-setup/docs/overview--http-status-codes.md @@ -46,8 +46,8 @@ with a bried explanation of what they mean: Request method other than POST. - **409 (Conflict)**: - Request to overwrite existing directory (e.g. deploy existing build or change PR visibility when - the destination directory does already exist). + Request to overwrite existing (public or non-public) directory (e.g. deploy existing build or + change PR visibility when the destination directory does already exist). - **413 (Payload Too Large)**: Payload larger than size specified in `AIO_UPLOAD_MAX_SIZE`. @@ -71,7 +71,8 @@ with a bried explanation of what they mean: Request method other than POST. - **409 (Conflict)**: - Request to overwrite existing directory (i.e. directories for both visibilities exist). + Request to overwrite existing (public or non-public) directory (i.e. directories for both + visibilities exist). (Normally, this should not happen.) diff --git a/aio/scripts/deploy-preview.sh b/aio/scripts/deploy-preview.sh index 4afd49a5cf..e49bd99482 100755 --- a/aio/scripts/deploy-preview.sh +++ b/aio/scripts/deploy-preview.sh @@ -26,31 +26,31 @@ readonly relevantChangedFilesCount=$(git diff --name-only $TRAVIS_COMMIT_RANGE | fi # Build the app - if [ "$skipBuild" != "true" ]; then + if [[ "$skipBuild" != "true" ]]; then yarn build fi tar --create --gzip --directory "$INPUT_DIR" --file "$OUTPUT_FILE" . yarn payload-size # Deploy to staging - readonly httpCode=$( + readonly output=$( curl --include --location --request POST --silent --write-out "\nHTTP_CODE: %{http_code}\n" \ --header "Authorization: Token $NGBUILDS_IO_KEY" --data-binary "@$OUTPUT_FILE" "$UPLOAD_URL" \ | sed 's/\r\n/\n/' \ - | tee /dev/fd/3 \ - | tail -1 \ - | sed 's/HTTP_CODE: //' + | tee /dev/fd/3 ) + readonly isHidden=$([[ `echo $output | grep 'non-public'` ]] && echo "true" || echo "") + readonly httpCode=$(echo "$output" | tail -1 | sed 's/HTTP_CODE: //') # Exit with an error if the request failed. # (Ignore 409 failures, which mean trying to re-deploy for the same PR/SHA.) - if [ $httpCode -lt 200 ] || ([ $httpCode -ge 400 ] && [ $httpCode -ne 409 ]); then + if [[ $httpCode -lt 200 ]] || ([[ $httpCode -ge 400 ]] && [[ $httpCode -ne 409 ]]); then exit 1 fi # Run PWA-score tests (unless the deployment is not public yet; # i.e. it could not be automatically verified). - if [ $httpCode -ne 202 ]; then + if [[ $httpCode -ne 202 ]] && [[ "$isHidden" != "true" ]]; then yarn test-pwa-score -- "$DEPLOYED_URL" "$MIN_PWA_SCORE" fi )