Repository navigation
122 lines (110 loc) · 4.46 KB
/
Copy pathdeploy-docs.yml
File metadata and controls
122 lines (110 loc) · 4.46 KB
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
name: Deploy docs
on:
workflow_dispatch:
release:
types: [published]
pull_request:
types: [closed]
branches: [main]
# Async release follow-up: releases created by changesets with GITHUB_TOKEN
# cannot trigger `release: published` downstream (GITHUB_TOKEN events spawn
# no new runs). workflow_run fires regardless of token, in its own run,
# so Release stays untouched. Read from main, so this takes effect post-merge.
workflow_run:
workflows: [Release]
types: [completed]
branches: [main]
permissions:
contents: read
concurrency:
group: deploy-docs-production
cancel-in-progress: false
jobs:
deploy:
name: 🚀 Build & Deploy docs (FTP)
if: >
github.event_name == 'workflow_dispatch' ||
github.event_name == 'release' ||
(github.event_name == 'pull_request' &&
github.event.pull_request.merged == true &&
contains(github.event.pull_request.labels.*.name, 'docs')) ||
(github.event_name == 'workflow_run' &&
github.event.workflow_run.conclusion == 'success')
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
persist-credentials: false
# The release-tag gate below needs tags even on branch checkouts.
fetch-tags: true
# A closed PR checkout defaults to a dead merge ref, so pin the merge commit on main.
# A workflow_run checkout defaults to default-branch HEAD, so pin the run's head SHA.
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.merge_commit_sha || github.event_name == 'workflow_run' && github.event.workflow_run.head_sha || github.sha }}
# The sitemap's lastmod reads `git log` per file.
fetch-depth: 0
# Release runs on every main push; deploy only when its head shipped
# a release (any tag present: every tag in these repos is a
# changesets release tag). Skips green, no red noise.
- name: Require release tag on head
id: gate
if: github.event_name == 'workflow_run'
run: |
if git tag --points-at HEAD | grep -q .; then
echo "release=true" >> "$GITHUB_OUTPUT"
else
echo "release=false" >> "$GITHUB_OUTPUT"
fi
- name: Setup Bun
# Same gate as upload: no release, no work (still green).
if: steps.gate.outputs.release != 'false'
uses: ./.github/actions/setup
- name: Validate docs links
if: steps.gate.outputs.release != 'false'
run: vp run --filter ./apps/docs validate --strict
- name: Typecheck docs site
if: steps.gate.outputs.release != 'false'
run: vp run --filter ./apps/docs check --isolated
- name: Build docs site
if: steps.gate.outputs.release != 'false'
run: vp run --filter ./apps/docs build
- name: Audit docs site
if: steps.gate.outputs.release != 'false'
run: vp run --filter ./apps/docs audit
- name: Upload to /lossless via FTP
# Gate runs on workflow_run only; skipped (empty) elsewhere, so upload proceeds.
if: steps.gate.outputs.release != 'false'
uses: SamKirkland/FTP-Deploy-Action@110f9186c050f71550953127052e77650219c287 # v4.4.0
with:
server: ${{ secrets.FTP_HOST }}
username: ${{ secrets.FTP_USERNAME }}
password: ${{ secrets.FTP_PASSWORD }}
protocol: ftps
port: 21
security: strict
local-dir: ./apps/docs/dist/
server-dir: ./
exclude: |
**/.git*
**/.git*/**
**/node_modules/**
# Fail-closed deploy proof: the live changelog is built from the releases
# API at build time, so only a fresh deploy can contain this run's tags.
# No tags on HEAD (docs PR, manual dispatch): assert liveness only.
- name: Verify live site serves this release
if: steps.gate.outputs.release != 'false'
run: |
SITE="https://stainless-code.com/lossless"
TAGS="$(git tag --points-at HEAD)"
if [ -z "$TAGS" ]; then
curl -sSfL -o /dev/null "$SITE/"
else
for TAG in $TAGS; do
ATTEMPT=0
until curl -sSL "$SITE/changelog" | grep -qF "$TAG"; do
ATTEMPT=$((ATTEMPT + 1))
if [ "$ATTEMPT" -ge 3 ]; then exit 1; fi
sleep 30
done
done
fi