From ba8d5f2101afa50fea081450cd67fc1c32f3ec57 Mon Sep 17 00:00:00 2001 From: Johan Suleiko Allansson Date: Wed, 23 Sep 2020 13:48:36 +0200 Subject: [PATCH 1/4] =?UTF-8?q?[chore]=C2=A0deploy=20a=20version=20of=20do?= =?UTF-8?q?cs=20when=20PR=20is=20created?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-deploy.yml | 92 +++++++++++++++++++++++++++++++++ gatsby-config.js | 5 +- src/styles/parts/fonts.scss | 18 ++++--- 3 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 .github/workflows/pr-deploy.yml diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml new file mode 100644 index 000000000..f30573c6a --- /dev/null +++ b/.github/workflows/pr-deploy.yml @@ -0,0 +1,92 @@ +name: Pull Request CI + +env: + PATH_PREFIX: /docs/pull-requests/${{ github.ref }} + GATSBY_DEFAULT_MAIN_URL: https://staging.k6.io + GATSBY_DEFAULT_DOC_URL: https://staging.k6.io/docs/pull-requests/${{ github.ref }} + GATSBY_DEFAULT_BLOG_URL: https://k6.io/blog + GATSBY_DEFAULT_APP_URL: https://app.staging.k6.io + +on: + pull_request: + branches: develop + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + + - name: Print build settings + run: | + echo "PATH_PREFIX: $PATH_PREFIX" + echo "GATSBY_DEFAULT_MAIN_URL: $GATSBY_DEFAULT_MAIN_URL" + echo "GATSBY_DEFAULT_DOC_URL: $GATSBY_DEFAULT_DOC_URL" + echo "GATSBY_DEFAULT_BLOG_URL: $GATSBY_DEFAULT_BLOG_URL" + echo "GATSBY_DEFAULT_APP_URL: $GATSBY_DEFAULT_APP_URL" + + - name: Use Node.js 12.xs + uses: actions/setup-node@v1 + with: + node-version: '12.x' + registry-url: 'https://registry.npmjs.org' + + - name: Install + run: npm install + + - name: Build + run: npm run build + + - name: Upload artifact + uses: actions/upload-artifact@v2 + with: + name: k6-docs + path: public/ + + deploy: + runs-on: ubuntu-latest + needs: [build] + + env: + AWS_ACCESS_KEY_ID: ${{ secrets.PR_CI_AWS_ACCESS_KEY }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_CI_AWS_SECRET_KEY }} + AWS_REGION: 'eu-west-1' + + steps: + - name: Download artifact + uses: actions/download-artifact@v2 + with: + name: k6-docs + path: public/ + + - name: Sync to S3 + uses: jakejarvis/s3-sync-action@v0.5.1 + with: + args: --delete + env: + AWS_S3_BUCKET: ${{ secrets.PR_CI_AWS_S3_BUCKET }} + SOURCE_DIR: public/ + DEST_DIR: docs/pull-requests/${{ github.ref }} + + - name: Invalidate Cloudfront + uses: chetan/invalidate-cloudfront-action@v1.2 + env: + DISTRIBUTION: ${{ secrets.PR_CI_CLOUDFRONT_DISTRIBUTION_ID }} + PATHS: '/docs/pull-requests/*' + + - name: Post published URL to PR + if: github.event.action == 'opened' + uses: actions/github-script@0.8.0 + with: + github-token: ${{secrets.GITHUB_TOKEN}} + script: | + github.issues.createComment({ + issue_number: context.payload.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: + "There's a version of the docs published here:\n\n" + + `${process.env.GATSBY_DEFAULT_DOC_URL}\n\n` + + 'It will be deleted automatically in 30 days.', + }) diff --git a/gatsby-config.js b/gatsby-config.js index 4d77bbbb3..1c6179fde 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -5,7 +5,7 @@ require('dotenv').config({ const mainURL = process.env.GATSBY_DEFAULT_DOC_URL; const isProduction = mainURL === 'https://k6.io/docs'; -const isStaging = mainURL === 'https://staging.k6.io/docs'; +const isStaging = mainURL.startsWith('https://staging.k6.io'); const plugins = [ 'gatsby-plugin-react-helmet', @@ -226,6 +226,7 @@ if (process.env.BUCKET_NAME) { options: { bucketName: process.env.BUCKET_NAME, region: process.env.BUCKET_REGION, + retainObjectsPatterns: ['pull-requests/**/*'], protocol: 'https', hostname: isProduction ? 'k6.io' : 'staging.k6.io', }, @@ -233,7 +234,7 @@ if (process.env.BUCKET_NAME) { } module.exports = { - pathPrefix: `/docs`, + pathPrefix: process.env.PATH_PREFIX || `/docs`, siteMetadata: { siteTitle: diff --git a/src/styles/parts/fonts.scss b/src/styles/parts/fonts.scss index 6ec28ec50..4731377f2 100644 --- a/src/styles/parts/fonts.scss +++ b/src/styles/parts/fonts.scss @@ -29,22 +29,28 @@ font-family: 'TT Norms Pro'; font-style: normal; font-weight: 400; - src: url('/fonts/tt-norms-pro/tt-pro-regular-webfont.woff2') format('woff2'), - url('/fonts/tt-norms-pro/tt-pro-regular-webfont.woff') format('woff'); + src: url('../../static/fonts/tt-norms-pro/tt-pro-regular-webfont.woff2') + format('woff2'), + url('../../static/fonts/tt-norms-pro/tt-pro-regular-webfont.woff') + format('woff'); } @font-face { font-family: 'TT Norms Pro'; font-style: normal; font-weight: 500; - src: url('/fonts/tt-norms-pro/tt-pro-medium-webfont.woff2') format('woff2'), - url('/fonts/tt-norms-pro/tt-pro-medium-webfont.woff') format('woff'); + src: url('../../static/fonts/tt-norms-pro/tt-pro-medium-webfont.woff2') + format('woff2'), + url('../../static/fonts/tt-norms-pro/tt-pro-medium-webfont.woff') + format('woff'); } @font-face { font-family: 'TT Norms Pro'; font-style: normal; font-weight: 700; - src: url('/fonts/tt-norms-pro/tt-pro-bold-webfont.woff2') format('woff2'), - url('/fonts/tt-norms-pro/tt-pro-bold-webfont.woff') format('woff'); + src: url('../../static/fonts/tt-norms-pro/tt-pro-bold-webfont.woff2') + format('woff2'), + url('../../static/fonts/tt-norms-pro/tt-pro-bold-webfont.woff') + format('woff'); } From 99a906d5742eac83effc2d57600362da266087fc Mon Sep 17 00:00:00 2001 From: Johan Suleiko Allansson Date: Thu, 29 Oct 2020 15:08:54 +0100 Subject: [PATCH 2/4] =?UTF-8?q?[chore]=C2=A0remove=20retainObjectsPatterns?= =?UTF-8?q?=20for=20gatsby-plugin-s3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gatsby-config.js | 1 - 1 file changed, 1 deletion(-) diff --git a/gatsby-config.js b/gatsby-config.js index 1c6179fde..7112be1a5 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -226,7 +226,6 @@ if (process.env.BUCKET_NAME) { options: { bucketName: process.env.BUCKET_NAME, region: process.env.BUCKET_REGION, - retainObjectsPatterns: ['pull-requests/**/*'], protocol: 'https', hostname: isProduction ? 'k6.io' : 'staging.k6.io', }, From 883bc780a6fc0ef0233f4471b936fe11ef0387ff Mon Sep 17 00:00:00 2001 From: Johan Suleiko Allansson Date: Thu, 29 Oct 2020 15:15:45 +0100 Subject: [PATCH 3/4] =?UTF-8?q?[chore]=C2=A0update=20pr=20branch=20to=20ma?= =?UTF-8?q?ster?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml index f30573c6a..f98d804c1 100644 --- a/.github/workflows/pr-deploy.yml +++ b/.github/workflows/pr-deploy.yml @@ -9,7 +9,7 @@ env: on: pull_request: - branches: develop + branches: master jobs: build: From b2772c0b8ada0b13a3125eb7d5fd351228d5b1a9 Mon Sep 17 00:00:00 2001 From: Johan Suleiko Allansson Date: Thu, 29 Oct 2020 15:28:24 +0100 Subject: [PATCH 4/4] =?UTF-8?q?[chore]=C2=A0update=20to=20correct=20urls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pr-deploy.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pr-deploy.yml b/.github/workflows/pr-deploy.yml index f98d804c1..30f97a653 100644 --- a/.github/workflows/pr-deploy.yml +++ b/.github/workflows/pr-deploy.yml @@ -1,9 +1,9 @@ name: Pull Request CI env: - PATH_PREFIX: /docs/pull-requests/${{ github.ref }} + PATH_PREFIX: /docs/${{ github.ref }} GATSBY_DEFAULT_MAIN_URL: https://staging.k6.io - GATSBY_DEFAULT_DOC_URL: https://staging.k6.io/docs/pull-requests/${{ github.ref }} + GATSBY_DEFAULT_DOC_URL: https://mdr-ci.staging.k6.io/docs/${{ github.ref }} GATSBY_DEFAULT_BLOG_URL: https://k6.io/blog GATSBY_DEFAULT_APP_URL: https://app.staging.k6.io @@ -67,13 +67,13 @@ jobs: env: AWS_S3_BUCKET: ${{ secrets.PR_CI_AWS_S3_BUCKET }} SOURCE_DIR: public/ - DEST_DIR: docs/pull-requests/${{ github.ref }} + DEST_DIR: docs/${{ github.ref }} - name: Invalidate Cloudfront uses: chetan/invalidate-cloudfront-action@v1.2 env: DISTRIBUTION: ${{ secrets.PR_CI_CLOUDFRONT_DISTRIBUTION_ID }} - PATHS: '/docs/pull-requests/*' + PATHS: '/docs/*' - name: Post published URL to PR if: github.event.action == 'opened'