From 840da5e7ad1d546ff99db11ee5970649d624098c Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Mon, 6 May 2024 16:05:43 +0200 Subject: [PATCH 01/10] Adding preview with Vercel --- .github/workflows/cloudflare.yml | 61 ---------------------- .github/workflows/vercel-preview.yml | 76 ++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 61 deletions(-) delete mode 100644 .github/workflows/cloudflare.yml create mode 100644 .github/workflows/vercel-preview.yml diff --git a/.github/workflows/cloudflare.yml b/.github/workflows/cloudflare.yml deleted file mode 100644 index 76b41caf10..0000000000 --- a/.github/workflows/cloudflare.yml +++ /dev/null @@ -1,61 +0,0 @@ -name: Cloudflare Pages - -on: - workflow_dispatch: - -jobs: - run: - runs-on: ubuntu-latest - env: - REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} - APP_ENV: prod - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: actions/setup-node@v3 - with: - node-version: 18 - cache: "npm" - cache-dependency-path: "**/package-lock.json" - - - name: Render Datasheets - run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh - - - name: Copy Static Files - run: | - mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts - find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \; - find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \; - find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \; - find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \; - - - name: Gatsby main cache - uses: actions/cache@v3 - id: gatsby-cache-folder - with: - path: .cache - key: ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-cache-gatsbyV2- - - - name: Gatsby Public Folder - uses: actions/cache@v3 - id: gatsby-public-folder - with: - path: public/ - key: ${{ runner.os }}-public-gatsbyV2-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-public-gatsbyV2- - - - run: npm install - - run: npm run build - - - name: Docs - uses: ./.github/actions/cloudflare-upload - with: - upload-dir: public - project-name: docs-content - cloudflare-api-token: ${{ secrets.CLOUDFLARE_API_TOKEN }} - cloudflare-account: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} diff --git a/.github/workflows/vercel-preview.yml b/.github/workflows/vercel-preview.yml new file mode 100644 index 0000000000..597f6722f9 --- /dev/null +++ b/.github/workflows/vercel-preview.yml @@ -0,0 +1,76 @@ +name: Vercel Preview Deployment + +on: + push: + branches: + - vercel-preview + pull_request: + types: [opened, synchronize] + +jobs: + run: + runs-on: ubuntu-latest + env: + REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID}} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID}} + APP_ENV: prod + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 18 + cache: "npm" + cache-dependency-path: "**/package-lock.json" + + - name: Render Datasheets + run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh + + - name: Copy Static Files + run: | + mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts + find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \; + find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \; + find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \; + find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \; + + - name: Gatsby main cache + uses: actions/cache@v4 + id: gatsby-cache-folder + with: + path: .cache + key: ${{ runner.os }}-cache-gatsbyV2-vercel-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-cache-gatsbyV2-vercel- + + - name: Gatsby Public Folder + uses: actions/cache@v4 + id: gatsby-public-folder + with: + path: public/ + key: ${{ runner.os }}-public-gatsbyV2-vercel-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-public-gatsbyV2-vercel- + + - run: npm install + - run: npm run build + + - name: Install Vercel CLI + run: npm install --global vercel@canary + - name: Pull Vercel Environment Information + run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} + - name: Build Project Artifacts + run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + + - uses: UnlyEd/github-action-deploy-on-vercel@latest + with: + command: "vercel deploy --archive=tgz --prebuilt --debug --token ${{ secrets.VERCEL_TOKEN }}" + env: + VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} + VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID}} + VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} + + - run: "echo \"Found deployment url: ${{ env.VERCEL_DEPLOYMENT_URL }}\"" From 805be6c7e22fa93397f22f7dfe0bc0c226e8972e Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Mon, 6 May 2024 16:11:06 +0200 Subject: [PATCH 02/10] Avoiding concurrent preview generation in order to keep cache safe --- .github/workflows/vercel-preview.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/vercel-preview.yml b/.github/workflows/vercel-preview.yml index 597f6722f9..532368b718 100644 --- a/.github/workflows/vercel-preview.yml +++ b/.github/workflows/vercel-preview.yml @@ -7,6 +7,10 @@ on: pull_request: types: [opened, synchronize] +concurrency: + group: vercel + cancel-in-progress: false + jobs: run: runs-on: ubuntu-latest From 71c6b2ef705d009ddc3bf83c78660ff1984d406a Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Tue, 7 May 2024 22:37:19 +0200 Subject: [PATCH 03/10] Goodbye Vercel! Hello Netlify --- .../{vercel-preview.yml => preview.yml} | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) rename .github/workflows/{vercel-preview.yml => preview.yml} (65%) diff --git a/.github/workflows/vercel-preview.yml b/.github/workflows/preview.yml similarity index 65% rename from .github/workflows/vercel-preview.yml rename to .github/workflows/preview.yml index 532368b718..3c4fc331dc 100644 --- a/.github/workflows/vercel-preview.yml +++ b/.github/workflows/preview.yml @@ -1,4 +1,4 @@ -name: Vercel Preview Deployment +name: Preview Deployment on: push: @@ -16,9 +16,6 @@ jobs: runs-on: ubuntu-latest env: REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID}} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID}} APP_ENV: prod steps: @@ -62,19 +59,14 @@ jobs: - run: npm install - run: npm run build - - name: Install Vercel CLI - run: npm install --global vercel@canary - - name: Pull Vercel Environment Information - run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} - - name: Build Project Artifacts - run: vercel build --token=${{ secrets.VERCEL_TOKEN }} + - name: Install Netlify + run: npm install netlify-cli@17.23.2 -g - - uses: UnlyEd/github-action-deploy-on-vercel@latest - with: - command: "vercel deploy --archive=tgz --prebuilt --debug --token ${{ secrets.VERCEL_TOKEN }}" - env: - VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }} - VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID}} - VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} - - - run: "echo \"Found deployment url: ${{ env.VERCEL_DEPLOYMENT_URL }}\"" + - name: Deploy to Netlify + id: netlify_deploy + run: | + netlify deploy \ + --dir public \ + --site ${{ secrets.NETLIFY_SITE_ID }} \ + --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ + --json \ No newline at end of file From 045f62b651e1b630583531e140027766a8ec5931 Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Wed, 8 May 2024 10:32:36 +0200 Subject: [PATCH 04/10] Filtering pr - building preview only on specific labels --- .github/workflows/preview.yml | 69 ++++++++++++++++++++++++++++++----- 1 file changed, 59 insertions(+), 10 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 3c4fc331dc..3009a15840 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,24 +1,45 @@ name: Preview Deployment on: - push: - branches: - - vercel-preview pull_request: - types: [opened, synchronize] + types: [opened, synchronize, labeled] concurrency: - group: vercel + group: netlify cancel-in-progress: false jobs: run: + if: contains(github.event.pull_request.labels.*.name, 'preview') runs-on: ubuntu-latest + concurrency: + group: netlify-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true env: REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} APP_ENV: prod steps: + + - name: Find PR Preview Comment + if: github.event_name == 'pull_request' + uses: peter-evans/find-comment@v1 + id: deploy-preview-comment + with: + issue-number: ${{ github.event.pull_request.number }} + comment-author: "github-actions[bot]" + body-includes: "Preview this PR" + + - name: Update Comment if exists + if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 + uses: peter-evans/create-or-update-comment@v1.4.5 + with: + comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} + edit-mode: replace + body: | + ## Preview Deployment + Waiting for deployment to complete... + - uses: actions/checkout@v4 - uses: actions/setup-node@v4 @@ -43,18 +64,18 @@ jobs: id: gatsby-cache-folder with: path: .cache - key: ${{ runner.os }}-cache-gatsbyV2-vercel-${{ github.sha }} + key: ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }} restore-keys: | - ${{ runner.os }}-cache-gatsbyV2-vercel- + ${{ runner.os }}-cache-gatsbyV2- - name: Gatsby Public Folder uses: actions/cache@v4 id: gatsby-public-folder with: path: public/ - key: ${{ runner.os }}-public-gatsbyV2-vercel-${{ github.sha }} + key: ${{ runner.os }}-public-gatsbyV2-${{ github.sha }} restore-keys: | - ${{ runner.os }}-public-gatsbyV2-vercel- + ${{ runner.os }}-public-gatsbyV2- - run: npm install - run: npm run build @@ -69,4 +90,32 @@ jobs: --dir public \ --site ${{ secrets.NETLIFY_SITE_ID }} \ --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ - --json \ No newline at end of file + --json \ + > deploy_output.json + + - name: Generate URL Preview + id: url_preview + run: | + NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) + echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" + + - name: Create PR Preview Comment + if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id == 0 + uses: peter-evans/create-or-update-comment@v1.4.5 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + ## Preview Deployment + 🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} + 📍 Commit SHA: ${{ github.sha }} + + - name: Update PR Preview Comment + if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 + uses: peter-evans/create-or-update-comment@v1.4.5 + with: + comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} + edit-mode: replace + body: | + ## Preview Deployment + 🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} + 📍 Commit SHA: ${{ github.sha }} \ No newline at end of file From 960dba98c8f5a36ea86cd65e9135dcb90438a1a2 Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Wed, 8 May 2024 15:34:19 +0200 Subject: [PATCH 05/10] Refining concurrency for preview workflow --- .github/workflows/preview.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 3009a15840..6375335198 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -5,16 +5,16 @@ on: types: [opened, synchronize, labeled] concurrency: - group: netlify - cancel-in-progress: false + group: netlify-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true jobs: run: if: contains(github.event.pull_request.labels.*.name, 'preview') runs-on: ubuntu-latest concurrency: - group: netlify-${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true + group: netlify + cancel-in-progress: false env: REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} APP_ENV: prod From 5dce1f53e174c6619c4f24c04fda2896452fdc1b Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Thu, 9 May 2024 11:02:58 +0200 Subject: [PATCH 06/10] Adding preview also for main branch --- .github/workflows/preview.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 6375335198..a4fc3cb4af 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,6 +1,9 @@ name: Preview Deployment on: + push: + branches: + - main pull_request: types: [opened, synchronize, labeled] @@ -10,7 +13,7 @@ concurrency: jobs: run: - if: contains(github.event.pull_request.labels.*.name, 'preview') + if: contains(github.event.pull_request.labels.*.name, 'preview') || ${{ github.ref_name == 'main' }} runs-on: ubuntu-latest concurrency: group: netlify @@ -18,6 +21,7 @@ jobs: env: REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} APP_ENV: prod + BRANCH_NAME: ${{ github.ref_name }} steps: @@ -83,10 +87,21 @@ jobs: - name: Install Netlify run: npm install netlify-cli@17.23.2 -g - - name: Deploy to Netlify - id: netlify_deploy + - name: Deploy to Netlify Preview + if: github.event_name == 'pull_request' + run: | + netlify deploy \ + --dir public \ + --site ${{ secrets.NETLIFY_SITE_ID }} \ + --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ + --json \ + > deploy_output.json + + - name: Deploy to Netlify Prod + if: github.event_name != 'pull_request' run: | netlify deploy \ + --prod \ --dir public \ --site ${{ secrets.NETLIFY_SITE_ID }} \ --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ @@ -94,6 +109,7 @@ jobs: > deploy_output.json - name: Generate URL Preview + if: github.event_name == 'pull_request' id: url_preview run: | NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) From 98aebe1dce261f692219d08a8e6c2c96d66fe872 Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Thu, 9 May 2024 15:23:37 +0200 Subject: [PATCH 07/10] Changing comment strategy --- .github/workflows/preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index a4fc3cb4af..81278eeaa1 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -32,7 +32,7 @@ jobs: with: issue-number: ${{ github.event.pull_request.number }} comment-author: "github-actions[bot]" - body-includes: "Preview this PR" + body-includes: "Preview Deployment" - name: Update Comment if exists if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 From 2ba6146d649c8446058b7f485aff20b9ccdb051f Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Thu, 9 May 2024 16:47:46 +0200 Subject: [PATCH 08/10] Updating README file --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fbf2b09e5e..0032ef01b3 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Broken URLs will show an error alert. URL must be in the GitHub domain and must ## Previewing Changes -Whenever you create a Pull Request (PR) GatsbyCloud will create a preview deployment in which you can see how your changes look when rendered on the website. The link to the preview will appear in the comments of the PR. This also works with Draft PRs, but not for PRs created from a fork. +Whenever you create a Pull Request (PR) and the label preview is assigned to it, a preview is created and updated for every commit, as explained at: https://github.com/arduino/docs-content/pull/1931 ## License From 0a9536b6bec7929e0349fb26a6ff93f61f3fad5e Mon Sep 17 00:00:00 2001 From: Luca Doglione <16229663+lukdog@users.noreply.github.com> Date: Mon, 20 May 2024 14:28:09 +0200 Subject: [PATCH 09/10] Update README.md Co-authored-by: Josefine Herlin <66409231+jhansson-ard@users.noreply.github.com> --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0032ef01b3..68d4d92229 100644 --- a/README.md +++ b/README.md @@ -94,7 +94,7 @@ Broken URLs will show an error alert. URL must be in the GitHub domain and must ## Previewing Changes -Whenever you create a Pull Request (PR) and the label preview is assigned to it, a preview is created and updated for every commit, as explained at: https://github.com/arduino/docs-content/pull/1931 +Whenever you create a Pull Request (PR) and the label `preview` is assigned to it, a preview is created and updated for every commit, as explained at: https://github.com/arduino/docs-content/pull/1931 ## License From 11635c4c7384f22904b77d4742a144697a495a49 Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Mon, 20 May 2024 14:52:37 +0200 Subject: [PATCH 10/10] Using right cache also for preview --- .github/workflows/preview.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 81278eeaa1..5a62cb3ea6 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -68,18 +68,18 @@ jobs: id: gatsby-cache-folder with: path: .cache - key: ${{ runner.os }}-cache-gatsbyV2-${{ github.sha }} + key: ${{ runner.os }}-cache-gatsby-${{ github.sha }} restore-keys: | - ${{ runner.os }}-cache-gatsbyV2- + ${{ runner.os }}-cache-gatsby- - name: Gatsby Public Folder uses: actions/cache@v4 id: gatsby-public-folder with: path: public/ - key: ${{ runner.os }}-public-gatsbyV2-${{ github.sha }} + key: ${{ runner.os }}-public-gatsby-${{ github.sha }} restore-keys: | - ${{ runner.os }}-public-gatsbyV2- + ${{ runner.os }}-public-gatsby- - run: npm install - run: npm run build