Skip to content

Commit 329b7df

Browse files
committed
Split CI build
1 parent face5ba commit 329b7df

File tree

4 files changed

+144
-34
lines changed

4 files changed

+144
-34
lines changed
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Disk cleanup
2+
description: "Cleanup disk space"
3+
runs:
4+
using: composite
5+
steps:
6+
- name: Free up disk space
7+
shell: bash
8+
run: |
9+
echo "Disk space before cleanup..."
10+
df -h /
11+
echo "Removing unnecessary files to free up disk space..."
12+
# https://github.com/actions/runner-images/issues/2840#issuecomment-2272410832
13+
sudo rm -rf \
14+
/opt/hostedtoolcache \
15+
/opt/google/chrome \
16+
/opt/microsoft/msedge \
17+
/opt/microsoft/powershell \
18+
/opt/pipx \
19+
/usr/lib/mono \
20+
/usr/local/julia* \
21+
/usr/local/lib/android \
22+
/usr/local/lib/node_modules \
23+
/usr/local/share/chromium \
24+
/usr/local/share/powershell \
25+
/usr/share/dotnet \
26+
/usr/share/swift
27+
echo "Disk space after cleanup..."
28+
df -h /
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: Purge Cloudflare Cache
2+
description: "Purge Cloudflare Cache"
3+
inputs:
4+
zone:
5+
description: "The Cloudflare Zone ID"
6+
required: true
7+
api-token:
8+
description: "The Cloudflare API Token with purge cache permission"
9+
required: true
10+
prefix:
11+
description: "The prefix to purge cache"
12+
required: true
13+
runs:
14+
using: composite
15+
steps:
16+
- name: Purge Cloudflare Cache
17+
shell: bash
18+
run: |
19+
curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ inputs.zone }}/purge_cache" \
20+
-H "Authorization: Bearer ${{ inputs.api-token }}" \
21+
-H "Content-Type: application/json" \
22+
--data '{"prefixes":["${{ inputs.prefix }}"]}'

.github/actions/sync-s3/action.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Sync assets on S3
2+
description: "Sync Docs assets on S3"
3+
inputs:
4+
role-to-assume:
5+
description: "The IAM role to assume"
6+
required: true
7+
bucket-name:
8+
description: "The name of the S3 bucket to sync assets to"
9+
required: true
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Configure AWS credentials from Staging account
14+
uses: aws-actions/configure-aws-credentials@v4
15+
with:
16+
role-to-assume: ${{ inputs.role-to-assume }}
17+
aws-region: us-east-1
18+
19+
- name: Sync all cacheable assets
20+
shell: bash
21+
run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ inputs.bucket-name }}/
22+
23+
- name: Sync all non-cacheable assets
24+
shell: bash
25+
# Don't cache any HTML or JSON file: they should always be up-to-dates
26+
run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ inputs.bucket-name }}/
27+
28+
- name: Sync PDF
29+
shell: bash
30+
run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ inputs.bucket-name }}/

.github/workflows/deploy-staging.yml

+64-34
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,50 @@ concurrency:
1010
group: deploy-staging
1111
cancel-in-progress: true
1212

13+
# Allow installation of dependencies
1314
permissions:
1415
id-token: write
1516
contents: read
1617

1718
jobs:
19+
# This job is used to render datasheets, but only if they have changed.
20+
# It's a separate job so we don't have to cleanup the machine afterwards.
21+
render-datasheets:
22+
name: Render Datasheets
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
with:
27+
fetch-depth: 1
28+
29+
- uses: actions/setup-node@v4
30+
with:
31+
node-version: 18
32+
cache: "npm"
33+
cache-dependency-path: "package-lock.json"
34+
35+
- uses: actions/cache@v4
36+
id: cache
37+
with:
38+
path: static/resources/datasheets
39+
key: ${{ runner.os }}-datasheets-${{ hashFiles('**/*datasheet.md') }}
40+
41+
- name: Render Datasheets
42+
if: steps.cache.outputs.cache-hit != 'true'
43+
run: |
44+
cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh
45+
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
46+
47+
- name: Export artifact
48+
uses: actions/upload-artifact@v4
49+
with:
50+
name: datasheets
51+
path: static/resources/datasheets
52+
retention-days: 1 # Only needed to pass it to the next job
53+
1854
build:
55+
name: Build and Deploy
56+
needs: render-datasheets
1957
runs-on: ubuntu-latest
2058
environment: staging
2159
env:
@@ -26,20 +64,23 @@ jobs:
2664
- uses: actions/checkout@v4
2765
with:
2866
fetch-depth: 1
67+
68+
- name: Cleanup runner disk
69+
uses: ./.github/actions/cleanup-disk # Cleanup machine before starting the build
70+
2971
- uses: actions/setup-node@v4
3072
with:
3173
node-version: 18
3274
cache: "npm"
33-
cache-dependency-path: "**/package-lock.json"
75+
cache-dependency-path: "package-lock.json"
3476

35-
- name: Render Datasheets
36-
run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh
77+
- uses: actions/download-artifact@v4
78+
with:
79+
name: datasheets
3780

3881
- name: Copy Static Files
3982
run: |
40-
mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts static/resources/models
41-
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
42-
find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \;
83+
mkdir -p static/resources/schematics static/resources/pinouts static/resources/models
4384
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
4485
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
4586
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;
@@ -63,38 +104,27 @@ jobs:
63104
${{ runner.os }}-public-gatsby-main
64105
65106
- run: npm install
107+
66108
- run: npm run build
67109

68-
- name: Clean up node_modules
110+
- name: Clean up node_modules # Just to save space
69111
run: rm -rf node_modules
70112

71-
- name: Configure AWS credentials from Staging account
72-
uses: aws-actions/configure-aws-credentials@v4
113+
- name: Deploy to S3
114+
uses: ./.github/actions/sync-s3
73115
with:
74116
role-to-assume: ${{ secrets.STAGING_IAM_ROLE }}
75-
aws-region: us-east-1
76-
77-
# - name: Sync all cacheable assets
78-
# run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/
79-
80-
# - name: Sync all non-cacheable assets
81-
# # Don't cache any HTML or JSON file: they should always be up-to-dates
82-
# run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.pdf" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/
83-
84-
# - name: Sync PDF
85-
# run: aws s3 sync --cache-control "public, max-age=86400, must-revalidate" --include "*.pdf" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --exclude="*.css" --exclude="*.html" --exclude="*.json" --exclude="sw.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/
86-
87-
# - name: Purge cache on CloudFlare
88-
# run: |
89-
# curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \
90-
# -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \
91-
# -H "Content-Type: application/json" \
92-
# --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}'
93-
94-
- name: Sync all cacheable assets
95-
run: aws s3 sync --cache-control "public, max-age=31536000, immutable" --include "*.css" --include="*.js" --include="*.gif" --include="*.png" --include="*.svg" --exclude "*.html" --exclude="sw.js" --exclude="*.json" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/
96-
97-
- name: Sync all non-cacheable assets
98-
# Don't cache any HTML or JSON file: they should always be up-to-dates
99-
run: aws s3 sync --cache-control "public, max-age=0, must-revalidate" --include "*.html" --include="sw.js" --include="*.json" --include "*.css" --exclude="*.js" --exclude="*.gif" --exclude="*.png" --exclude="*.svg" --delete public/ s3://${{ secrets.STAGING_BUCKET_NAME }}/
117+
bucket-name: ${{ secrets.STAGING_BUCKET_NAME }}
100118

119+
purge-datasheets:
120+
name: Purge Datasheets cache
121+
needs: build
122+
runs-on: ubuntu-latest
123+
environment: staging
124+
steps:
125+
- name: Invalidate datasheets cache
126+
uses: ./.github/actions/cloudflare-purge
127+
with:
128+
api-token: ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}
129+
zone: ${{ secrets.CLOUDFLARE_ZONE }}
130+
prefix: ${{ vars.DATASHEETS_BASE_URL }}

0 commit comments

Comments
 (0)