forked from expo/expo
-
Notifications
You must be signed in to change notification settings - Fork 0
130 lines (122 loc) · 5.48 KB
/
docs-pr.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
name: Docs Website PR
defaults:
run:
shell: bash
working-directory: docs
on:
workflow_dispatch: {}
push:
paths:
- '.github/workflows/docs-pr.yml'
- '.github/workflows/docs-pr-destroy.yml'
pull_request:
paths:
- 'docs/**'
- '.github/workflows/docs-pr.yml'
- '.github/workflows/docs-pr-destroy.yml'
types:
- opened
- labeled
- synchronize
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.ref }}
cancel-in-progress: true
jobs:
docs-pr:
runs-on: ubuntu-22.04
steps:
- name: 👀 Checkout
uses: actions/checkout@v4
- name: ⬢ Setup Node
uses: actions/setup-node@v4
with:
node-version: 20
- name: ♻️ Restore caches
uses: ./.github/actions/expo-caches
id: expo-caches
with:
yarn-docs: 'true'
- name: ➕ Add `bin` to GITHUB_PATH
run: echo "$(pwd)/bin" >> $GITHUB_PATH
- name: 🧶 Yarn install
if: steps.expo-caches.outputs.yarn-docs-hit != 'true'
run: yarn install --frozen-lockfile
- name: 🧪 Run Docs tests
run: yarn test
- name: 🚨 Lint Docs website code
env:
NODE_ENV: production
run: yarn lint --max-warnings 0
- name: 💬 Lint Docs website content
uses: errata-ai/vale-action@reviewdog
with:
reporter: github-pr-check
files: 'docs/pages'
vale_flags: '--config=./docs/.vale.ini'
fail_on_error: true
- name: 🏗️ Build Docs website
run: yarn export-preview
timeout-minutes: 20
env:
AWS_BUCKET: 'docs.expo.dev-pr-${{ github.event.pull_request.number }}'
- name: 🔗 Lint pages links
working-directory: docs
run: yarn lint-links --quiet
- name: 🪣 Set up docs preview bucket
if: contains(github.event.pull_request.labels.*.name, 'preview')
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'us-east-1'
run: |
# Create bucket
aws s3api create-bucket --bucket docs.expo.dev-pr-${{ github.event.pull_request.number }}
# Set "block public access" to off
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"
# Set bucket policy to public
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 }}/*\"}]}"
# Tag bucket to tell compliance monitoring that it is intended to be public
aws s3api put-bucket-tagging --bucket docs.expo.dev-pr-${{ github.event.pull_request.number }} --tagging "{\"TagSet\":[{\"Key\":\"DrataExclude\",\"Value\":\"This is a test instance of our public docs page and is intended to be public.\"}]}"
# Set up static website hosting
aws s3 website s3://docs.expo.dev-pr-${{ github.event.pull_request.number }}/ --index-document index.html
- name: 🚀 Deploy Docs website
if: contains(github.event.pull_request.labels.*.name, 'preview')
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: 'us-east-1'
AWS_BUCKET: docs.expo.dev-pr-${{ github.event.pull_request.number }}
run: ./deploy.sh
- name: 🔍 Find old comment if it exists
if: contains(github.event.pull_request.labels.*.name, 'preview')
uses: peter-evans/find-comment@v3
id: old_comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: 'expo-bot'
body-includes: 📘 Your docs
- name: 💬 Add comment with preview URL
if: contains(github.event.pull_request.labels.*.name, 'preview') && steps.old_comment.outputs.comment-id == ''
uses: actions/github-script@v7
with:
github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '📘 Your docs [preview website](http://docs.expo.dev-pr-${{ github.event.pull_request.number }}.s3-website-us-east-1.amazonaws.com/) is ready!'
});
- name: 💬 Update comment with preview URL
if: contains(github.event.pull_request.labels.*.name, 'preview') && steps.old_comment.outputs.comment-id != ''
uses: actions/github-script@v7
with:
github-token: ${{ secrets.EXPO_BOT_GITHUB_TOKEN }}
script: |
github.rest.issues.updateComment({
issue_number: context.issue.number,
comment_id: '${{ steps.old_comment.outputs.comment-id }}',
owner: context.repo.owner,
repo: context.repo.repo,
body: '📘 Your docs [preview website](http://docs.expo.dev-pr-${{ github.event.pull_request.number }}.s3-website-us-east-1.amazonaws.com/) is ready!'
});