-
Notifications
You must be signed in to change notification settings - Fork 537
202 lines (176 loc) · 7.55 KB
/
preview.yml
File metadata and controls
202 lines (176 loc) · 7.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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:
# This job is used to render datasheets, but only if they have changed.
# It's a separate job so we don't have to cleanup the machine afterwards.
render-datasheets:
name: Render Datasheets
if: ${{ contains(github.event.pull_request.labels.*.name, 'preview') || github.ref_name == 'main' }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
- uses: ./.github/actions/generate-datasheets
with:
artifact-name: datasheets
datasheets-path: static/resources/datasheets
preview-build:
if: ${{ contains(github.event.pull_request.labels.*.name, 'preview') || github.ref_name == 'main' }}
runs-on: ubuntu-latest
needs: render-datasheets
concurrency:
group: netlify
cancel-in-progress: false
env:
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
APP_ENV: staging
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
with:
fetch-depth: 1
- name: Cleanup runner disk
uses: ./.github/actions/cleanup-disk
- uses: actions/setup-node@v4
with:
node-version: 18
cache: "npm"
cache-dependency-path: "**/package-lock.json"
- name: Retrieve Datasheets
uses: actions/download-artifact@v4
with:
name: datasheets
path: static/resources/datasheets
- name: Copy Static Files
run: |
mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts static/resources/models
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/ \;
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;
# - name: Fail on Oversized Files
# id: fail_on_oversized_files
# run: |
# #!/bin/bash
# # This script is a stricter check that fails the workflow if files exceed size limits.
# set -e
# # Thresholds in Megabytes (same as the warning step)
# IMAGE_LIMIT_MB=2
# ASSET_LIMIT_MB=10
# # Find oversized files and prepare a detailed report
# OVERSIZED_FILES=$(find content -type f \
# \( \( -name "*.png" -o -name "*.jpg" -o -name "*.jpeg" -o -name "*.svg" -o -name "*.gif" \) -size "+${IMAGE_LIMIT_MB}M" \) -o \
# \( \( -name "*.pdf" -o -name "*.zip" -o -name "*.mp4" \) -size "+${ASSET_LIMIT_MB}M" \) \
# -exec ls -lh {} + | awk '{printf " - %s (%s)\n", $9, $5}')
# # Check if the report is non-empty and fail the job if so
# if [ -n "$OVERSIZED_FILES" ]; then
# echo "::error::Found files exceeding size limits. This new check is failing the build as intended."
# echo "--------------------------------------------------"
# echo "Oversized Files Found:"
# echo "$OVERSIZED_FILES"
# echo "--------------------------------------------------"
# echo "Limits:"
# echo " - Images (PNG, JPG, SVG, GIF): ${IMAGE_LIMIT_MB}MB"
# echo " - Assets (PDF, ZIP, MP4): ${ASSET_LIMIT_MB}MB"
# exit 1
# else
# echo "No oversized files found. New check passed."
# fi
- name: Compress Large Images
run: |
sudo apt-get update && sudo apt-get install -y jpegoptim optipng
echo "Compressing large JPGs..."
find content -type f \( -name "*.jpg" -o -name "*.jpeg" \) -size +2M -print -exec jpegoptim --strip-all {} \;
echo "Compressing large PNGs..."
find content -type f -name "*.png" -size +2M -print -exec optipng -o2 {} \;
- name: Gatsby main cache
uses: actions/cache@v4
id: gatsby-cache-folder
with:
path: .cache
key: ${{ runner.os }}-cache-gatsby-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-cache-gatsby-main
- name: Gatsby Public Folder
uses: actions/cache@v4
id: gatsby-public-folder
with:
path: public/
key: ${{ runner.os }}-public-gatsby-${{ github.ref_name }}
restore-keys: |
${{ runner.os }}-public-gatsby-main
- run: npm install
- run: GATSBY_HF_CDN_URL="" 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 }}