From 840da5e7ad1d546ff99db11ee5970649d624098c Mon Sep 17 00:00:00 2001 From: Luca Doglione Date: Mon, 6 May 2024 16:05:43 +0200 Subject: [PATCH 1/5] 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 2/5] 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 3/5] 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 4/5] 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 5/5] 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