Skip to content

Commit 79f37f4

Browse files
committed
Add preview deployments
1 parent f4ed394 commit 79f37f4

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed

.github/workflows/preview_build.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# This action builds and deploys egui_demo_app on each pull request created
2+
# Security notes:
3+
# This action is split in two workflows, preview_build and preview_deploy.
4+
# `preview_build` runs on pull_request, so it won't have any access to the repositories secrets, so it is safe to execute
5+
# untrusted code.
6+
# `preview_deploy` has access to the repositories secrets (so it can push to the pr preview repo) but won't run
7+
# any untrusted code (it will just extract the build artifact and push it to the pages branch where it will
8+
# automatically be deployed).
9+
10+
on:
11+
- pull_request
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- run: rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown
18+
- uses: Swatinem/rust-cache@v2
19+
with:
20+
prefix-key: "pr-preview-"
21+
22+
- name: "Install wasmopt / binaryen"
23+
run: |
24+
sudo apt-get update && sudo apt-get install binaryen
25+
26+
- run: |
27+
scripts/build_demo_web.sh --release
28+
29+
- uses: actions/upload-artifact@v4
30+
with:
31+
name: web_demo
32+
path: web_demo
33+
34+
- name: Generate meta.json
35+
env:
36+
PR_NUMBER: ${{ github.event.number }}
37+
PR_BRANCH: ${{ github.head_ref }}
38+
run: |
39+
echo "{\"pr_number\": \"$PR_NUMBER\", \"pr_branch\": \"$PR_BRANCH\"}" > meta.json
40+
41+
- uses: actions/upload-artifact@v4
42+
with:
43+
name: meta.json
44+
path: meta.json

.github/workflows/preview_cleanup.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
on:
2+
pull_request_target:
3+
types:
4+
- closed
5+
6+
jobs:
7+
cleanup:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- run: mkdir -p empty_dir
11+
- name: Url slug variable
12+
run: |
13+
echo "URL_SLUG=${{ github.event.pull_request.number }}-${{ github.event.pull_request.head.ref }}" >> $GITHUB_ENV
14+
- name: Deploy
15+
uses: JamesIves/github-pages-deploy-action@v4
16+
if: secrets.DEPLOY_KEY
17+
with:
18+
folder: empty_dir
19+
repository-name: egui-pr-preview/pr
20+
branch: 'main'
21+
clean: true
22+
target-folder: ${{ env.URL_SLUG }}
23+
ssh-key: ${{ secrets.DEPLOY_KEY }}
24+
commit-message: "Remove preview for PR ${{ env.URL_SLUG }}"

.github/workflows/preview_deploy.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
on:
2+
workflow_run:
3+
workflows:
4+
- preview_build
5+
types:
6+
- completed
7+
8+
9+
permissions:
10+
pull-requests: write
11+
12+
jobs:
13+
deploy:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Download Artifact
17+
uses: actions/download-artifact@v4
18+
with:
19+
run-id: '${{ github.event.workflow_run.id }}'
20+
21+
- name: Parse meta.json
22+
run: |
23+
echo "PR_NUMBER=$(jq -r .pr_number meta.json)" >> $GITHUB_ENV
24+
echo "PR_BRANCH=$(jq -r .pr_branch meta.json)" >> $GITHUB_ENV
25+
26+
- name: Url slug variable
27+
run: |
28+
echo "URL_SLUG=${{ env.PR_NUMBER }}-${{ env.PR_BRANCH }}" >> $GITHUB_ENV
29+
30+
- name: Deploy
31+
uses: JamesIves/github-pages-deploy-action@v4
32+
if: secrets.DEPLOY_KEY
33+
with:
34+
folder: web_demo
35+
repository-name: egui-pr-preview/pr
36+
branch: 'main'
37+
clean: true
38+
target-folder: ${{ env.URL_SLUG }}
39+
ssh-key: ${{ secrets.DEPLOY_KEY }}
40+
commit-message: "Update preview for PR ${{ env.URL_SLUG }}"
41+
force: false
42+
43+
- name: Comment PR
44+
uses: thollander/actions-comment-pull-request@v2
45+
with:
46+
message: |
47+
Preview available at https://egui-pr-preview.github.io/pr/${{ env.URL_SLUG }}

0 commit comments

Comments
 (0)