-
Notifications
You must be signed in to change notification settings - Fork 4
128 lines (108 loc) · 3.84 KB
/
Copy pathpr-preview.yml
File metadata and controls
128 lines (108 loc) · 3.84 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
123
124
125
126
127
128
name: PR Preview
on:
pull_request:
types: [opened, synchronize, reopened, closed]
branches:
- master
permissions:
contents: write
pull-requests: write
concurrency:
group: pr-preview-${{ github.event.number }}
cancel-in-progress: true
jobs:
deploy-preview:
if: github.event.action != 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: wasm32-unknown-unknown
- name: Cache Rust dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install wasm-pack
uses: jetli/wasm-pack-action@v0.4.0
with:
version: 'latest'
- name: Generate contracts.js
run: ./playground/generate_contracts.sh
- name: Build WASM package
run: wasm-pack build --target web --out-dir playground/pkg -- --features wasm
- name: Clean up WASM package artifacts
run: |
rm -f playground/pkg/.gitignore
rm -f playground/pkg/package.json
rm -f playground/pkg/README.md
- name: Remove playground .gitignore so generated files are included
run: rm playground/.gitignore
- name: Deploy PR preview
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: playground
target-folder: pr-previews/pr-${{ github.event.number }}
clean: true
- name: Post or update PR comment
uses: actions/github-script@v7
with:
script: |
const pr = context.payload.pull_request.number;
const previewUrl = `https://arkade-os.github.io/compiler/pr-previews/pr-${pr}/`;
const marker = '<!-- arkade-pr-preview -->';
const body = `${marker}
### Playground Preview
A live preview of this PR's playground is available at:
**[${previewUrl}](${previewUrl})**
> Built from commit \`${{ github.sha }}\` · [Workflow run](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})`;
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
});
const existing = comments.find(c => c.body.includes(marker));
if (existing) {
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existing.id,
body,
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: pr,
body,
});
}
cleanup-preview:
if: github.event.action == 'closed'
runs-on: ubuntu-latest
steps:
- name: Checkout gh-pages branch
uses: actions/checkout@v4
with:
ref: gh-pages
- name: Remove preview directory
run: |
PR_DIR="pr-previews/pr-${{ github.event.number }}"
if [ -d "$PR_DIR" ]; then
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git rm -rf "$PR_DIR"
git commit -m "chore: remove PR preview for #${{ github.event.number }}"
git push
else
echo "No preview directory found at $PR_DIR, nothing to clean up."
fi