From b204400bedf5de7fee6f3a8bafe077634644b597 Mon Sep 17 00:00:00 2001 From: Nick Ardecky <38665452+damntrecky@users.noreply.github.com> Date: Thu, 26 Dec 2019 13:07:54 -0800 Subject: [PATCH 01/20] Deploy action Add action to deploy to Google App Engine. --- .github/workflows/deploy-gae.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/deploy-gae.yml diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml new file mode 100644 index 0000000..3d1e9bc --- /dev/null +++ b/.github/workflows/deploy-gae.yml @@ -0,0 +1,39 @@ +# overall CI pipeline name +name: Deploy to GAE + +# only run on master and stage branches +on: + push: + branches: + - master + - stage + +# Environment variables available to all jobs and steps in this workflow +env: + CI: true + +# jobs are the different pipelines +jobs: + build: + + runs-on: ubuntu-latest + name: Publish and Deploy + # define all the steps in the "build" stage + steps: + # deploy to GAE step + - name: Google Cloud Platform (GCP) CLI - gcloud + uses: actions-hub/gcloud@272.0.0 + with: + # Project id + PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} + APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} + + # Configure where to deploy export server + - name: Deploy Stage + if: github.ref == 'stage' + run: | + gcloud app deploy --version stage + - name: Deploy Production + if: github.ref == 'master' + run: | + gcloud app deploy From 9a89bef063b96d4d0e1cbd96df3e31ac5088920e Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 13:37:24 -0800 Subject: [PATCH 02/20] Update node build matrix --- .github/workflows/build-test.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 13300ce..eca0fe8 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -11,8 +11,6 @@ on: # Environment variables available to all jobs and steps in this workflow env: CI: true - PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} - APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} # jobs are the different pipelines jobs: @@ -22,7 +20,7 @@ jobs: strategy: matrix: - node-version: [10.x, 12.x] + node-version: [12.x] # define all the steps in the "build" stage steps: From e012ccac9d64c9e5b8c61da2c2d67e5ec5b36184 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 13:40:16 -0800 Subject: [PATCH 03/20] Add env variable globally --- .github/workflows/build-test.yml | 2 +- .github/workflows/deploy-gae.yml | 13 +++++-------- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index eca0fe8..32c4284 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -20,7 +20,7 @@ jobs: strategy: matrix: - node-version: [12.x] + node-version: [10.x] # define all the steps in the "build" stage steps: diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 3d1e9bc..58b3548 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -10,7 +10,8 @@ on: # Environment variables available to all jobs and steps in this workflow env: - CI: true + PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} + APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} # jobs are the different pipelines jobs: @@ -18,16 +19,12 @@ jobs: runs-on: ubuntu-latest name: Publish and Deploy + # define all the steps in the "build" stage steps: # deploy to GAE step - - name: Google Cloud Platform (GCP) CLI - gcloud - uses: actions-hub/gcloud@272.0.0 - with: - # Project id - PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} - APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} - + - uses: actions-hub/gcloud@272.0.0 + # Configure where to deploy export server - name: Deploy Stage if: github.ref == 'stage' From 8253ca1124c3be8eedc1e54adb3a3195e0b4eae7 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 13:45:54 -0800 Subject: [PATCH 04/20] Update if statements --- .github/workflows/deploy-gae.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 58b3548..0433b88 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -23,14 +23,14 @@ jobs: # define all the steps in the "build" stage steps: # deploy to GAE step - - uses: actions-hub/gcloud@272.0.0 + - uses: actions-hub/gcloud@master # Configure where to deploy export server - name: Deploy Stage - if: github.ref == 'stage' + if: $GITHUB_REF == 'stage' run: | gcloud app deploy --version stage - name: Deploy Production - if: github.ref == 'master' + if: $GITHUB_REF == 'master' run: | gcloud app deploy From 2a0653ff7ecac203d9a2785845c01019c9106b78 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 14:26:38 -0800 Subject: [PATCH 05/20] [Bugfix] Fix broken yml file --- .github/workflows/deploy-gae.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 0433b88..a3e58f3 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -19,18 +19,18 @@ jobs: runs-on: ubuntu-latest name: Publish and Deploy - # define all the steps in the "build" stage steps: # deploy to GAE step - - uses: actions-hub/gcloud@master - + - name: Google Cloud Platform (GCP) CLI - gcloud + uses: actions-hub/gcloud@272.0.0 + # Configure where to deploy export server - name: Deploy Stage if: $GITHUB_REF == 'stage' run: | gcloud app deploy --version stage - name: Deploy Production - if: $GITHUB_REF == 'master' + if: $GITHUB_REF == 'master' run: | - gcloud app deploy + gcloud app deploy \ No newline at end of file From 4b4d32e1a1a9c6fb2258979fd24b1b3812149614 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 14:30:31 -0800 Subject: [PATCH 06/20] [bugfix] Update conditional path for branches --- .github/workflows/deploy-gae.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index a3e58f3..1440bca 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -27,10 +27,10 @@ jobs: # Configure where to deploy export server - name: Deploy Stage - if: $GITHUB_REF == 'stage' + if: github.ref == 'refs/heads/stage' run: | gcloud app deploy --version stage - name: Deploy Production - if: $GITHUB_REF == 'master' + if: github.ref == 'refs/heads/master' run: | gcloud app deploy \ No newline at end of file From dcf061d19869e561f96b80032d392dd00564fa37 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 14:33:26 -0800 Subject: [PATCH 07/20] [Bugfix] Add build/login to each deploy step --- .github/workflows/deploy-gae.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 1440bca..8a3df8a 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -21,16 +21,14 @@ jobs: name: Publish and Deploy # define all the steps in the "build" stage steps: - # deploy to GAE step - - name: Google Cloud Platform (GCP) CLI - gcloud - uses: actions-hub/gcloud@272.0.0 - # Configure where to deploy export server - name: Deploy Stage + uses: actions-hub/gcloud@master if: github.ref == 'refs/heads/stage' run: | gcloud app deploy --version stage - name: Deploy Production + uses: actions-hub/gcloud@master if: github.ref == 'refs/heads/master' run: | gcloud app deploy \ No newline at end of file From b618233f60d9e1a4920fc21413142c00b6e18623 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 14:40:20 -0800 Subject: [PATCH 08/20] [bugfix] Add codecheckout action --- .github/workflows/deploy-gae.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 8a3df8a..9d62df8 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -21,14 +21,16 @@ jobs: name: Publish and Deploy # define all the steps in the "build" stage steps: + # This step checks out a copy of your repository. + - uses: actions/checkout@v1 + # This step checks out and logs in to gcloud + - uses: actions-hub/gcloud@master # Configure where to deploy export server - name: Deploy Stage - uses: actions-hub/gcloud@master if: github.ref == 'refs/heads/stage' run: | gcloud app deploy --version stage - name: Deploy Production - uses: actions-hub/gcloud@master if: github.ref == 'refs/heads/master' run: | gcloud app deploy \ No newline at end of file From b4e782f57dd62009483965868b913bf663f44b84 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 14:58:26 -0800 Subject: [PATCH 09/20] Add args to gcloud step --- .github/workflows/deploy-gae.yml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 9d62df8..79d857e 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -9,9 +9,9 @@ on: - stage # Environment variables available to all jobs and steps in this workflow -env: - PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} - APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} +# env: +# PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} +# APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} # jobs are the different pipelines jobs: @@ -24,7 +24,13 @@ jobs: # This step checks out a copy of your repository. - uses: actions/checkout@v1 # This step checks out and logs in to gcloud - - uses: actions-hub/gcloud@master + - name: test + uses: actions-hub/gcloud@master + with: + # Project id + PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} + # GCP authorization credentials + APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} # Configure where to deploy export server - name: Deploy Stage if: github.ref == 'refs/heads/stage' From 763024b7e1140db8b503bf7a04414f4f1bda9cd5 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 15:01:29 -0800 Subject: [PATCH 10/20] Try adding info to args and other infos to .env --- .github/workflows/deploy-gae.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 79d857e..9d6ef9f 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -26,11 +26,13 @@ jobs: # This step checks out and logs in to gcloud - name: test uses: actions-hub/gcloud@master - with: + env: # Project id PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} # GCP authorization credentials APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} + with: + args: info # Configure where to deploy export server - name: Deploy Stage if: github.ref == 'refs/heads/stage' From 0ab7fa2b116aa2e13053251a7bc838c681f7e352 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 15:06:00 -0800 Subject: [PATCH 11/20] Try to deploy to stage --- .github/workflows/deploy-gae.yml | 7 ++++--- app-stage.yaml | 6 ++++++ 2 files changed, 10 insertions(+), 3 deletions(-) create mode 100644 app-stage.yaml diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 9d6ef9f..4f53d76 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -24,15 +24,16 @@ jobs: # This step checks out a copy of your repository. - uses: actions/checkout@v1 # This step checks out and logs in to gcloud - - name: test - uses: actions-hub/gcloud@master + - uses: actions-hub/gcloud@master env: # Project id PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} # GCP authorization credentials APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} + # define to use gcloud over gsutil + CLI: gcloud with: - args: info + args: app deploy app-stage.yaml # Configure where to deploy export server - name: Deploy Stage if: github.ref == 'refs/heads/stage' diff --git a/app-stage.yaml b/app-stage.yaml new file mode 100644 index 0000000..8406ae6 --- /dev/null +++ b/app-stage.yaml @@ -0,0 +1,6 @@ +runtime: nodejs10 +instance_class: F4_1G +service: default +env_variables: + NODE_ENV: stage +version: stage From 7d1e19770126f90ca3e44b3ada564b9b0715198b Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 15:08:19 -0800 Subject: [PATCH 12/20] Try hardcoding project id --- .github/workflows/deploy-gae.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 4f53d76..d2d65e4 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -27,7 +27,7 @@ jobs: - uses: actions-hub/gcloud@master env: # Project id - PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} + PROJECT_ID: export-server # GCP authorization credentials APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} # define to use gcloud over gsutil From 7ebe32e2e53558a8fb7492e732479539bdda7cdc Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 15:37:57 -0800 Subject: [PATCH 13/20] Test CLI deploy --- .github/workflows/deploy-gae.yml | 33 ++++++++++++++------------------ app-stage.yaml | 1 - 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index d2d65e4..66d5f03 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -9,10 +9,14 @@ on: - stage # Environment variables available to all jobs and steps in this workflow -# env: -# PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} -# APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} - +env: + # Project id + PROJECT_ID: export-server + # GCP authorization credentials + APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} + # define to use gcloud over gsutil + CLI: gcloud + # jobs are the different pipelines jobs: build: @@ -24,22 +28,13 @@ jobs: # This step checks out a copy of your repository. - uses: actions/checkout@v1 # This step checks out and logs in to gcloud - - uses: actions-hub/gcloud@master - env: - # Project id - PROJECT_ID: export-server - # GCP authorization credentials - APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} - # define to use gcloud over gsutil - CLI: gcloud - with: - args: app deploy app-stage.yaml - # Configure where to deploy export server - name: Deploy Stage if: github.ref == 'refs/heads/stage' - run: | - gcloud app deploy --version stage + uses: actions-hub/gcloud@master + with: + args: app deploy app-stage.yaml --version test - name: Deploy Production if: github.ref == 'refs/heads/master' - run: | - gcloud app deploy \ No newline at end of file + uses: actions-hub/gcloud@master + with: + args: app deploy app.yaml --version master \ No newline at end of file diff --git a/app-stage.yaml b/app-stage.yaml index 8406ae6..7e9c4b0 100644 --- a/app-stage.yaml +++ b/app-stage.yaml @@ -3,4 +3,3 @@ instance_class: F4_1G service: default env_variables: NODE_ENV: stage -version: stage From 707ab59b1fa48622260df959d56fb46801c7cb77 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Thu, 26 Dec 2019 17:06:50 -0800 Subject: [PATCH 14/20] Add base unit tests as async/await --- .gcloudignore | 8 ++- .github/workflows/build-test.yml | 13 ++-- .github/workflows/deploy-gae.yml | 7 ++- app-stage.yaml | 4 ++ app.yaml | 4 ++ test/base-test.spec.js | 102 ++++++++++++++----------------- 6 files changed, 72 insertions(+), 66 deletions(-) diff --git a/.gcloudignore b/.gcloudignore index a3f0c76..9ac9672 100644 --- a/.gcloudignore +++ b/.gcloudignore @@ -14,4 +14,10 @@ .gitignore # Node.js dependencies: -node_modules/ \ No newline at end of file +node_modules/ + +# ignore test directory +test/ + +# ignore github actions yaml files +.github/ \ No newline at end of file diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 32c4284..3182425 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -1,12 +1,8 @@ # overall CI pipeline name name: Build and test export server -# only run on master and stage branches -on: - push: - branches: - - master - - stage +# Run tests on EVERY branch and push +on: [push] # Environment variables available to all jobs and steps in this workflow env: @@ -24,16 +20,15 @@ jobs: # define all the steps in the "build" stage steps: - # use the checkout action + # use the checkout action to get repository contents - uses: actions/checkout@v1 - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} # Try to build and run tests again export server - - name: npm install, build, and test + - name: Run Tests run: | npm ci - npm run build --if-present npm test diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index 66d5f03..b82d314 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -21,8 +21,10 @@ env: jobs: build: + # Define the OS and name runs-on: ubuntu-latest name: Publish and Deploy + # define all the steps in the "build" stage steps: # This step checks out a copy of your repository. @@ -32,9 +34,12 @@ jobs: if: github.ref == 'refs/heads/stage' uses: actions-hub/gcloud@master with: - args: app deploy app-stage.yaml --version test + # This step deploys + args: app deploy app-stage.yaml --version stage + # This step checks out and logs in to gcloud - name: Deploy Production if: github.ref == 'refs/heads/master' uses: actions-hub/gcloud@master with: + # This step deploys to production args: app deploy app.yaml --version master \ No newline at end of file diff --git a/app-stage.yaml b/app-stage.yaml index 7e9c4b0..3c756d9 100644 --- a/app-stage.yaml +++ b/app-stage.yaml @@ -3,3 +3,7 @@ instance_class: F4_1G service: default env_variables: NODE_ENV: stage +# prevents all traffic from splitting immediately +# sends a "warmup" request to new version +inbound_services: +- warmup \ No newline at end of file diff --git a/app.yaml b/app.yaml index 821443b..af35182 100644 --- a/app.yaml +++ b/app.yaml @@ -3,3 +3,7 @@ instance_class: F4_1G service: default env_variables: NODE_ENV: production +# prevents all traffic from splitting immediately +# sends a "warmup" request to new version +inbound_services: +- warmup \ No newline at end of file diff --git a/test/base-test.spec.js b/test/base-test.spec.js index cee761c..2e2e163 100644 --- a/test/base-test.spec.js +++ b/test/base-test.spec.js @@ -10,38 +10,32 @@ describe(`Server Route Test's`, function() { // test the response status's // --------------------------------- - describe.skip('Get Base Routes', function() { - it(' Post / Url is OK', function(done) { - axios.post('http://localhost:8080/') - .then(function (response) { - // console.log(response); - expect(response.statusText).to.equal('OK'); - expect(response.status).to.equal(200); - done(); - }) - .catch(function (error) { - console.log(error); - }); + describe('Get Base Routes', function() { + it(' Post / Url is OK', async function() { + try { + let response = await axios.post('http://localhost:8080/'); + expect(response.statusText).to.equal('OK'); + expect(response.status).to.equal(200); + } catch(e) { + if (process.env.DEBUG) console.error(e); + } }); - - it('Post /json Url is OK', function(done) { - axios.post('http://localhost:8080/json') - .then(function (response) { - // console.log(response); - expect(response.statusText).to.equal('OK'); - expect(response.status).to.equal(200); - done(); - }) - .catch(function (error) { - console.log(error); - }); + + it('Post /json Url is OK', async function() { + try { + let response = await axios.post('http://localhost:8080/json'); + expect(response.statusText).to.equal('OK'); + expect(response.status).to.equal(200); + } catch(e) { + if (process.env.DEBUG) console.error(e); + } }); }); // test the output for PNG creation // --------------------------------- - describe('PNG Creation', function() { - it.skip(' Post / PNG output is OK', function(done) { + describe.skip('PNG Creation', function() { + it.skip(' Post / PNG output is OK', async function(done) { axios.post('http://localhost:8080/') .then(function (response) { // console.log(response); @@ -54,37 +48,35 @@ describe(`Server Route Test's`, function() { }); }); - it('Post /json PNG output is exact match', function(done) { - let chartConfig = require('./configs/plain-chart.js'); + it.skip('Post /json PNG output is exact match', async function(done) { + try { + let chartConfig = require('./configs/plain-chart.js'); - axios({ - method: 'post', - url: 'http://localhost:8080/json', - responseType: 'stream', - data: { - chartConfig, - t: 'png', - height: '500px', - width: '500px' - } - }) - .then(async function (response) { - // pipe results into dist folder - response.data.pipe(fs.createWriteStream(`${__dirname}/dist/test1.png`)); - // check results again reference image and pipe to dist/diff - let blinkDiffResults = await utils.compareScreenshotsBlinkDiff( - `${__dirname}/dist/test1.png`, // file 1 - `${__dirname}/references/test1-500x500.png`, // file 2 - `${__dirname}/dist/diff/test1.png`, // output image path - ); - // verify pass's threshold and the the differences are zero (COULD Loosen this restriction) - expect(blinkDiffResults.pass).to.equal(true); - expect(blinkDiffResults.differences).to.equal(0); - done(); + let response = await axios({ + method: 'post', + url: 'http://localhost:8080/json', + responseType: 'stream', + data: { + chartConfig, + t: 'png', + height: '500px', + width: '500px' + } }) - .catch(function (error) { - console.log(error); - }); + // pipe results into dist folder + response.data.pipe(fs.createWriteStream(`${__dirname}/dist/test1.png`)); + // check results again reference image and pipe to dist/diff + let blinkDiffResults = await utils.compareScreenshotsBlinkDiff( + `${__dirname}/dist/test1.png`, // file 1 + `${__dirname}/references/test1-500x500.png`, // file 2 + `${__dirname}/dist/diff/test1.png`, // output image path + ); + // verify pass's threshold and the the differences are zero (COULD Loosen this restriction) + expect(blinkDiffResults.pass).to.equal(true); + expect(blinkDiffResults.differences).to.equal(0); + } catch(e) { + console.error(e); + } }); }); }); From 58aef59916321dcb639acdf9e2a3dafb793355ed Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 27 Dec 2019 08:59:31 -0800 Subject: [PATCH 15/20] Run test suite again --- server.js | 124 +++++++++++++++++------------------------ test/base-test.spec.js | 24 +++----- 2 files changed, 59 insertions(+), 89 deletions(-) diff --git a/server.js b/server.js index 7106109..8afff5e 100644 --- a/server.js +++ b/server.js @@ -141,45 +141,35 @@ app.post('/', async (req, res) => { // }; // }); - // read file asynchronously in case it never returns - // fs.readFile(readFilePath, (err, imageFile) => { - - // catch err - // if (err) { - // console.error(err); - // return res.status(500).send('Issue Reading File From Server'); - // } - - // request headers - let rHeaders = { - 'Content-Type': '', - // 'Content-Length': '', - // 'Content-Disposition': `attachment; filename="${fileName}.${imgType}"` - }; - - // set appropriate mime/types - switch (imgType) { - case 'svg': - rHeaders['Content-Type'] = 'image/svg+xml'; - // rHeaders['Content-Length'] = svgData.length; - break; - case 'pdf': - rHeaders['Content-Type'] = 'application/pdf'; - // rHeaders['Content-Length'] = imageFile.length; - break; - case 'png': - case 'jpeg': - default: - rHeaders['Content-Type'] = `image/${imgType}`; - // rHeaders['Content-Length'] = imageFile.length; - } + // request headers + let rHeaders = { + 'Content-Type': '', + // 'Content-Length': '', + // 'Content-Disposition': `attachment; filename="${fileName}.${imgType}"` + }; + + // set appropriate mime/types + switch (imgType) { + case 'svg': + rHeaders['Content-Type'] = 'image/svg+xml'; + // rHeaders['Content-Length'] = svgData.length; + break; + case 'pdf': + rHeaders['Content-Type'] = 'application/pdf'; + // rHeaders['Content-Length'] = imageFile.length; + break; + case 'png': + case 'jpeg': + default: + rHeaders['Content-Type'] = `image/${imgType}`; + // rHeaders['Content-Length'] = imageFile.length; + } - // write headers - res.writeHead(200, rHeaders); + // write headers + res.writeHead(200, rHeaders); - // end the buffer and send - return res.end(tmpBuffer); - // }); + // end the buffer and send + return res.end(tmpBuffer); } catch(e) { console.error(e); @@ -299,41 +289,31 @@ app.post('/json', async (req, res) => { // }; // }); - // read file asynchronously in case it never returns - // fs.readFile(readFilePath, (err, imageFile) => { - - // catch err - // if (err) { - // console.error(err); - // return res.status(500).send('Issue Reading File From Server'); - // } - - // request headers - let rHeaders = { - 'Content-Type': '', - // 'Content-Length': '', - // 'Content-Disposition': `attachment; filename="${fileName}.${imgType}"` - }; - - // set appropriate mime/types - switch (imgType) { - case 'pdf': - rHeaders['Content-Type'] = 'application/pdf'; - // rHeaders['Content-Length'] = imageFile.length; - break; - case 'png': - case 'jpeg': - default: - rHeaders['Content-Type'] = `image/${imgType}`; - // rHeaders['Content-Length'] = imageFile.length; - } - - // write headers - res.writeHead(200, rHeaders); - - // end the buffer and send - return res.end(tmpBuffer); - // }); + // request headers + let rHeaders = { + 'Content-Type': '', + // 'Content-Length': '', + 'Content-Disposition': `attachment; filename="${fileName}.${imgType}"` + }; + + // set appropriate mime/types + switch (imgType) { + case 'pdf': + rHeaders['Content-Type'] = 'application/pdf'; + // rHeaders['Content-Length'] = imageFile.length; + break; + case 'png': + case 'jpeg': + default: + rHeaders['Content-Type'] = `image/${imgType}`; + // rHeaders['Content-Length'] = imageFile.length; + } + + // write headers + res.writeHead(200, rHeaders); + + // end the buffer and send + return res.end(tmpBuffer); } }); diff --git a/test/base-test.spec.js b/test/base-test.spec.js index 2e2e163..a629acc 100644 --- a/test/base-test.spec.js +++ b/test/base-test.spec.js @@ -34,21 +34,11 @@ describe(`Server Route Test's`, function() { // test the output for PNG creation // --------------------------------- - describe.skip('PNG Creation', function() { - it.skip(' Post / PNG output is OK', async function(done) { - axios.post('http://localhost:8080/') - .then(function (response) { - // console.log(response); - expect(response.statusText).to.equal('OK'); - expect(response.status).to.equal(200); - done(); - }) - .catch(function (error) { - console.log(error); - }); - }); + describe('PNG Creation', function() { + - it.skip('Post /json PNG output is exact match', async function(done) { + // test to make sure the image matches + it('Post /json PNG output is exact match', async function() { try { let chartConfig = require('./configs/plain-chart.js'); @@ -62,9 +52,9 @@ describe(`Server Route Test's`, function() { height: '500px', width: '500px' } - }) + }); // pipe results into dist folder - response.data.pipe(fs.createWriteStream(`${__dirname}/dist/test1.png`)); + response.data.pipe(await fs.createWriteStream(`${__dirname}/dist/test1.png`)); // check results again reference image and pipe to dist/diff let blinkDiffResults = await utils.compareScreenshotsBlinkDiff( `${__dirname}/dist/test1.png`, // file 1 @@ -75,7 +65,7 @@ describe(`Server Route Test's`, function() { expect(blinkDiffResults.pass).to.equal(true); expect(blinkDiffResults.differences).to.equal(0); } catch(e) { - console.error(e); + if (process.env.DEBUG) console.error(e); } }); }); From 9e707c3d410d8ba77a0e32e91f46555d02dc1458 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 27 Dec 2019 09:06:16 -0800 Subject: [PATCH 16/20] Try running tests on specific node version --- .github/workflows/build-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index 3182425..fb791f4 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -16,7 +16,7 @@ jobs: strategy: matrix: - node-version: [10.x] + node-version: [10.14.2] # define all the steps in the "build" stage steps: From 137c3b4e4d039c188c9a758ad5559fac69eafe7c Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 27 Dec 2019 09:23:11 -0800 Subject: [PATCH 17/20] Try pushing version in yaml --- app-stage.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/app-stage.yaml b/app-stage.yaml index 3c756d9..2bd95f0 100644 --- a/app-stage.yaml +++ b/app-stage.yaml @@ -1,6 +1,7 @@ runtime: nodejs10 instance_class: F4_1G service: default +version: v2 env_variables: NODE_ENV: stage # prevents all traffic from splitting immediately From e82e4ae961f4f6808422ed16306dd1fa2542c226 Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 27 Dec 2019 10:05:17 -0800 Subject: [PATCH 18/20] Test --- .github/workflows/deploy-gae.yml | 5 +++-- app-stage.yaml | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index b82d314..b0a12a7 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -34,8 +34,9 @@ jobs: if: github.ref == 'refs/heads/stage' uses: actions-hub/gcloud@master with: - # This step deploys - args: app deploy app-stage.yaml --version stage + # This step deploys to stage and the --no-promote flag prevents + # traffic from being split to this version + args: app deploy app-stage.yaml --version stage # This step checks out and logs in to gcloud - name: Deploy Production if: github.ref == 'refs/heads/master' diff --git a/app-stage.yaml b/app-stage.yaml index 2bd95f0..3c756d9 100644 --- a/app-stage.yaml +++ b/app-stage.yaml @@ -1,7 +1,6 @@ runtime: nodejs10 instance_class: F4_1G service: default -version: v2 env_variables: NODE_ENV: stage # prevents all traffic from splitting immediately From 8901d63fe81900b6dfa8fd7ac6a1bb5121a059da Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 27 Dec 2019 15:07:38 -0800 Subject: [PATCH 19/20] Polish CI process variables --- .github/workflows/build-test.yml | 4 +++- .github/workflows/deploy-gae.yml | 4 ++-- test/base-test.spec.js | 1 + 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-test.yml b/.github/workflows/build-test.yml index fb791f4..e45a88e 100644 --- a/.github/workflows/build-test.yml +++ b/.github/workflows/build-test.yml @@ -22,13 +22,15 @@ jobs: steps: # use the checkout action to get repository contents - uses: actions/checkout@v1 + - name: Use Node.js ${{ matrix.node-version }} uses: actions/setup-node@v1 with: node-version: ${{ matrix.node-version }} + # Try to build and run tests again export server - name: Run Tests run: | - npm ci + npm ci npm test diff --git a/.github/workflows/deploy-gae.yml b/.github/workflows/deploy-gae.yml index b0a12a7..681343f 100644 --- a/.github/workflows/deploy-gae.yml +++ b/.github/workflows/deploy-gae.yml @@ -11,7 +11,7 @@ on: # Environment variables available to all jobs and steps in this workflow env: # Project id - PROJECT_ID: export-server + PROJECT_ID: ${{secrets.GCLOUD_PROJECT_ID}} # GCP authorization credentials APPLICATION_CREDENTIALS: ${{secrets.GOOGLE_APPLICATION_CREDENTIALS}} # define to use gcloud over gsutil @@ -36,7 +36,7 @@ jobs: with: # This step deploys to stage and the --no-promote flag prevents # traffic from being split to this version - args: app deploy app-stage.yaml --version stage + args: app deploy app-stage.yaml --version stage --no-promote # This step checks out and logs in to gcloud - name: Deploy Production if: github.ref == 'refs/heads/master' diff --git a/test/base-test.spec.js b/test/base-test.spec.js index a629acc..15ec9b7 100644 --- a/test/base-test.spec.js +++ b/test/base-test.spec.js @@ -3,6 +3,7 @@ const axios = require('axios'); const fs = require('fs'); describe(`Server Route Test's`, function() { + // before(function(done) { // // Waits for quickbooks to initialize // done(); From 87dbd31f98efe5fb551c1099c11a76e6086a62bf Mon Sep 17 00:00:00 2001 From: Nick Ardecky Date: Fri, 27 Dec 2019 16:09:37 -0800 Subject: [PATCH 20/20] Cleanup repository --- .gitlab-ci.yaml | 44 -------------------------------------------- test.js | 1 - 2 files changed, 45 deletions(-) delete mode 100644 .gitlab-ci.yaml delete mode 100644 test.js diff --git a/.gitlab-ci.yaml b/.gitlab-ci.yaml deleted file mode 100644 index 6c34cab..0000000 --- a/.gitlab-ci.yaml +++ /dev/null @@ -1,44 +0,0 @@ -# define docker image to use -image: devillex/docker-firebase:slim - -# define what to cache between stages AND pipelines -# this is a shortcut for passing node_modules around -cache: - paths: - - node_modules/ - -before_script: - # Path to NVM install location - - export NVM_DIR="$HOME/.nvm" - - . ${NVM_DIR}/nvm.sh - - gitlab-runner --version - # Install dependent node version via NVM - - nvm --version - - nvm install 10.14 - - node --version - -# define the stages of our pipeline -stages: - - test - - deployment - -###################################################### -### COMMANDS ALWAYS RUN -###################################################### - -## run unit tests -test:unit: - stage: test - script: - - npm install - - npm run test - allow_failure: true - -# deploy:stage: -# stage: deployment -# script: -# - npm install -# - npm run test -# allow_failure: true -# dependencies: -# - test:unit diff --git a/test.js b/test.js deleted file mode 100644 index 1a9b465..0000000 --- a/test.js +++ /dev/null @@ -1 +0,0 @@ -// all tests rendered from gallery at width 725 and height 500