Skip to content

Commit c17efbc

Browse files
authored
enable PR previews for docs (#126)
1 parent ef6486e commit c17efbc

File tree

4 files changed

+145
-1
lines changed

4 files changed

+145
-1
lines changed

Diff for: .github/workflows/github-pages.yml

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ on:
66
push:
77
branches:
88
- main
9-
pull_request:
109

1110
jobs:
1211
deploy:

Diff for: .github/workflows/preview-build.yml

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Preview Build
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
jobs:
8+
build-preview:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
with:
14+
ref: ${{ github.event.pull_request.head.sha }}
15+
submodules: recursive
16+
17+
- name: Setup Hugo
18+
uses: peaceiris/actions-hugo@v2
19+
with:
20+
hugo-version: '0.83.1'
21+
extended: true
22+
23+
- name: Setup Node
24+
uses: actions/setup-node@v2
25+
with:
26+
node-version: '14'
27+
28+
- name: Install and Build
29+
run: |
30+
npm ci
31+
hugo --gc --minify
32+
33+
- name: Upload dist artifact
34+
uses: actions/upload-artifact@v2
35+
with:
36+
name: dist
37+
path: ./public
38+
retention-days: 7
39+
40+
- name: Save PR number
41+
if: ${{ always() }}
42+
run: echo ${{ github.event.number }} > ./pr-id.txt
43+
44+
- name: Upload PR number
45+
if: ${{ always() }}
46+
uses: actions/upload-artifact@v2
47+
with:
48+
name: pr
49+
path: ./pr-id.txt

Diff for: .github/workflows/preview-deploy.yml

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Preview Deploy
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Preview Build"]
6+
types:
7+
- completed
8+
9+
jobs:
10+
success:
11+
runs-on: ubuntu-latest
12+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success'
13+
steps:
14+
- name: download pr artifact
15+
uses: dawidd6/action-download-artifact@v2
16+
with:
17+
workflow: ${{ github.event.workflow_run.workflow_id }}
18+
name: pr
19+
20+
- name: Save the PR ID
21+
id: pr
22+
run: echo "::set-output name=id::$(<pr-id.txt)"
23+
24+
- name: Download dist artifact
25+
uses: dawidd6/action-download-artifact@v2
26+
with:
27+
workflow: ${{ github.event.workflow_run.workflow_id }}
28+
workflow_conclusion: success
29+
name: dist
30+
31+
- name: Upload on Surge
32+
id: deploy
33+
run: |
34+
export DEPLOY_DOMAIN=https://localstack-docs-preview-pr-${{ steps.pr.outputs.id }}.surge.sh
35+
npx surge --project ./ --domain $DEPLOY_DOMAIN --token ${{ secrets.SURGE_TOKEN }}
36+
37+
- name: Update status Comment
38+
uses: actions-cool/[email protected]
39+
with:
40+
token: ${{ secrets.GITHUB_TOKEN }}
41+
body: |
42+
🎊 PR Preview has been successfully built and deployed to https://localstack-docs-preview-pr-${{ steps.pr.outputs.id }}.surge.sh 🎊
43+
<!-- Sticky Pull Request Comment -->
44+
body-include: '<!-- Sticky Pull Request Comment -->'
45+
number: ${{ steps.pr.outputs.id }}
46+
47+
- name: Job failure
48+
if: ${{ failure() }}
49+
uses: actions-cool/[email protected]
50+
with:
51+
token: ${{ secrets.GITHUB_TOKEN }}
52+
body: |
53+
Deploy PR Preview failed.
54+
<!-- Sticky Pull Request Comment -->
55+
body-include: '<!-- Sticky Pull Request Comment -->'
56+
number: ${{ steps.pr.outputs.id }}
57+
58+
failed:
59+
runs-on: ubuntu-latest
60+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure'
61+
steps:
62+
- name: Download PR artifact
63+
uses: dawidd6/action-download-artifact@v2
64+
with:
65+
workflow: ${{ github.event.workflow_run.workflow_id }}
66+
name: pr
67+
68+
- name: Save the PR ID
69+
id: pr
70+
run: echo "::set-output name=id::$(<pr-id.txt)"
71+
72+
- name: Job failure
73+
uses: actions-cool/[email protected]
74+
with:
75+
token: ${{ secrets.GITHUB_TOKEN }}
76+
body: |
77+
Deploy PR Preview failed.
78+
<!-- Sticky Pull Request Comment -->
79+
body-include: '<!-- Sticky Pull Request Comment -->'
80+
number: ${{ steps.pr.outputs.id }}

Diff for: .github/workflows/preview-start.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Preview Start
2+
3+
on: pull_request_target
4+
5+
jobs:
6+
preview:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- name: create
10+
uses: actions-cool/[email protected]
11+
with:
12+
token: ${{ secrets.GITHUB_TOKEN }}
13+
body: |
14+
⚡️ Deploying PR Preview...
15+
<!-- Sticky Pull Request Comment -->
16+
body-include: '<!-- Sticky Pull Request Comment -->'

0 commit comments

Comments
 (0)