-
Notifications
You must be signed in to change notification settings - Fork 378
153 lines (124 loc) · 4.86 KB
/
website-preview.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
148
149
150
151
152
153
---
name: Website Preview
on:
pull_request_target:
types:
# not for "labeled" to prevent two builds for "labeled" and "unlabeled" when labels are changed
- unlabeled # if GitHub Actions stuck, add and remove "not ready" label to force rebuild
- opened
- reopened
- synchronize
# Do not run this workflow in parallel for any PR change
# to prevent concurrent pushes for the same Cloudflare domain alias.
concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
cancel-in-progress: false
env:
GOPATH: /home/runner/go
GOCACHE: /home/runner/go/cache
GOLANGCI_LINT_CACHE: /home/runner/go/cache/lint
GOMODCACHE: /home/runner/go/mod
GOPROXY: https://proxy.golang.org
GOTOOLCHAIN: local
jobs:
blog-preview:
name: Preview blog
runs-on: ubuntu-22.04
timeout-minutes: 10
if: >
contains(github.event.pull_request.labels.*.name, 'trust') &&
!contains(github.event.pull_request.labels.*.name, 'not ready') &&
(contains(github.event.pull_request.labels.*.name, 'blog/engineering') ||
contains(github.event.pull_request.labels.*.name, 'blog/marketing'))
environment:
name: cloudflare-dev-blog
url: ${{ steps.extract.outputs.extracted_url }}
steps:
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for wrangler to work
lfs: true
ref: ${{ github.event.pull_request.head.sha }}
# for Wrangler / Cloudflare Pages on pull_request_target
- name: Name branch
env:
BRANCH: ${{ github.head_ref }} # see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
run: git checkout -b $BRANCH
# no ppremk/lfs-warning due to https://github.com/ppremk/lfs-warning/issues/150
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: website-preview
- name: Install Task
run: go generate -x
working-directory: tools
- name: Build tools
run: bin/task env-pull
- name: Build blog
run: bin/task blog
- name: Check dirty
run: |
git status
git diff --exit-code
- name: Deploy to Cloudflare Pages
run: bin/task blog-cloudflare-preview | tee deploy.txt
env:
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Set GitHub deployment URL
id: extract
uses: FerretDB/github-actions/extract-first-url@main
docs-preview:
name: Preview docs
runs-on: ubuntu-22.04
timeout-minutes: 10
if: >
contains(github.event.pull_request.labels.*.name, 'trust') &&
!contains(github.event.pull_request.labels.*.name, 'not ready') &&
contains(github.event.pull_request.labels.*.name, 'documentation')
environment:
name: cloudflare-dev-docs
url: ${{ steps.extract.outputs.extracted_url }}
steps:
# We can't easily download build results from the Docs workflow:
# https://github.com/actions/download-artifact/issues/172
# Just build them again instead.
# That also allows us to pass branch name, commit hash, etc from git to wrangler.
# TODO https://github.com/FerretDB/github-actions/issues/211
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # for wrangler to work
lfs: true
ref: ${{ github.event.pull_request.head.sha }} # TODO https://github.com/FerretDB/github-actions/issues/211
# for Wrangler / Cloudflare Pages on pull_request_target
- name: Name branch
env:
BRANCH: ${{ github.head_ref }} # see https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
run: git checkout -b $BRANCH
# no ppremk/lfs-warning due to https://github.com/ppremk/lfs-warning/issues/150
- name: Setup Go
uses: FerretDB/github-actions/setup-go@main
with:
cache-key: website-preview
- name: Install Task
run: go generate -x
working-directory: tools
- name: Build tools
run: bin/task env-pull
- name: Build docs
run: bin/task docs
- name: Check dirty
run: |
git status
git diff --exit-code
- name: Deploy to Cloudflare Pages
run: bin/task docs-cloudflare-preview | tee deploy.txt
env:
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
- name: Set GitHub deployment URL
id: extract
uses: FerretDB/github-actions/extract-first-url@main