xref: /expo/.github/workflows/docs-pr-deploy.yml (revision fe1ef024)
1
2name: docs-pr-deploy
3
4defaults:
5  run:
6    shell: bash
7    working-directory: docs
8
9on:
10  workflow_dispatch: {}
11  push:
12    paths:
13      - 'docs/**'
14      - '.github/workflows/docs-pr-deploy.yml'
15      - '.github/workflows/docs-pr-destroy.yml'
16  pull_request:
17    paths:
18      - 'docs/**'
19      - '.github/workflows/docs.yml'
20      - '.github/workflows/docs-pr-deploy.yml'
21      - '.github/workflows/docs-pr-destroy.yml'
22    types:
23      - labeled
24      - synchronize
25
26concurrency:
27  group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
28  cancel-in-progress: true
29
30jobs:
31  docs-pr-deploy:
32    if: contains(github.event.pull_request.labels.*.name, 'preview')
33    runs-on: ubuntu-20.04
34    steps:
35      - name: �� Checkout
36        uses: actions/checkout@v3
37      - name: ⬢ Setup Node
38        uses: actions/setup-node@v3
39        with:
40          node-version: 16.x
41      - name: ♻️ Restore caches
42        uses: ./.github/actions/expo-caches
43        id: expo-caches
44        with:
45          yarn-docs: 'true'
46      - name: ➕ Add `bin` to GITHUB_PATH
47        run: echo "$(pwd)/bin" >> $GITHUB_PATH
48      - name: �� Set up docs preview bucket
49        env:
50          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
51          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
52          AWS_DEFAULT_REGION: 'us-east-1'
53        run: |
54          # Create bucket
55          aws s3api create-bucket --bucket docs.expo.dev-pr-${{ github.event.pull_request.number }}
56
57          # Set "block public access" to off
58          aws s3api put-public-access-block --bucket docs.expo.dev-pr-${{ github.event.pull_request.number }} --public-access-block-configuration "BlockPublicAcls=false,IgnorePublicAcls=false,BlockPublicPolicy=false,RestrictPublicBuckets=false"
59
60          # Set bucket policy to public
61          aws s3api put-bucket-policy --bucket docs.expo.dev-pr-${{ github.event.pull_request.number }} --policy "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Sid\":\"\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Action\":\"s3:GetObject\",\"Resource\":\"arn:aws:s3:::docs.expo.dev-pr-${{ github.event.pull_request.number }}/*\"}]}"
62
63          # Set up static website hosting
64          aws s3 website s3://docs.expo.dev-pr-${{ github.event.pull_request.number }}/ --index-document index.html
65      - name: �� Yarn install
66        if: steps.expo-caches.outputs.yarn-docs-hit != 'true'
67        run: yarn install --frozen-lockfile
68      - run: yarn danger ci
69        env:
70          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
71      - name: ��️ Build Docs website for deploy
72        run: yarn export
73        timeout-minutes: 20
74        env:
75          AWS_BUCKET: 'docs.expo.dev-pr-${{ github.event.pull_request.number }}'
76      - name: �� Deploy Docs website
77        env:
78          AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
79          AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
80          AWS_DEFAULT_REGION: 'us-east-1'
81          AWS_BUCKET: docs.expo.dev-pr-${{ github.event.pull_request.number }}
82        run: ./deploy.sh
83      - name: �� Find old comment if it exists
84        uses: peter-evans/find-comment@v2
85        id: old_comment
86        with:
87          issue-number: ${{ github.event.pull_request.number }}
88          comment-author: 'expo-bot'
89          body-includes: �� Your docs
90      - name: �� Add comment with preview URL
91        if: steps.old_comment.outputs.comment-id == ''
92        uses: actions/github-script@v6
93        with:
94          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
95          script: |
96            github.rest.issues.createComment({
97              issue_number: context.issue.number,
98              owner: context.repo.owner,
99              repo: context.repo.repo,
100              body: '�� Your docs [preview website](http://docs.expo.dev-pr-${{ github.event.pull_request.number }}.s3-website-us-east-1.amazonaws.com/) is ready!'
101            });
102      - name: �� Update comment with preview URL
103        if: steps.old_comment.outputs.comment-id != ''
104        uses: actions/github-script@v6
105        with:
106          github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
107          script: |
108            github.rest.issues.updateComment({
109              issue_number: context.issue.number,
110              comment_id: '${{ steps.old_comment.outputs.comment-id }}',
111              owner: context.repo.owner,
112              repo: context.repo.repo,
113              body: '�� Your docs [preview website](http://docs.expo.dev-pr-${{ github.event.pull_request.number }}.s3-website-us-east-1.amazonaws.com/) is ready!'
114            });
115