Skip to content

Commit 3281565

Browse files
committed
Update production workflow, too
1 parent 96d1694 commit 3281565

File tree

1 file changed

+46
-36
lines changed

1 file changed

+46
-36
lines changed

.github/workflows/deploy-production.yml

+46-36
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,57 @@ concurrency:
1010
group: deploy-production
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: ./.github/actions/generated-datasheets
26+
with:
27+
artifact-name: datasheets
28+
datasheets-path: static/resources/datasheets
29+
1830
build:
19-
if: "github.repository == 'arduino/docs-content'"
31+
name: Build and Deploy
32+
needs: render-datasheets
2033
runs-on: ubuntu-latest
2134
environment: production
2235
env:
2336
REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
24-
APP_ENV: prod
37+
APP_ENV: production
2538

2639
steps:
2740
- uses: actions/checkout@v4
2841
with:
2942
fetch-depth: 1
43+
44+
- name: Cleanup runner disk
45+
uses: ./.github/actions/cleanup-disk # Cleanup machine before starting the build
46+
3047
- uses: actions/setup-node@v4
3148
with:
3249
node-version: 18
3350
cache: "npm"
34-
cache-dependency-path: "**/package-lock.json"
51+
cache-dependency-path: "package-lock.json"
52+
53+
- name: Retrieve Datasheets
54+
uses: actions/download-artifact@v4 # Retrieve the datasheets generated in the previous job
55+
with:
56+
name: datasheets
3557

36-
- name: Render Datasheets
37-
run: cd ${GITHUB_WORKSPACE}/scripts/datasheet-rendering;./render-datasheets.sh
58+
- name: Debug datasheet list
59+
run: ls -lah static/resources/datasheets
3860

3961
- name: Copy Static Files
4062
run: |
41-
mkdir -p static/resources/datasheets static/resources/schematics static/resources/pinouts static/resources/models
42-
find ./content/hardware -type f -name "*-schematics.pdf" -exec cp {} ./static/resources/schematics/ \;
43-
find ./content/hardware -type f -name "*-datasheet.pdf" -exec cp {} ./static/resources/datasheets/ \;
63+
mkdir -p static/resources/schematics static/resources/pinouts static/resources/models
4464
find ./content/hardware -type f -name "*-full-pinout.pdf" -exec cp {} ./static/resources/pinouts/ \;
4565
find ./content/hardware -type f -name "*-pinout.png" -exec cp {} ./static/resources/pinouts/ \;
4666
find ./content/hardware -type f -name "*-step.zip" -exec cp {} ./static/resources/models/ \;
@@ -54,7 +74,7 @@ jobs:
5474
restore-keys: |
5575
${{ runner.os }}-cache-gatsby-main
5676
57-
- name: Gatsby Public Folder
77+
- name: Gatsby Public Folder cache
5878
uses: actions/cache@v4
5979
id: gatsby-public-folder
6080
with:
@@ -64,37 +84,27 @@ jobs:
6484
${{ runner.os }}-public-gatsby-main
6585
6686
- run: npm install
87+
6788
- run: npm run build
6889

69-
- name: Clean up node_modules
90+
- name: Clean up node_modules # Just to save space
7091
run: rm -rf node_modules
7192

72-
- name: Configure AWS credentials from Production account
73-
uses: aws-actions/configure-aws-credentials@v4
93+
- name: Deploy to S3
94+
uses: ./.github/actions/sync-s3
7495
with:
7596
role-to-assume: ${{ secrets.PRODUCTION_IAM_ROLE }}
76-
aws-region: us-east-1
97+
bucket-name: ${{ secrets.PRODUCTION_BUCKET_NAME }}
7798

78-
- name: Sync all cacheable assets
79-
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.PRODUCTION_BUCKET_NAME }}/
80-
81-
- name: Sync all non-cacheable assets
82-
# Don't cache any HTML or JSON file: they should always be up-to-dates
83-
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.PRODUCTION_BUCKET_NAME }}/
84-
85-
# - name: Sync PDF
86-
# 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.PRODUCTION_BUCKET_NAME }}/
87-
88-
# - name: Purge cache on CloudFlare
89-
# run: |
90-
# curl -X POST "https://api.cloudflare.com/client/v4/zones/${{ secrets.CLOUDFLARE_ZONE }}/purge_cache" \
91-
# -H "Authorization: Bearer ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}" \
92-
# -H "Content-Type: application/json" \
93-
# --data '{"prefixes":["${{ vars.DATASHEETS_BASE_URL }}"]}'
94-
95-
- name: Sync all cacheable assets
96-
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.PRODUCTION_BUCKET_NAME }}/
97-
98-
- name: Sync all non-cacheable assets
99-
# Don't cache any HTML or JSON file: they should always be up-to-dates
100-
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.PRODUCTION_BUCKET_NAME }}/
99+
purge-datasheets:
100+
name: Purge Datasheets cache
101+
needs: build
102+
runs-on: ubuntu-latest
103+
environment: production
104+
steps:
105+
- name: Invalidate datasheets cache
106+
uses: ./.github/actions/cloudflare-purge
107+
with:
108+
api-token: ${{ secrets.CLOUDFLARE_PURGE_API_TOKEN }}
109+
zone: ${{ secrets.CLOUDFLARE_ZONE }}
110+
prefix: ${{ vars.DATASHEETS_BASE_URL }}

0 commit comments

Comments
 (0)