@@ -10,12 +10,50 @@ concurrency:
10
10
group : deploy-staging
11
11
cancel-in-progress : true
12
12
13
+ # Allow installation of dependencies
13
14
permissions :
14
15
id-token : write
15
16
contents : read
16
17
17
18
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
+
18
54
build :
55
+ name : Build and Deploy
56
+ needs : render-datasheets
19
57
runs-on : ubuntu-latest
20
58
environment : staging
21
59
env :
@@ -26,20 +64,23 @@ jobs:
26
64
- uses : actions/checkout@v4
27
65
with :
28
66
fetch-depth : 1
67
+
68
+ - name : Cleanup runner disk
69
+ uses : ./.github/actions/cleanup-disk # Cleanup machine before starting the build
70
+
29
71
- uses : actions/setup-node@v4
30
72
with :
31
73
node-version : 18
32
74
cache : " npm"
33
- cache-dependency-path : " **/ package-lock.json"
75
+ cache-dependency-path : " package-lock.json"
34
76
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
37
80
38
81
- name : Copy Static Files
39
82
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
43
84
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
44
85
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
45
86
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;
@@ -63,38 +104,27 @@ jobs:
63
104
${{ runner.os }}-public-gatsby-main
64
105
65
106
- run : npm install
107
+
66
108
- run : npm run build
67
109
68
- - name : Clean up node_modules
110
+ - name : Clean up node_modules # Just to save space
69
111
run : rm -rf node_modules
70
112
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
73
115
with :
74
116
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 }}
100
118
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