-
-
Notifications
You must be signed in to change notification settings - Fork 653
111 lines (92 loc) · 3.64 KB
/
doc-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
name: Laf Doc Preview
# todo: When the requirements are mature enough, refactor using TypeScript, create a generic GitHub Action, and make it available to users.
on:
pull_request_target:
branches: [main]
types: [opened, synchronize, reopened, closed]
paths:
- "docs/**"
- ".github/workflows/doc-preview.yml"
# permissions:
# pull-requests: write
env:
LAF_CI_DOCS_PREVIEW_PAT: ${{ secrets.LAF_CI_DOCS_PREVIEW_PAT }}
LAF_CI_DOCS_PREVIEW_APPID: ${{ secrets.LAF_CI_DOCS_PREVIEW_APPID }}
LAF_CI_DOCS_PREVIEW_API_URL: ${{ secrets.LAF_CI_DOCS_PREVIEW_API_URL }}
BUCKET_SHORT_NAME: pr-${{ github.event.pull_request.number }}-doc-preview
jobs:
create-or-update-doc-preview:
if: github.event_name == 'pull_request_target' && github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.ref }}
repository: ${{ github.event.pull_request.head.repo.full_name }}
fetch-depth: 0
- name: Build Docs
uses: ./.github/actions/build-docs
- name: Setup laf-cli
run: npm i laf-cli -g
- name: Login laf-cli
run: |
laf user add doc -r ${{ env.LAF_CI_DOCS_PREVIEW_API_URL }}
laf user switch doc
laf login ${{ env.LAF_CI_DOCS_PREVIEW_PAT }}
laf app init ${{ env.LAF_CI_DOCS_PREVIEW_APPID }}
- name: Check if bucket exists
id: check-bucket
run: |
output=$(laf storage list)
# Check if the output contains the desired text
if echo "$output" | grep -q ${{ env.BUCKET_SHORT_NAME }}; then
echo "BUCKET_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "BUCKET_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Create bucket and create website
if: steps.check-bucket.outputs.BUCKET_EXISTS == 'false'
id: create-bucket-and-website
run: |
laf storage create ${{ env.BUCKET_SHORT_NAME }} -p readonly
output=$(laf website create ${{ env.BUCKET_SHORT_NAME }})
last_line=$(echo "$output" | tail -n 1)
echo "website_url_message=$last_line" >> $GITHUB_OUTPUT
- name: Deploy to laf
run: |
laf storage push -f ${{ env.BUCKET_SHORT_NAME }} docs/.vitepress/dist/
- uses: mshick/add-pr-comment@v2
if: steps.check-bucket.outputs.BUCKET_EXISTS == 'false'
with:
message: |
Laf Doc Preview:
${{ steps.create-bucket-and-website.outputs.website_url_message }}
delete-doc-preview:
if: github.event_name == 'pull_request_target' && github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup laf-cli
run: npm i laf-cli -g
- name: Login laf-cli
run: |
laf user add doc -r ${{ env.LAF_CI_DOCS_PREVIEW_API_URL }}
laf user switch doc
laf login ${{ env.LAF_CI_DOCS_PREVIEW_PAT }}
laf app init ${{ env.LAF_CI_DOCS_PREVIEW_APPID }}
- name: Check if bucket exists
id: check-bucket
run: |
output=$(laf storage list)
# Check if the output contains the desired text
if echo "$output" | grep -q ${{ env.BUCKET_SHORT_NAME }}; then
echo "BUCKET_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "BUCKET_EXISTS=false" >> $GITHUB_OUTPUT
fi
- name: Delete bucket
if: steps.check-bucket.outputs.BUCKET_EXISTS == 'true'
id: delete-bucket
run: |
laf website del ${{ env.BUCKET_SHORT_NAME }}
laf storage del ${{ env.BUCKET_SHORT_NAME }}