|
| 1 | +name: Deploy to production |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +jobs: |
| 7 | + build: |
| 8 | + if: "github.repository == 'arduino/docs-content'" |
| 9 | + runs-on: ubuntu-latest |
| 10 | + env: |
| 11 | + REPO_ACCESS_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }} |
| 12 | + APP_ENV: prod |
| 13 | + |
| 14 | + steps: |
| 15 | + - uses: actions/checkout@v2 |
| 16 | + - uses: actions/setup-node@v2 |
| 17 | + with: |
| 18 | + node-version: 14 |
| 19 | + cache: "npm" |
| 20 | + cache-dependency-path: "**/package-lock.json" |
| 21 | + |
| 22 | + - name: Gatsby main cache |
| 23 | + uses: actions/cache@v1 |
| 24 | + id: gatsby-cache-folder |
| 25 | + with: |
| 26 | + path: .cache |
| 27 | + key: ${{ runner.os }}-cache-gatsby-${{ github.sha }} |
| 28 | + restore-keys: | |
| 29 | + ${{ runner.os }}-cache-gatsby- |
| 30 | +
|
| 31 | + - name: Gatsby Public Folder |
| 32 | + uses: actions/cache@v1 |
| 33 | + id: gatsby-public-folder |
| 34 | + with: |
| 35 | + path: public/ |
| 36 | + key: ${{ runner.os }}-public-gatsby-${{ github.sha }} |
| 37 | + restore-keys: | |
| 38 | + ${{ runner.os }}-public-gatsby- |
| 39 | +
|
| 40 | + - run: npm install |
| 41 | + |
| 42 | + - run: npm run build |
| 43 | + |
| 44 | + - name: Configure AWS Credentials |
| 45 | + uses: aws-actions/configure-aws-credentials@v1 |
| 46 | + with: |
| 47 | + aws-access-key-id: ${{ secrets.PROD_AWS_ACCESS_KEY_ID }} |
| 48 | + aws-secret-access-key: ${{ secrets.PROD_AWS_SECRET_ACCESS_KEY }} |
| 49 | + aws-region: us-west-1 |
| 50 | + |
| 51 | + - name: Sync all cacheable assets |
| 52 | + run: |
| 53 | + 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.PROD_AWS_S3_BUCKET_NAME }}/ |
| 54 | + # Don't cache any HTML or JSON file: they should always be up-to-date |
| 55 | + - name: Sync all non-cacheable assets |
| 56 | + 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.PROD_AWS_S3_BUCKET_NAME }}/ |
0 commit comments