-
Notifications
You must be signed in to change notification settings - Fork 222
147 lines (135 loc) · 4.99 KB
/
pr-deploy.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
name: Pull Request CI
env:
PATH_PREFIX: /docs/${{ github.ref }}
GATSBY_DEFAULT_MAIN_URL: https://staging.k6.io
GATSBY_DEFAULT_DOC_URL: https://mdr-ci.staging.k6.io/docs/${{ github.ref }}
GATSBY_DEFAULT_BLOG_URL: https://k6.io/blog
GATSBY_DEFAULT_APP_URL: https://app.staging.k6.io
GATSBY_NEWSLETTER_FORM_URL: https://go2.grafana.com
GATSBY_NEWSLETTER_FORM_MUNCHKIN_ID: 356-YFG-389
GATSBY_NEWSLETTER_FORM_ID: 1420
on:
pull_request:
branches: main
jobs:
lint:
name: Lint code
runs-on: ubuntu-latest
steps:
- name: Checkout project
uses: actions/checkout@v3
- name: Use Node.js 16.xs
uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Restore cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install dependencies
run: npm install
- name: Check formatting
run: |
npm run format
- name: Lint code
run: |
npm run lint
- name: Lint code examples
run: |
npm run lint:examples
lint-prose:
name: Lint prose
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: errata-ai/vale-action@reviewdog
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
with:
files: ./src/data/markdown
version: 2.17.0
fail_on_error: true
vale_flags: '--glob=**/{docs,translated-guides/en}/**/*.md'
build:
name: Build and deploy pull request
runs-on: ubuntu-latest
needs: lint
steps:
- uses: actions/checkout@v3
- name: Print build settings
run: |
echo "PATH_PREFIX: $PATH_PREFIX"
echo "GATSBY_DEFAULT_MAIN_URL: $GATSBY_DEFAULT_MAIN_URL"
echo "GATSBY_DEFAULT_DOC_URL: $GATSBY_DEFAULT_DOC_URL"
echo "GATSBY_DEFAULT_BLOG_URL: $GATSBY_DEFAULT_BLOG_URL"
echo "GATSBY_DEFAULT_APP_URL: $GATSBY_DEFAULT_APP_URL"
- name: Use Node.js 16.xs
uses: actions/setup-node@v3
with:
node-version: '16.x'
registry-url: 'https://registry.npmjs.org'
cache: 'npm'
- name: Restore node_modules cache
uses: actions/cache@v3
with:
path: '**/node_modules'
key: ${{ runner.os }}-modules-${{ hashFiles('**/package-lock.json') }}
- name: Install
run: npm install
- name: Restore build cache
uses: actions/cache@v3
with:
# Gatsby requires both .cache and public. It will refuse to use .cache/ if public/ is not present.
path: |
.cache
public
# Cache will not be used by Gatsby if the following files change:
# https://www.gatsbyjs.com/docs/build-caching/
key: pr-gatsby-${{ hashFiles('package.json', 'gatsby-config.js', 'gatsby-node.js') }}-${{ github.ref }}
restore-keys: |
pr-gatsby-${{ hashFiles('package.json', 'gatsby-config.js', 'gatsby-node.js') }}-
- name: Build
run: npm run build
- name: Sync to S3
id: upload
# Run only if PR does not come from a fork and it is not from dependabot.
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
uses: jakejarvis/s3-sync-action@v0.5.1
with:
args: --delete
env:
AWS_ACCESS_KEY_ID: ${{ secrets.PR_CI_AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_CI_AWS_SECRET_KEY }}
AWS_REGION: 'eu-west-1'
AWS_S3_BUCKET: ${{ secrets.PR_CI_AWS_S3_BUCKET }}
SOURCE_DIR: public/
DEST_DIR: docs/${{ github.ref }}
- name: Invalidate Cloudfront
# Run only if we did not skip the upload step
if: steps.upload.outcome == 'success'
uses: chetan/invalidate-cloudfront-action@v1.2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.PR_CI_AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.PR_CI_AWS_SECRET_KEY }}
AWS_REGION: 'eu-west-1'
DISTRIBUTION: ${{ secrets.PR_CI_CLOUDFRONT_DISTRIBUTION_ID }}
PATHS: '/docs/*'
- name: Post published URL to PR
# Run only if we did not skip the upload step and it's the first run for this PR.
if: steps.upload.outcome == 'success' && github.event.action == 'opened'
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
github.rest.issues.createComment({
issue_number: context.payload.number,
owner: context.repo.owner,
repo: context.repo.repo,
body:
"There's a version of the docs published here:\n\n" +
`${process.env.GATSBY_DEFAULT_DOC_URL}\n\n` +
'It will be deleted automatically in 30 days.',
})