From 344fbcee5583aa3c535c3489e17a1c92b4aa296b Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:03:53 +0100 Subject: [PATCH 01/29] I'm not sure if this will work, time to test --- .github/workflows/main.yml | 27 +++++++++++++++++++++++++++ .travis.yml | 14 -------------- 2 files changed, 27 insertions(+), 14 deletions(-) create mode 100644 .github/workflows/main.yml delete mode 100644 .travis.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 00000000..d5a5c2aa --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +name: CI + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v1 + - name: Use Node.js v12.10.0 + uses: actions/setup-node@v1 + with: + node-version: v12.10.0 + - name: npm install, build, and test + run: | + npm install + npm run build + npm test + - name: Build and Deploy + if: $GITHUB_REF == "master" + uses: JamesIves/github-pages-deploy-action@master + env: + ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} + BASE_BRANCH: master + BRANCH: gh-pages + FOLDER: build diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 465373e7..00000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: node_js - -script: - - npm i - - npm test - - npm run build - -deploy: - provider: pages - skip_cleanup: true - github_token: $GITHUB_TOKEN - local_dir: dist - on: - branch: master From b87f4ca5baa68a8dbdaf0b354ddd476758623665 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:04:47 +0100 Subject: [PATCH 02/29] Try this --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d5a5c2aa..ec554f54 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: npm run build npm test - name: Build and Deploy - if: $GITHUB_REF == "master" + if: GITHUB_REF == "master" uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From 33fd3a4ed54edb3555cc664c4cd4f410604858de Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:06:26 +0100 Subject: [PATCH 03/29] This is it oohhhhhhh --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ec554f54..f8e8cbd2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: npm run build npm test - name: Build and Deploy - if: GITHUB_REF == "master" + if: github.ref == "master" uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From cd83d9f152a5a2b6f45de20c2dd763b4e2a2d5cf Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:07:17 +0100 Subject: [PATCH 04/29] u wot github --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f8e8cbd2..0bca8299 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: npm run build npm test - name: Build and Deploy - if: github.ref == "master" + if: github.ref == 'master' uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From cf0823b10b522d188c9b16875d007ecc46365ceb Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:08:44 +0100 Subject: [PATCH 05/29] It'd just be deploy here --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 0bca8299..6bf6f02c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: npm install npm run build npm test - - name: Build and Deploy + - name: Deploy if: github.ref == 'master' uses: JamesIves/github-pages-deploy-action@master env: From 7d48914bec634d74a22e942243acb143c123b870 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:09:04 +0100 Subject: [PATCH 06/29] That should be dist --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6bf6f02c..18a3ad03 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,4 +24,4 @@ jobs: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} BASE_BRANCH: master BRANCH: gh-pages - FOLDER: build + FOLDER: dist From c6c15d41df8a8f63ff8f6becae5cfc160cad6be7 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:13:03 +0100 Subject: [PATCH 07/29] Test the action with a mock deployment --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 18a3ad03..984cefab 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,10 +18,10 @@ jobs: npm run build npm test - name: Deploy - if: github.ref == 'master' + if: github.ref == 'gh-actions' uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} BASE_BRANCH: master - BRANCH: gh-pages + BRANCH: gh-pages-test FOLDER: dist From 49f7d38361e144ab682336297a415dd1a076e16b Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:13:28 +0100 Subject: [PATCH 08/29] Right branch would help --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 984cefab..f3cd3ce1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: npm run build npm test - name: Deploy - if: github.ref == 'gh-actions' + if: github.ref == 'gh_actions' uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From f23899b835ceb2bfa386273c146c820cf8b7e204 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:18:04 +0100 Subject: [PATCH 09/29] Are quotes not a thing? --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f3cd3ce1..79c36551 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,7 +18,7 @@ jobs: npm run build npm test - name: Deploy - if: github.ref == 'gh_actions' + if: github.ref == gh_actions uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From 130efd0e0d7c943d56ffff9199c766bcb3768f70 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:21:19 +0100 Subject: [PATCH 10/29] No it does need quotes, echo the ref --- .github/workflows/main.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 79c36551..bcba6c5b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,8 +17,9 @@ jobs: npm install npm run build npm test + echo ${{ github.ref }} - name: Deploy - if: github.ref == gh_actions + if: github.ref == 'gh_actions' uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From bf81dcc3d85842f12ffe72c64d2f8fad19b1e1c1 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:24:22 +0100 Subject: [PATCH 11/29] Try this --- .github/workflows/main.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index bcba6c5b..859ca773 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,9 +17,8 @@ jobs: npm install npm run build npm test - echo ${{ github.ref }} - name: Deploy - if: github.ref == 'gh_actions' + if: github.ref == 'refs/heads/gh_actions' uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} From 78159ac2cae3255e909b3fc9e81b0377b7c549bf Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 18:29:11 +0100 Subject: [PATCH 12/29] Make it deployment ready --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 859ca773..009ec1d1 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -18,10 +18,10 @@ jobs: npm run build npm test - name: Deploy - if: github.ref == 'refs/heads/gh_actions' + if: github.ref == 'refs/heads/master' uses: JamesIves/github-pages-deploy-action@master env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} BASE_BRANCH: master - BRANCH: gh-pages-test + BRANCH: gh-pages FOLDER: dist From 092404a183f36cc9c00ad3583eda3572f82f3bef Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 19:11:16 +0100 Subject: [PATCH 13/29] This *should* work --- .github/workflows/main.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 009ec1d1..1f16e0c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: npm install npm run build npm test - - name: Deploy + - name: Deploy to GitHub Pages if: github.ref == 'refs/heads/master' uses: JamesIves/github-pages-deploy-action@master env: @@ -25,3 +25,10 @@ jobs: BASE_BRANCH: master BRANCH: gh-pages FOLDER: dist + - uses: chrislennon/action-aws-cli@v1.1 + - name: Deploy to DigitalOcean Spaces + run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com + env: + AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: ${{ secrets.SPACES_REGION }} From 78c2d6b8a43b968f2fefaea6977bbb3d1d648756 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 19:18:29 +0100 Subject: [PATCH 14/29] Hopefully this works --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1f16e0c7..d955f609 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: FOLDER: dist - uses: chrislennon/action-aws-cli@v1.1 - name: Deploy to DigitalOcean Spaces - run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com + run: aws configure set default.s3.signature_version s3v2 && aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} From 7c17f5b32e7b01db85b4e809b8a6135caa32af0a Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 19:28:58 +0100 Subject: [PATCH 15/29] Try this *I reset the bucket env var, this works locally* --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d955f609..1f16e0c7 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: FOLDER: dist - uses: chrislennon/action-aws-cli@v1.1 - name: Deploy to DigitalOcean Spaces - run: aws configure set default.s3.signature_version s3v2 && aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com + run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} From 37fc775816eb4810fe66f8110b90cca34672d35a Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 19:52:21 +0100 Subject: [PATCH 16/29] Set the ACL --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1f16e0c7..92c2870c 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -27,7 +27,7 @@ jobs: FOLDER: dist - uses: chrislennon/action-aws-cli@v1.1 - name: Deploy to DigitalOcean Spaces - run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com + run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} From 96aa5d5e630361b8dd2a2faf654ad4b49dd9bbf2 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 20:08:05 +0100 Subject: [PATCH 17/29] Lots of linting --- .github/workflows/main.yml | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 92c2870c..09c5731b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -1,6 +1,6 @@ name: CI -on: [push] +on: push jobs: build: @@ -8,25 +8,33 @@ jobs: steps: - uses: actions/checkout@v1 - - name: Use Node.js v12.10.0 + + - name: Read .nvmrc + run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)" + id: nvm + + - name: Use Node.js (.nvmrc) uses: actions/setup-node@v1 with: - node-version: v12.10.0 - - name: npm install, build, and test + node-version: "${{ steps.nvm.outputs.NVMRC }}" + + - name: npm ci, test, and build run: | - npm install - npm run build + npm ci npm test - - name: Deploy to GitHub Pages + npm run build + + - name: Deploy master to GitHub Pages if: github.ref == 'refs/heads/master' - uses: JamesIves/github-pages-deploy-action@master + uses: JamesIves/github-pages-deploy-action@v2 env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} BASE_BRANCH: master BRANCH: gh-pages FOLDER: dist + - uses: chrislennon/action-aws-cli@v1.1 - - name: Deploy to DigitalOcean Spaces + - name: Deploy commit to DigitalOcean Spaces run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} From be9573aa5556833f6b3e95957a6fc93a99565855 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 20:09:21 +0100 Subject: [PATCH 18/29] I don't know if this'll work --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 09c5731b..93848dc4 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -33,8 +33,8 @@ jobs: BRANCH: gh-pages FOLDER: dist - - uses: chrislennon/action-aws-cli@v1.1 - name: Deploy commit to DigitalOcean Spaces + uses: chrislennon/action-aws-cli@v1.1 run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} From 9f703b3913e9bdcbf4805b52e888ac225a89d360 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 20:11:36 +0100 Subject: [PATCH 19/29] Fixes --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 93848dc4..7628eb1d 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -26,15 +26,15 @@ jobs: - name: Deploy master to GitHub Pages if: github.ref == 'refs/heads/master' - uses: JamesIves/github-pages-deploy-action@v2 + uses: JamesIves/github-pages-deploy-action@2.0.0 env: ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} BASE_BRANCH: master BRANCH: gh-pages FOLDER: dist + - uses: chrislennon/action-aws-cli@v1.1 - name: Deploy commit to DigitalOcean Spaces - uses: chrislennon/action-aws-cli@v1.1 run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} From da1f746ff04c777496bd098804e43f7e9cc47098 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 20:40:11 +0100 Subject: [PATCH 20/29] Try this --- .github/workflows/main.yml | 8 ++++++++ build/createGithubComment.js | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 build/createGithubComment.js diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 7628eb1d..ea07a787 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -40,3 +40,11 @@ jobs: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} AWS_DEFAULT_REGION: ${{ secrets.SPACES_REGION }} + + - name: Leave a comment + run: node ./build/createGithubComment.js + env: + COMMIT_SHA: ${{ github.sha }} + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} + SPACES_REGION: ${{ secrets.SPACES_REGION }} + SPACES_BUCKET: ${{ secrets.SPACES_BUCKET }} diff --git a/build/createGithubComment.js b/build/createGithubComment.js new file mode 100644 index 00000000..6c0b3784 --- /dev/null +++ b/build/createGithubComment.js @@ -0,0 +1,21 @@ +const fetch = require("node-fetch") + +const url = `https://${process.env.SPACES_BUCKET}.${process.env.SPACES_REGION}.digitaloceanspaces.com/${process.env.COMMIT_SHA}` + +const comment = `This commit has been deployed to DigitalOcean Spaces for easy viewing. ([DNS Tool](${url}/dns-tool/index.html), [SPF Explainer](${url}/spf-explainer/index.html))` + +fetch( + `https://api.github.com/repos/do-community/dns-tool/commits/${process.env.COMMIT_SHA}/comments`, + { + method: "POST", + body: JSON.stringify({ + body: comment, + }), + headers: { + Accept: "application/vnd.github.v3+json", + Authorization: `Basic JakeMakesStuff:${(new Buffer(process.env.GITHUB_ACCESS_TOKEN)).toString("base64")}`, + } + }, +).then(x => { + if (!x.ok) throw x +}).catch(e => { throw e }) From 6700b70af62a5351c32e7a28a1aa2cf25140e81e Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 21:01:20 +0100 Subject: [PATCH 21/29] Fix the comment code --- build/createGithubComment.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/build/createGithubComment.js b/build/createGithubComment.js index 6c0b3784..13dada53 100644 --- a/build/createGithubComment.js +++ b/build/createGithubComment.js @@ -12,10 +12,11 @@ fetch( body: comment, }), headers: { + "Content-Type": "application/json", Accept: "application/vnd.github.v3+json", - Authorization: `Basic JakeMakesStuff:${(new Buffer(process.env.GITHUB_ACCESS_TOKEN)).toString("base64")}`, + Authorization: `Basic ${Buffer.from(`JakeMakesStuff:${process.env.GITHUB_ACCESS_TOKEN}`).toString("base64")}`, } }, -).then(x => { - if (!x.ok) throw x -}).catch(e => { throw e }) +).then(async x => { + if (!x.ok) { console.log(await x.json()); process.exit(1); } +}).catch(async e => { console.log(await e.json()); process.exit(1); }) From 5b30f4dc0eacf70ed79b034a2f5a28e3d00d3d71 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 21:07:48 +0100 Subject: [PATCH 22/29] Test using the GH token --- .github/workflows/main.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index ea07a787..877207a6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,7 +28,7 @@ jobs: if: github.ref == 'refs/heads/master' uses: JamesIves/github-pages-deploy-action@2.0.0 env: - ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} + ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} BASE_BRANCH: master BRANCH: gh-pages FOLDER: dist @@ -45,6 +45,6 @@ jobs: run: node ./build/createGithubComment.js env: COMMIT_SHA: ${{ github.sha }} - GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_ACCESS_TOKEN }} + GITHUB_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }} SPACES_REGION: ${{ secrets.SPACES_REGION }} SPACES_BUCKET: ${{ secrets.SPACES_BUCKET }} From 9ba3c41c96e38630e7ae9047c47f8cc2da0f3124 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Thu, 12 Sep 2019 21:15:20 +0100 Subject: [PATCH 23/29] Fix auth header, Add new line --- .github/workflows/main.yml | 1 + build/createGithubComment.js | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 877207a6..f87d1d54 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -34,6 +34,7 @@ jobs: FOLDER: dist - uses: chrislennon/action-aws-cli@v1.1 + - name: Deploy commit to DigitalOcean Spaces run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read env: diff --git a/build/createGithubComment.js b/build/createGithubComment.js index 13dada53..9942e5a8 100644 --- a/build/createGithubComment.js +++ b/build/createGithubComment.js @@ -14,7 +14,7 @@ fetch( headers: { "Content-Type": "application/json", Accept: "application/vnd.github.v3+json", - Authorization: `Basic ${Buffer.from(`JakeMakesStuff:${process.env.GITHUB_ACCESS_TOKEN}`).toString("base64")}`, + Authorization: `Basic ${Buffer.from(`github-actions:${process.env.GITHUB_ACCESS_TOKEN}`).toString("base64")}`, } }, ).then(async x => { From 320edf95a7e70651e425d0b31ae118ff4c11a2a7 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Fri, 13 Sep 2019 08:50:17 +0100 Subject: [PATCH 24/29] Add content type --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index f87d1d54..259045a8 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -36,7 +36,7 @@ jobs: - uses: chrislennon/action-aws-cli@v1.1 - name: Deploy commit to DigitalOcean Spaces - run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read + run: aws s3 sync ./dist s3://${{ secrets.SPACES_BUCKET }}/${{ github.sha }} --endpoint=https://${{ secrets.SPACES_REGION }}.digitaloceanspaces.com --acl public-read --content-encoding utf8 env: AWS_ACCESS_KEY_ID: ${{ secrets.SPACES_ACCESS_KEY_ID }} AWS_SECRET_ACCESS_KEY: ${{ secrets.SPACES_SECRET_ACCESS_KEY }} From 6a0a2d0701f5fa75ef128de7cb0fbad7839e3c64 Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Fri, 13 Sep 2019 15:06:34 +0100 Subject: [PATCH 25/29] =?UTF-8?q?Magic=20tidying=20fairy=20(=E2=88=A9=20?= =?UTF-8?q?=CD=A1=C2=B0=20=CD=9C=CA=96=20=CD=A1=C2=B0)=E2=8A=83=E2=94=81?= =?UTF-8?q?=E2=98=86=EF=BE=9F.=20*=20=EF=BD=A5=20=EF=BD=A1=EF=BE=9F,?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/createGithubComment.js | 81 ++++++++++++++++++++++++++---------- 1 file changed, 59 insertions(+), 22 deletions(-) diff --git a/build/createGithubComment.js b/build/createGithubComment.js index 9942e5a8..6fd286a0 100644 --- a/build/createGithubComment.js +++ b/build/createGithubComment.js @@ -1,22 +1,59 @@ -const fetch = require("node-fetch") - -const url = `https://${process.env.SPACES_BUCKET}.${process.env.SPACES_REGION}.digitaloceanspaces.com/${process.env.COMMIT_SHA}` - -const comment = `This commit has been deployed to DigitalOcean Spaces for easy viewing. ([DNS Tool](${url}/dns-tool/index.html), [SPF Explainer](${url}/spf-explainer/index.html))` - -fetch( - `https://api.github.com/repos/do-community/dns-tool/commits/${process.env.COMMIT_SHA}/comments`, - { - method: "POST", - body: JSON.stringify({ - body: comment, - }), - headers: { - "Content-Type": "application/json", - Accept: "application/vnd.github.v3+json", - Authorization: `Basic ${Buffer.from(`github-actions:${process.env.GITHUB_ACCESS_TOKEN}`).toString("base64")}`, - } - }, -).then(async x => { - if (!x.ok) { console.log(await x.json()); process.exit(1); } -}).catch(async e => { console.log(await e.json()); process.exit(1); }) +/* +Copyright 2019 DigitalOcean + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +const fetch = require('node-fetch') +const path = require('path') +const { readdirSync } = require('fs') + +const main = async () => { + + const baseURL = `https://${process.env.SPACES_BUCKET}.${process.env.SPACES_REGION}.digitaloceanspaces.com/${process.env.COMMIT_SHA}` + + const tools = readdirSync(path.join(__dirname, '..', 'dist'), { withFileTypes: true }) + .filter(dirent => dirent.isDirectory()) + .map(dirent => dirent.name) + .map(name => `[${name}](${baseURL}/${name}/index.html)`) + + const comment = `This commit has been deployed to DigitalOcean Spaces for easy reviewing. + +| ${tools.join(' | ')} | +|${(new Array(tools.length).fill('---')).join('|')}|` + + const res = await fetch( + `https://api.github.com/repos/do-community/dns-tool/commits/${process.env.COMMIT_SHA}/comments`, + { + method: 'POST', + body: JSON.stringify({ + body: comment, + }), + headers: { + 'Content-Type': 'application/json', + Accept: 'application/vnd.github.v3+json', + Authorization: `Basic ${Buffer.from(`github-actions:${process.env.GITHUB_ACCESS_TOKEN}`).toString('base64')}`, + } + }, + ).catch(async e => { + console.log(await e.json()) + process.exit(1) + }) + + if (!res.ok) { + console.log(await res.json()) + process.exit(1) + } +} + +main() From 4d7259e0d7a6530fb1b116c2a23f3123b898d5dc Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Fri, 13 Sep 2019 16:19:09 +0100 Subject: [PATCH 26/29] I'm not keeping this edit, I just want to test this --- src/spf-explainer/templates/spf.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spf-explainer/templates/spf.vue b/src/spf-explainer/templates/spf.vue index 18abcf8f..a3a548bc 100644 --- a/src/spf-explainer/templates/spf.vue +++ b/src/spf-explainer/templates/spf.vue @@ -18,7 +18,7 @@ limitations under the License.
- {{ key }}  + {{ key }}
From f3a391402e4fa06e078db1f4db08c12786c33c6c Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Fri, 13 Sep 2019 16:26:41 +0100 Subject: [PATCH 27/29] Hmmmm that worked, lets test moving that space --- src/spf-explainer/templates/spf.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/src/spf-explainer/templates/spf.vue b/src/spf-explainer/templates/spf.vue index a3a548bc..5f422d17 100644 --- a/src/spf-explainer/templates/spf.vue +++ b/src/spf-explainer/templates/spf.vue @@ -19,6 +19,7 @@ limitations under the License.
{{ key }} +  
From 020a4cd6a4174ebddc9bf27c14420271bd323592 Mon Sep 17 00:00:00 2001 From: Jake Gealer Date: Fri, 13 Sep 2019 16:32:35 +0100 Subject: [PATCH 28/29] Try this (sorry for all the commits, I cannot recreate locally) --- src/spf-explainer/templates/spf.vue | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/spf-explainer/templates/spf.vue b/src/spf-explainer/templates/spf.vue index 5f422d17..3734a9c0 100644 --- a/src/spf-explainer/templates/spf.vue +++ b/src/spf-explainer/templates/spf.vue @@ -18,8 +18,7 @@ limitations under the License.
- {{ key }} -   + {{ key }}
From 3e7c02e253e435f886c3dadd82e46585130a7acf Mon Sep 17 00:00:00 2001 From: MattIPv4 Date: Fri, 13 Sep 2019 17:17:12 +0100 Subject: [PATCH 29/29] try this --- build/buildTool.js | 7 +++++-- build/fetchTemplate.js | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/build/buildTool.js b/build/buildTool.js index 95c25538..46cb4eeb 100644 --- a/build/buildTool.js +++ b/build/buildTool.js @@ -63,10 +63,13 @@ const index = async (file, out) => { const post = posthtml(plugins) // Process - const result = await post.process(source) + const html = (await post.process(source)).html + + // Remove comments before HTML + const result = html.replace(/^([\w\n]*)*/gms, '') // Export - fs.writeFileSync(Path.join(__dirname, '..', out), result.html, { flag: 'w+' }) + fs.writeFileSync(Path.join(__dirname, '..', out), result, { flag: 'w+' }) console.log(`...build successfully, saved to ${out}`) } diff --git a/build/fetchTemplate.js b/build/fetchTemplate.js index d265e79e..51b3ea7e 100644 --- a/build/fetchTemplate.js +++ b/build/fetchTemplate.js @@ -27,7 +27,8 @@ const main = async () => { let rawHTML = await res.text() // Parse - const { document } = (new JSDOM(rawHTML)).window + const dom = new JSDOM(rawHTML) + const { document } = dom.window const nav = document.querySelector('nav.do_nav') // Nuke top log in button @@ -58,8 +59,13 @@ const main = async () => { } }) + // Inject charset + const charset = document.createElement('meta') + charset.setAttribute('charset', 'utf8') + document.head.insertBefore(charset, document.head.firstChild) + // Convert back to raw - rawHTML = document.documentElement.innerHTML + rawHTML = dom.serialize() // Inject title block rawHTML = rawHTML.replace(/(.+?)<\/title>/, '<title><block name="title"></block>$1') @@ -72,7 +78,7 @@ const main = async () => { '
') // Inject last fetch comment - rawHTML = rawHTML.replace('', ``) + rawHTML = rawHTML.replace('', `\n`) // Export fs.writeFileSync(`${__dirname}/base.html`, rawHTML, { flag: 'w+' })