From 20979f8698740f53ff44fcbba080415b3442c69b Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Mon, 21 Jun 2021 22:34:28 +0000 Subject: [PATCH 01/15] test auto-deploy action Former-commit-id: cd683c41c6dff71e090506488b1cd98df2c767a5 --- .github/workflows/deploy-draft.yml | 83 ++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 .github/workflows/deploy-draft.yml diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml new file mode 100644 index 00000000000..91d5a7b4bec --- /dev/null +++ b/.github/workflows/deploy-draft.yml @@ -0,0 +1,83 @@ +name: Deploy branch draft on Netlify +on: + pull_request: + types: [labeled, opened, synchronize] + +jobs: + build-deploy: + if: | + (github.event.action == 'labeled' && github.event.label.name == 'deploy') || + (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'deploy')) + runs-on: ubuntu-latest + steps: + + - name: create a github deployment + uses: bobheadxi/deployments@v0.5.2 + id: deployment + with: + step: start + token: ${{ secrets.GITHUB_TOKEN }} + env: pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }} + ref: ${{ github.head_ref }} + + - uses: actions/checkout@v2 + with: + ref: content/mongo_data_adapter/5.2.9/upcoming_release + fetch-depth: 0 # fetch whole repo so git-restore-mtime can work + - name: Update submodules + run: git submodule update --init --remote + - name: Adjust file watchers limit + run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p + + - uses: actions/setup-node@v1 + with: + node-version: '14.x' + - name: Install yarn + run: sudo npm -g install yarn + - name: Yarn install + run: yarn install --immutable + env: + NODE_ENV: ${{ secrets.NODE_ENV }} + + - name: Checking Gatsby cache + id: gatsby-cache-build + uses: actions/cache@v2 + with: + path: | + public + .cache + key: ${{ runner.os }}-gatsby-build-develop-${{ github.run_id }} + restore-keys: | + ${{ runner.os }}-gatsby-build-develop- + + - name: Fix mtimes + run: yarn fix-mtimes --force + - name: Gatsby build + run: yarn build + env: + APP_ENV: staging + NODE_ENV: ${{ secrets.NODE_ENV }} + NODE_OPTIONS: --max-old-space-size=4096 + ALGOLIA_API_KEY: ${{ secrets.ALGOLIA_API_KEY }} + ALGOLIA_APP_ID: ${{ secrets.ALGOLIA_APP_ID }} + ALGOLIA_INDEX_NAME: edb-docs-staging + INDEX_ON_BUILD: false + + - name: Netlify deploy + run: | + sudo yarn global add netlify-cli + netlify deploy --dir=public --json | tee deploy_results.json + echo "NETLIFY_DRAFT_URL=`jq '.deploy_url' deploy_results.json`" >> $GITHUB_ENV + env: + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_WIP2_SITE_ID }} + + - name: update the github deployment status + uses: bobheadxi/deployments@v0.5.2 + if: always() + with: + step: finish + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + env_url: ${{ env.NETLIFY_DRAFT_URL }} From e43ada7f10efa199c086d5c73752669480f4eda9 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Mon, 21 Jun 2021 22:36:30 +0000 Subject: [PATCH 02/15] use staging site Former-commit-id: 45797de0b665082a5a766286407378752f89aadc --- .github/workflows/deploy-draft.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 91d5a7b4bec..1026c35e7a1 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -70,7 +70,7 @@ jobs: echo "NETLIFY_DRAFT_URL=`jq '.deploy_url' deploy_results.json`" >> $GITHUB_ENV env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_WIP2_SITE_ID }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} - name: update the github deployment status uses: bobheadxi/deployments@v0.5.2 From 24cac49ff55363d89fa453cfd89a5bcb758aae5b Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 22 Jun 2021 01:49:14 +0000 Subject: [PATCH 03/15] argh, quotes Former-commit-id: e11c7c6e9d2ef125edfef049ce6a5d5208534e60 --- .github/workflows/deploy-draft.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 1026c35e7a1..4e5be273f43 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -67,7 +67,7 @@ jobs: run: | sudo yarn global add netlify-cli netlify deploy --dir=public --json | tee deploy_results.json - echo "NETLIFY_DRAFT_URL=`jq '.deploy_url' deploy_results.json`" >> $GITHUB_ENV + echo "NETLIFY_DRAFT_URL=`jq -r '.deploy_url' deploy_results.json`" >> $GITHUB_ENV env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} From 8f4332e4ce26ad37a10c01d33c80a5ad45ecac0a Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:40:04 +0000 Subject: [PATCH 04/15] better name (ref: https://github.com/jgoux/preview-environments-per-pull-request-using-aws-cdk-and-github-actions) Former-commit-id: 4c514ab223bf333b6c3eb168578857f49c93b58a --- .github/workflows/deploy-draft.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 4e5be273f43..3cc27a91e2b 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -10,6 +10,11 @@ jobs: (github.event.action != 'labeled' && contains(github.event.pull_request.labels.*.name, 'deploy')) runs-on: ubuntu-latest steps: + - name: inject slug/short variables + uses: rlespinasse/github-slug-action@v3.x + + - name: set STAGE variable in environment for next steps + run: echo "STAGE=pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" >> $GITHUB_ENV - name: create a github deployment uses: bobheadxi/deployments@v0.5.2 @@ -17,7 +22,7 @@ jobs: with: step: start token: ${{ secrets.GITHUB_TOKEN }} - env: pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }} + env: ${{ env.STAGE }} ref: ${{ github.head_ref }} - uses: actions/checkout@v2 From ca04204fb9660a60c552a2d4890fce28688f51c2 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Fri, 2 Jul 2021 16:47:56 +0000 Subject: [PATCH 05/15] kill submodules, use current branch Former-commit-id: 85c26298c30e29cc66e4a8fe980cd24e42556e79 --- .github/workflows/deploy-draft.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 3cc27a91e2b..2823de164d3 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -27,10 +27,8 @@ jobs: - uses: actions/checkout@v2 with: - ref: content/mongo_data_adapter/5.2.9/upcoming_release fetch-depth: 0 # fetch whole repo so git-restore-mtime can work - - name: Update submodules - run: git submodule update --init --remote + - name: Adjust file watchers limit run: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p From 724a6c54fbaf2069202258278fb147f8af3842f1 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 6 Jul 2021 21:30:38 +0000 Subject: [PATCH 06/15] use current branch for edit links Former-commit-id: 2ad3ba1f938753917ffbff4d0ebc979ee64b1686 --- gatsby-node.js | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index a769df86bb0..a3c15eb30e0 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -28,6 +28,23 @@ const { const isBuild = process.env.NODE_ENV === 'production'; const isProduction = process.env.APP_ENV === 'production'; +const currentBranchName = (() => { + // if this build was triggered by a GH action in response to a PR, + // use the head ref (the branch that someone is requesting be merged) + let branch = process.env.GITHUB_HEAD_REF; + // if this process was otherwise triggered by a GH action, use the current branch name + if (!branch) branch = process.env.GITHUB_REF; + // non-GH Action build? Try actually running Git for the name... + if (!branch) { + try { + branch = execSync('git rev-parse --abbrev-ref HEAD').toString(); + } catch {} + } + if (!branch) branch = isProduction ? 'main' : 'develop'; + + return branch.replace(/^refs\/heads\//, '').replace(/^refs\/tags\//, ''); +})(); + exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => { const { createNodeField } = actions; @@ -238,12 +255,11 @@ const createDoc = (navTree, prevNext, doc, productVersions, actions) => { const isIndexPage = isPathAnIndexPage(doc.fileAbsolutePath); const docsRepoUrl = 'https://github.com/EnterpriseDB/docs'; - const branch = isProduction ? 'main' : 'develop'; const fileUrlSegment = removeTrailingSlash(doc.fields.path) + (isIndexPage ? '/index.mdx' : '.mdx'); - const githubFileLink = `${docsRepoUrl}/commits/${branch}/product_docs/docs${fileUrlSegment}`; - const githubEditLink = `${docsRepoUrl}/edit/${branch}/product_docs/docs${fileUrlSegment}`; + const githubFileLink = `${docsRepoUrl}/commits/${currentBranchName}/product_docs/docs${fileUrlSegment}`; + const githubEditLink = `${docsRepoUrl}/edit/${currentBranchName}/product_docs/docs${fileUrlSegment}`; const githubIssuesLink = `${docsRepoUrl}/issues/new?title=Feedback%20on%20${encodeURIComponent( fileUrlSegment, )}`; @@ -297,13 +313,12 @@ const createAdvocacy = (navTree, prevNext, doc, learn, actions) => { ); const advocacyDocsRepoUrl = 'https://github.com/EnterpriseDB/docs'; - const branch = isProduction ? 'main' : 'develop'; const isIndexPage = isPathAnIndexPage(doc.fileAbsolutePath); const fileUrlSegment = removeTrailingSlash(doc.fields.path) + (isIndexPage ? '/index.mdx' : '.mdx'); - const githubFileLink = `${advocacyDocsRepoUrl}/commits/${branch}/advocacy_docs${fileUrlSegment}`; - const githubEditLink = `${advocacyDocsRepoUrl}/edit/${branch}/advocacy_docs${fileUrlSegment}`; + const githubFileLink = `${advocacyDocsRepoUrl}/commits/${currentBranchName}/advocacy_docs${fileUrlSegment}`; + const githubEditLink = `${advocacyDocsRepoUrl}/edit/${currentBranchName}/advocacy_docs${fileUrlSegment}`; const githubIssuesLink = `${advocacyDocsRepoUrl}/issues/new?title=Regarding%20${encodeURIComponent( fileUrlSegment, )}`; From ed09a15f79f3b4e502de3bc1bdad154042e3dc94 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 04:24:03 +0000 Subject: [PATCH 07/15] poke to trigger build Former-commit-id: e14e51b9c7cf3d9c245db1260e0c6ef44e01b563 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7fd12e848e4..b4bb0eb470b 100644 --- a/README.md +++ b/README.md @@ -236,3 +236,4 @@ Option 2: on GitHub 1. Edit a file on GitHub. 2. Submit changes as a PR on a new branch. + From 03cc6ebacf0b7254b83006d76cfcebd8cce64cd2 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 05:22:28 +0000 Subject: [PATCH 08/15] suggestions from @frago12 Former-commit-id: ba9d7e0688c529dc04f8c4131c1f8b30a1256afc --- .github/workflows/deploy-draft.yml | 28 +++++++++++++++------------- package.json | 3 ++- yarn.lock | 5 +++++ 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 2823de164d3..68346892522 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -13,8 +13,8 @@ jobs: - name: inject slug/short variables uses: rlespinasse/github-slug-action@v3.x - - name: set STAGE variable in environment for next steps - run: echo "STAGE=pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" >> $GITHUB_ENV + - name: compose a name for the build environment + run: echo "BUILD_ENV_NAME=pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" >> $GITHUB_ENV - name: create a github deployment uses: bobheadxi/deployments@v0.5.2 @@ -22,7 +22,7 @@ jobs: with: step: start token: ${{ secrets.GITHUB_TOKEN }} - env: ${{ env.STAGE }} + env: ${{ env.BUILD_ENV_NAME }} ref: ${{ github.head_ref }} - uses: actions/checkout@v2 @@ -35,10 +35,8 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '14.x' - - name: Install yarn - run: sudo npm -g install yarn - name: Yarn install - run: yarn install --immutable + run: npx yarn install --immutable env: NODE_ENV: ${{ secrets.NODE_ENV }} @@ -66,14 +64,18 @@ jobs: ALGOLIA_INDEX_NAME: edb-docs-staging INDEX_ON_BUILD: false - - name: Netlify deploy - run: | - sudo yarn global add netlify-cli - netlify deploy --dir=public --json | tee deploy_results.json - echo "NETLIFY_DRAFT_URL=`jq -r '.deploy_url' deploy_results.json`" >> $GITHUB_ENV + - name: Deploy to Netlify + id: netlify-deploy + uses: nwtgck/actions-netlify@v1.2.2 + with: + publish-dir: './public' + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: "Deploy from GitHub Actions" + alias: ${{ github.head_ref }} + github-deployment-environment: ${{ env.BUILD_ENV_NAME }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} - name: update the github deployment status uses: bobheadxi/deployments@v0.5.2 @@ -83,4 +85,4 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} status: ${{ job.status }} deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: ${{ env.NETLIFY_DRAFT_URL }} + env_url: ${{ steps.netlify-deploy.outputs.deploy-url }} diff --git a/package.json b/package.json index 8e8472a2d54..396e7cf98a0 100644 --- a/package.json +++ b/package.json @@ -85,7 +85,8 @@ "remark-stringify": "^8.1.1", "semver-compare": "^1.0.0", "to-vfile": "^6.1.0", - "typescript": "^4.1.3" + "typescript": "^4.1.3", + "yarn": "^1.22.10" }, "repository": { "type": "git", diff --git a/yarn.lock b/yarn.lock index 940459fbad0..c396bcb28f2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -15290,6 +15290,11 @@ yargs@^16.1.0: y18n "^5.0.5" yargs-parser "^20.2.2" +yarn@^1.22.10: + version "1.22.10" + resolved "https://registry.yarnpkg.com/yarn/-/yarn-1.22.10.tgz#c99daa06257c80f8fa2c3f1490724e394c26b18c" + integrity sha512-IanQGI9RRPAN87VGTF7zs2uxkSyQSrSPsju0COgbsKQOOXr5LtcVPeyXWgwVa0ywG3d8dg6kSYKGBuYK021qeA== + yauzl@^2.4.2: version "2.10.0" resolved "https://registry.yarnpkg.com/yauzl/-/yauzl-2.10.0.tgz#c7eb17c93e112cb1086fa6d8e51fb0667b79a5f9" From cdbbe92b80960ba4c71b460d94da8251fea3c516 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 05:50:37 +0000 Subject: [PATCH 09/15] clean up refs Former-commit-id: 47c9fba65fd4c4fa484772d21e31d368f239c974 --- .github/workflows/deploy-draft.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 68346892522..90cbdbc51b6 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -23,10 +23,11 @@ jobs: step: start token: ${{ secrets.GITHUB_TOKEN }} env: ${{ env.BUILD_ENV_NAME }} - ref: ${{ github.head_ref }} + ref: ${{ github.event.pull_request.head.ref }} - uses: actions/checkout@v2 with: + ref: ${{ github.event.pull_request.head.sha }} fetch-depth: 0 # fetch whole repo so git-restore-mtime can work - name: Adjust file watchers limit @@ -35,6 +36,7 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '14.x' + - name: Yarn install run: npx yarn install --immutable env: From 40b6afe94527f198bafc5b3bcda6ecce60c7fd61 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 19:43:32 +0000 Subject: [PATCH 10/15] slimmer Former-commit-id: 4927ed5661c716e1dc86f479ccc13d694d5d229a --- .github/workflows/deploy-draft.yml | 39 +++++++++++++----------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 90cbdbc51b6..69200aa8bd3 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -16,15 +16,6 @@ jobs: - name: compose a name for the build environment run: echo "BUILD_ENV_NAME=pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" >> $GITHUB_ENV - - name: create a github deployment - uses: bobheadxi/deployments@v0.5.2 - id: deployment - with: - step: start - token: ${{ secrets.GITHUB_TOKEN }} - env: ${{ env.BUILD_ENV_NAME }} - ref: ${{ github.event.pull_request.head.ref }} - - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} @@ -36,6 +27,19 @@ jobs: - uses: actions/setup-node@v1 with: node-version: '14.x' + + # ref: https://github.com/actions/cache/blob/main/examples.md#node---yarn + - name: Get yarn cache directory + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Checking Yarn cache + uses: actions/cache@v2 + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- - name: Yarn install run: npx yarn install --immutable @@ -49,12 +53,11 @@ jobs: path: | public .cache - key: ${{ runner.os }}-gatsby-build-develop-${{ github.run_id }} - restore-keys: | - ${{ runner.os }}-gatsby-build-develop- + key: ${{ runner.os }}-gatsby-build-draft-${{ github.head_ref }} - name: Fix mtimes run: yarn fix-mtimes --force + - name: Gatsby build run: yarn build env: @@ -72,19 +75,11 @@ jobs: with: publish-dir: './public' github-token: ${{ secrets.GITHUB_TOKEN }} - deploy-message: "Deploy from GitHub Actions" + deploy-message: ${{ github.event.pull_request.title }} + enable-commit-comment: false alias: ${{ github.head_ref }} github-deployment-environment: ${{ env.BUILD_ENV_NAME }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} - - name: update the github deployment status - uses: bobheadxi/deployments@v0.5.2 - if: always() - with: - step: finish - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: ${{ steps.netlify-deploy.outputs.deploy-url }} From 1cc567e1d2546f42e8803e29da8a7696fbb7a565 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 21:06:07 +0000 Subject: [PATCH 11/15] indicate that deployment is starting sooner. Ditch alias Former-commit-id: 3718aee3bfe170cec80ec2abf0059dab4c2ab1ba --- .github/workflows/deploy-draft.yml | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 69200aa8bd3..659f5d04095 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -2,7 +2,11 @@ name: Deploy branch draft on Netlify on: pull_request: types: [labeled, opened, synchronize] - + +concurrency: + group: ${{ github.head_ref }} + cancel-in-progress: true + jobs: build-deploy: if: | @@ -16,6 +20,18 @@ jobs: - name: compose a name for the build environment run: echo "BUILD_ENV_NAME=pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" >> $GITHUB_ENV + # creates a deployment so that a status is immediately visible on the PR + # this deployment will be completed by the netlify deploy step below + - name: create a github deployment + uses: bobheadxi/deployments@v0.6.0 + id: deployment + with: + step: start + token: ${{ secrets.GITHUB_TOKEN }} + env: ${{ env.BUILD_ENV_NAME }} + ref: ${{ github.head_ref }} + logs: https://github.com/${{ github.repository }}/pull/${{ github.event.number }} + - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} @@ -77,7 +93,6 @@ jobs: github-token: ${{ secrets.GITHUB_TOKEN }} deploy-message: ${{ github.event.pull_request.title }} enable-commit-comment: false - alias: ${{ github.head_ref }} github-deployment-environment: ${{ env.BUILD_ENV_NAME }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} From 017243dec7cdc69215a928e24e79edd015804c06 Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 21:09:28 +0000 Subject: [PATCH 12/15] link to run for logs Former-commit-id: daf054de75d65d78ec513a4cd2fb2da53585add2 --- .github/workflows/deploy-draft.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 659f5d04095..346bc7d8464 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -30,7 +30,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} env: ${{ env.BUILD_ENV_NAME }} ref: ${{ github.head_ref }} - logs: https://github.com/${{ github.repository }}/pull/${{ github.event.number }} + logs: https://github.com/${{ github.repository }}/pull/${{ github.event.number }}/checks?check_run_id=${{ github.run_id }} - uses: actions/checkout@v2 with: From 5b35958e01a90d2eb493d0b01aa46c5e7378c3cf Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 22:01:50 +0000 Subject: [PATCH 13/15] iterate on getting deployment status right Former-commit-id: c2fb6451a9aa3d5b2469419f22e1ca7b2f4e2a4f --- .github/workflows/deploy-draft.yml | 45 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 346bc7d8464..633a5f36a87 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -23,15 +23,23 @@ jobs: # creates a deployment so that a status is immediately visible on the PR # this deployment will be completed by the netlify deploy step below - name: create a github deployment - uses: bobheadxi/deployments@v0.6.0 id: deployment + uses: avakar/create-deployment@v1 with: - step: start - token: ${{ secrets.GITHUB_TOKEN }} - env: ${{ env.BUILD_ENV_NAME }} ref: ${{ github.head_ref }} - logs: https://github.com/${{ github.repository }}/pull/${{ github.event.number }}/checks?check_run_id=${{ github.run_id }} - + environment: ${{ env.BUILD_ENV_NAME }} + transient_environment: true + auto_merge: false + env: + GITHUB_TOKEN: ${{ secrets.DEPLOY_TOKEN }} + + - uses: avakar/set-deployment-status@v1 + with: + state: in_progress + deployment_id: ${{ steps.deployment.output.deployment_id }} + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} @@ -85,16 +93,21 @@ jobs: ALGOLIA_INDEX_NAME: edb-docs-staging INDEX_ON_BUILD: false - - name: Deploy to Netlify - id: netlify-deploy - uses: nwtgck/actions-netlify@v1.2.2 - with: - publish-dir: './public' - github-token: ${{ secrets.GITHUB_TOKEN }} - deploy-message: ${{ github.event.pull_request.title }} - enable-commit-comment: false - github-deployment-environment: ${{ env.BUILD_ENV_NAME }} + - name: Netlify deploy + run: | + sudo yarn global add netlify-cli + netlify deploy --dir=public --json | tee deploy_results.json + echo "NETLIFY_DRAFT_URL=`jq -r '.deploy_url' deploy_results.json`" >> $GITHUB_ENV env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} + - name: update the github deployment status + uses: bobheadxi/deployments@v0.5.2 + if: always() + with: + step: finish + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + deployment_id: ${{ steps.deployment.outputs.deployment_id }} + env_url: ${{ steps.netlify-deploy.outputs.deploy-url }} \ No newline at end of file From 62791d204fddd1eec6fcf848c1f571d37b3497ee Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Tue, 20 Jul 2021 22:06:10 +0000 Subject: [PATCH 14/15] give up on full deployment coverage for now Former-commit-id: bb60bacb12e628ef3059e898ffa43613302ac69d --- .github/workflows/deploy-draft.yml | 47 +++++++----------------------- 1 file changed, 11 insertions(+), 36 deletions(-) diff --git a/.github/workflows/deploy-draft.yml b/.github/workflows/deploy-draft.yml index 633a5f36a87..48f8e1880f7 100644 --- a/.github/workflows/deploy-draft.yml +++ b/.github/workflows/deploy-draft.yml @@ -19,27 +19,7 @@ jobs: - name: compose a name for the build environment run: echo "BUILD_ENV_NAME=pr-${{ github.event.number }}-${{ env.GITHUB_HEAD_REF_SLUG }}" >> $GITHUB_ENV - - # creates a deployment so that a status is immediately visible on the PR - # this deployment will be completed by the netlify deploy step below - - name: create a github deployment - id: deployment - uses: avakar/create-deployment@v1 - with: - ref: ${{ github.head_ref }} - environment: ${{ env.BUILD_ENV_NAME }} - transient_environment: true - auto_merge: false - env: - GITHUB_TOKEN: ${{ secrets.DEPLOY_TOKEN }} - - - uses: avakar/set-deployment-status@v1 - with: - state: in_progress - deployment_id: ${{ steps.deployment.output.deployment_id }} - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - + - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} @@ -93,21 +73,16 @@ jobs: ALGOLIA_INDEX_NAME: edb-docs-staging INDEX_ON_BUILD: false - - name: Netlify deploy - run: | - sudo yarn global add netlify-cli - netlify deploy --dir=public --json | tee deploy_results.json - echo "NETLIFY_DRAFT_URL=`jq -r '.deploy_url' deploy_results.json`" >> $GITHUB_ENV + - name: Deploy to Netlify + id: netlify-deploy + uses: nwtgck/actions-netlify@v1.2.2 + with: + publish-dir: './public' + github-token: ${{ secrets.GITHUB_TOKEN }} + deploy-message: ${{ github.event.pull_request.title }} + enable-commit-comment: false + github-deployment-environment: ${{ env.BUILD_ENV_NAME }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} - NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_DEVELOP_SITE_ID }} - - name: update the github deployment status - uses: bobheadxi/deployments@v0.5.2 - if: always() - with: - step: finish - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - deployment_id: ${{ steps.deployment.outputs.deployment_id }} - env_url: ${{ steps.netlify-deploy.outputs.deploy-url }} \ No newline at end of file From 3accf4b8a9aa4dc587d29160457be618bcef70fa Mon Sep 17 00:00:00 2001 From: Josh Heyer <63653723+josh-heyer@users.noreply.github.com> Date: Mon, 9 Aug 2021 14:05:27 -0700 Subject: [PATCH 15/15] Automerge let me down (removed broken and superfluous code block) Former-commit-id: ecb82fbe9e0b6f2268a97d392bfb026efe83ac9e --- gatsby-node.js | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 70995caaed6..ec6000a6ded 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -54,23 +54,6 @@ const gitData = (() => { return { branch, sha }; })(); -const currentBranchName = (() => { - // if this build was triggered by a GH action in response to a PR, - // use the head ref (the branch that someone is requesting be merged) - let branch = process.env.GITHUB_HEAD_REF; - // if this process was otherwise triggered by a GH action, use the current branch name - if (!branch) branch = process.env.GITHUB_REF; - // non-GH Action build? Try actually running Git for the name... - if (!branch) { - try { - branch = execSync("git rev-parse --abbrev-ref HEAD").toString(); - } catch {} - } - if (!branch) branch = isProduction ? "main" : "develop"; - - return branch.replace(/^refs\/heads\//, "").replace(/^refs\/tags\//, ""); -})(); - exports.onCreateNode = async ({ node, getNode, actions, loadNodeContent }) => { const { createNodeField } = actions;