|
| 1 | +name: Preview Deployment |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + pull_request: |
| 8 | + types: [opened, synchronize, labeled] |
| 9 | + |
| 10 | +concurrency: |
| 11 | + group: netlify-${{ github.workflow }}-${{ github.ref }} |
| 12 | + cancel-in-progress: true |
| 13 | + |
| 14 | +jobs: |
| 15 | + run: |
| 16 | + if: contains(github.event.pull_request.labels.*.name, 'preview') || ${{ github.ref_name == 'main' }} |
| 17 | + runs-on: ubuntu-latest |
| 18 | + concurrency: |
| 19 | + group: netlify |
| 20 | + cancel-in-progress: false |
| 21 | + env: |
| 22 | + REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} |
| 23 | + APP_ENV: prod |
| 24 | + BRANCH_NAME: ${{ github.ref_name }} |
| 25 | + |
| 26 | + steps: |
| 27 | + |
| 28 | + - name: Find PR Preview Comment |
| 29 | + if: github.event_name == 'pull_request' |
| 30 | + uses: peter-evans/find-comment@v1 |
| 31 | + id: deploy-preview-comment |
| 32 | + with: |
| 33 | + issue-number: ${{ github.event.pull_request.number }} |
| 34 | + comment-author: "github-actions[bot]" |
| 35 | + body-includes: "Preview Deployment" |
| 36 | + |
| 37 | + - name: Update Comment if exists |
| 38 | + if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 |
| 39 | + uses: peter-evans/create-or-update-comment@v1.4.5 |
| 40 | + with: |
| 41 | + comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} |
| 42 | + edit-mode: replace |
| 43 | + body: | |
| 44 | + ## Preview Deployment |
| 45 | + Waiting for deployment to complete... |
| 46 | +
|
| 47 | + - uses: actions/checkout@v4 |
| 48 | + |
| 49 | + - uses: actions/setup-node@v4 |
| 50 | + with: |
| 51 | + node-version: 18 |
| 52 | + cache: "npm" |
| 53 | + cache-dependency-path: "**/package-lock.json" |
| 54 | + |
| 55 | + - name: Render Datasheets |
| 56 | + run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh |
| 57 | + |
| 58 | + - name: Copy Static Files |
| 59 | + run: | |
| 60 | + mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts |
| 61 | + find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \; |
| 62 | + find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \; |
| 63 | + find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \; |
| 64 | + find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \; |
| 65 | +
|
| 66 | + - name: Gatsby main cache |
| 67 | + uses: actions/cache@v4 |
| 68 | + id: gatsby-cache-folder |
| 69 | + with: |
| 70 | + path: .cache |
| 71 | + key: ${{ runner.os }}-cache-gatsby-${{ github.sha }} |
| 72 | + restore-keys: | |
| 73 | + ${{ runner.os }}-cache-gatsby- |
| 74 | +
|
| 75 | + - name: Gatsby Public Folder |
| 76 | + uses: actions/cache@v4 |
| 77 | + id: gatsby-public-folder |
| 78 | + with: |
| 79 | + path: public/ |
| 80 | + key: ${{ runner.os }}-public-gatsby-${{ github.sha }} |
| 81 | + restore-keys: | |
| 82 | + ${{ runner.os }}-public-gatsby- |
| 83 | +
|
| 84 | + - run: npm install |
| 85 | + - run: npm run build |
| 86 | + |
| 87 | + - name: Install Netlify |
| 88 | + run: npm install netlify-cli@17.23.2 -g |
| 89 | + |
| 90 | + - name: Deploy to Netlify Preview |
| 91 | + if: github.event_name == 'pull_request' |
| 92 | + run: | |
| 93 | + netlify deploy \ |
| 94 | + --dir public \ |
| 95 | + --site ${{ secrets.NETLIFY_SITE_ID }} \ |
| 96 | + --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ |
| 97 | + --json \ |
| 98 | + > deploy_output.json |
| 99 | +
|
| 100 | + - name: Deploy to Netlify Prod |
| 101 | + if: github.event_name != 'pull_request' |
| 102 | + run: | |
| 103 | + netlify deploy \ |
| 104 | + --prod \ |
| 105 | + --dir public \ |
| 106 | + --site ${{ secrets.NETLIFY_SITE_ID }} \ |
| 107 | + --auth ${{ secrets.NETLIFY_AUTH_TOKEN }} \ |
| 108 | + --json \ |
| 109 | + > deploy_output.json |
| 110 | + |
| 111 | + - name: Generate URL Preview |
| 112 | + if: github.event_name == 'pull_request' |
| 113 | + id: url_preview |
| 114 | + run: | |
| 115 | + NETLIFY_PREVIEW_URL=$(jq -r '.deploy_url' deploy_output.json) |
| 116 | + echo "NETLIFY_PREVIEW_URL=$NETLIFY_PREVIEW_URL" >> "$GITHUB_OUTPUT" |
| 117 | +
|
| 118 | + - name: Create PR Preview Comment |
| 119 | + if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id == 0 |
| 120 | + uses: peter-evans/create-or-update-comment@v1.4.5 |
| 121 | + with: |
| 122 | + issue-number: ${{ github.event.pull_request.number }} |
| 123 | + body: | |
| 124 | + ## Preview Deployment |
| 125 | + 🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} |
| 126 | + 📍 Commit SHA: ${{ github.sha }} |
| 127 | + |
| 128 | + - name: Update PR Preview Comment |
| 129 | + if: github.event_name == 'pull_request' && steps.deploy-preview-comment.outputs.comment-id != 0 |
| 130 | + uses: peter-evans/create-or-update-comment@v1.4.5 |
| 131 | + with: |
| 132 | + comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }} |
| 133 | + edit-mode: replace |
| 134 | + body: | |
| 135 | + ## Preview Deployment |
| 136 | + 🚀 Preview this PR: ${{ steps.url_preview.outputs.NETLIFY_PREVIEW_URL }} |
| 137 | + 📍 Commit SHA: ${{ github.sha }} |
0 commit comments