Skip to content

Commit ebca321

Browse files
Added Feature to deploy previews of pull requests (#638)
* Added Feature to deploy previews of pull requests * Removed environment variables from build-lint workflow * Modified the changes mentioned in the code-review
1 parent 3657c15 commit ebca321

File tree

5 files changed

+137
-2
lines changed

5 files changed

+137
-2
lines changed

.github/workflows/build-pr.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: Build PR-Preview
2+
3+
on:
4+
pull_request_review:
5+
types: submitted
6+
7+
concurrency:
8+
group: ${{github.workflow}}-${{github.ref}}
9+
cancel-in-progress: true
10+
11+
env:
12+
LAYOUT_EDITOR_BASE_URL: "/EmbeddedChat/pulls/pr-${{github.event.pull_request.number}}/layout_editor"
13+
DOCS_BASE_URL: "/EmbeddedChat/pulls/pr-${{github.event.pull_request.number}}/docs"
14+
STORYBOOK_RC_HOST: "https://demo.qa.rocket.chat"
15+
16+
jobs:
17+
build:
18+
if: github.event.review.state == 'approved' && (github.event.review.author_association == 'COLLABORATOR' || github.event.review.author_association == 'OWNER')
19+
runs-on: ubuntu-latest
20+
21+
steps:
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
25+
- name: Setup Node.js
26+
uses: actions/setup-node@v4
27+
with:
28+
node-version: "16.19.0"
29+
30+
- name: Install Dependencies
31+
run: yarn install
32+
33+
- name: Build packages
34+
run: yarn build && yarn build:storybook
35+
36+
- name: Setup Node.js for Docs
37+
uses: actions/setup-node@v4
38+
with:
39+
node-version: "18.x"
40+
41+
- name: "Install dependencies for docs"
42+
run: yarn install
43+
working-directory: packages/docs/
44+
45+
- name: Build Docs
46+
run: yarn build
47+
working-directory: packages/docs/
48+
49+
- name: Prepare Build Folder
50+
run: |
51+
mkdir -p build/pulls/pr-${{github.event.pull_request.number}}/
52+
mkdir -p build/pulls/pr-${{github.event.pull_request.number}}/ui-elements
53+
mkdir -p build/pulls/pr-${{github.event.pull_request.number}}/layout_editor
54+
mkdir -p build/pulls/pr-${{github.event.pull_request.number}}/docs
55+
56+
mv -v packages/react/storybook-static/* build/pulls/pr-${{github.event.pull_request.number}}/
57+
mv -v packages/ui-elements/storybook-static/* build/pulls/pr-${{github.event.pull_request.number}}/ui-elements/
58+
mv -v packages/layout_editor/dist/* build/pulls/pr-${{github.event.pull_request.number}}/layout_editor/
59+
mv -v packages/docs/build/* build/pulls/pr-${{github.event.pull_request.number}}/docs/
60+
61+
- name: Upload Artifacts
62+
uses: actions/upload-artifact@v4
63+
with:
64+
name: github-pages
65+
path: build/

.github/workflows/deploy-pr.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Deploy PR-Preview
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Build PR-Preview"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pages: write
12+
13+
jobs:
14+
deploy:
15+
if: github.event.workflow_run.conclusion == 'success'
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- uses: actions/download-artifact@v4
20+
with:
21+
name: github-pages
22+
path: build/
23+
github-token: ${{github.token}}
24+
repository: ${{github.repository}}
25+
run-id: ${{github.event.workflow_run.id}}
26+
27+
- name: Deploy to GitHub Pages
28+
uses: crazy-max/ghaction-github-pages@v2
29+
with:
30+
target_branch: gh-deploy
31+
build_dir: build/
32+
commit_message: "Deploy to Github Pages"
33+
jekyll: false
34+
keep_history: true
35+
env:
36+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/pr-cleanup.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Pull Request Cleanup
2+
on:
3+
pull_request_target:
4+
types: [closed]
5+
6+
jobs:
7+
cleanup:
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout repository
12+
uses: actions/checkout@v2
13+
with:
14+
ref: gh-deploy
15+
16+
- name: Check if Deployment Exists
17+
id: check_deployment
18+
run: |
19+
if [ -d "pulls/pr-${{ github.event.pull_request.number }}" ]; then
20+
echo "deployment_exists=true" >> $GITHUB_ENV
21+
else
22+
echo "deployment_exists=false" >> $GITHUB_ENV
23+
fi
24+
25+
- name: Remove Deployment
26+
if: env.deployment_exists == 'true'
27+
run: |
28+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
29+
git config --global user.name "github-actions[bot]"
30+
git fetch origin gh-deploy
31+
git checkout gh-deploy
32+
git rm -r pulls/pr-${{github.event.pull_request.number}}
33+
git commit -m "Remove deployment for PR #${{github.event.pull_request.number}}"
34+
git push origin gh-deploy

packages/docs/docusaurus.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const config = {
1717
url: "https://rocketchat.github.io/",
1818
// Set the /<baseUrl>/ pathname under which your site is served
1919
// For GitHub pages deployment, it is often '/<projectName>/'
20-
baseUrl: "/EmbeddedChat/docs/",
20+
baseUrl: process.env.DOCS_BASE_URL || "/EmbeddedChat/docs/",
2121

2222
// GitHub pages deployment config.
2323
// If you aren't using GitHub pages, you don't need these.

packages/layout_editor/vite.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ export default defineConfig({
1111
},
1212
}),
1313
],
14-
base: "/EmbeddedChat/layout_editor"
14+
base: process.env.LAYOUT_EDITOR_BASE_URL || '/EmbeddedChat/layout_editor',
1515
});

0 commit comments

Comments
 (0)