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/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 0000000000..5a62cb3ea6 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,137 @@ +name: Preview Deployment + +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize, labeled] + +concurrency: + group: netlify-${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + run: + if: contains(github.event.pull_request.labels.*.name, 'preview') || ${{ github.ref_name == 'main' }} + runs-on: ubuntu-latest + concurrency: + group: netlify + cancel-in-progress: false + env: + REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} + APP_ENV: prod + BRANCH_NAME: ${{ github.ref_name }} + + 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 Deployment" + + - 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 + 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-gatsby-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-cache-gatsby- + + - name: Gatsby Public Folder + uses: actions/cache@v4 + id: gatsby-public-folder + with: + path: public/ + key: ${{ runner.os }}-public-gatsby-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-public-gatsby- + + - run: npm install + - run: npm run build + + - name: Install Netlify + run: npm install netlify-cli@17.23.2 -g + + - 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 }} \ + --json \ + > 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) + 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 diff --git a/README.md b/README.md index fbf2b09e5e..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) 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