Skip to content

Commit 03b6fe9

Browse files
authored
Support publishing of PR previews to the langium-previews repo (#210)
* Update preview workflow to publish results to the langium-previews repo; ensure that relative links are used for building the website
1 parent 13556b1 commit 03b6fe9

File tree

3 files changed

+62
-9
lines changed

3 files changed

+62
-9
lines changed

.github/workflows/preview.yml

Lines changed: 57 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,84 @@
11
name: Deploy PR previews
22

33
on:
4-
pull_request:
4+
pull_request_target:
55
types:
66
- opened
77
- synchronize
88
- reopened
99
- closed
1010

11-
concurrency: preview-${{ github.ref }}
11+
concurrency: preview-${{ github.head_ref }}
1212

1313
defaults:
1414
run:
1515
shell: bash
1616

1717
jobs:
18-
deploy-preview:
18+
build-preview:
19+
if: github.event_name == 'pull_request_target' && github.event.action != 'closed'
1920
runs-on: ubuntu-latest
2021
steps:
2122
- name: Use Node.js
22-
uses: actions/setup-node@v3
23+
uses: actions/setup-node@1a4442cacd436585916779262731d5b162bc6ec7 # v3.8.2
2324
with:
2425
node-version: '18'
2526
- name: Checkout
26-
uses: actions/checkout@v3
27+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
28+
with:
29+
ref: ${{ github.event.pull_request.head.sha }}
2730
- name: Build
2831
run: |
2932
npm install
3033
npm run build
31-
- name: Deploy preview
32-
uses: rossjrw/pr-preview-action@v1
34+
- name: Upload artifact
35+
uses: actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
36+
with:
37+
name: "site"
38+
path: ./public
39+
40+
deploy-preview:
41+
needs: build-preview
42+
runs-on: ubuntu-latest
43+
permissions:
44+
pull-requests: write
45+
environment:
46+
name: pull-request-preview
47+
url: ${{ steps.deployment.outputs.deployment-url }}
48+
steps:
49+
# checkout required for pr-preview-action to succeed,
50+
# while the content will not be used
51+
- name: Checkout
52+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
53+
- name: Download the preview page
54+
uses: actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
55+
with:
56+
name: "site"
57+
path: ./public
58+
- uses: rossjrw/pr-preview-action@183082fd714654433c8e2f6daedbfb4f20f2a94a # v1.4.4
59+
id: deployment
3360
with:
3461
source-dir: ./public
62+
preview-branch: previews
63+
umbrella-dir: pr-previews
64+
deploy-repository: eclipse-langium/langium-previews
65+
token: ${{ secrets.DEPLOY_PREVIEW_TOKEN }}
66+
action: auto
67+
68+
# remove the preview page when the PR got closed
69+
remove-preview:
70+
if: github.event_name == 'pull_request_target' && github.event.action == 'closed'
71+
runs-on: ubuntu-latest
72+
steps:
73+
# checkout required for pr-preview-action to succeed,
74+
# while the content will not be used
75+
- name: Checkout
76+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
77+
- uses: rossjrw/pr-preview-action@183082fd714654433c8e2f6daedbfb4f20f2a94a # v1.4.4
78+
id: deployment
79+
with:
80+
preview-branch: previews
81+
umbrella-dir: pr-previews
82+
deploy-repository: eclipse-langium/langium-previews
83+
token: ${{ secrets.DEPLOY_PREVIEW_TOKEN }}
84+
action: auto

hugo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ baseURL = "/"
22
title = "Langium"
33
theme = "hugo-geekdoc"
44

5+
# Required for publishing of previews as they are hosted in subdirs
6+
relativeURLs = true
7+
58
# Required to get well formatted code blocks
69
disablePathToLower = true
710
enableGitInfo = true

hugo/content/playground/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ async function getFreshLangiumWrapper(htmlElement: HTMLElement): Promise<MonacoE
250250
await langiumWrapper.start(createUserConfig({
251251
languageId: "langium",
252252
code: currentGrammarContent,
253-
worker: "/playground/libs/worker/langiumServerWorker.js",
253+
worker: "./libs/worker/langiumServerWorker.js",
254254
monarchGrammar: LangiumMonarchContent
255255
}), htmlElement);
256256
return langiumWrapper;
@@ -298,7 +298,7 @@ function registerForDocumentChanges(dslClient: any | undefined) {
298298
async function getLSWorkerForGrammar(grammar: string): Promise<Worker> {
299299
return new Promise((resolve, reject) => {
300300
// create & notify the worker to setup w/ this grammar
301-
const worker = new Worker("/playground/libs/worker/userServerWorker.js");
301+
const worker = new Worker("./libs/worker/userServerWorker.js");
302302
worker.postMessage({
303303
type: "startWithGrammar",
304304
grammar

0 commit comments

Comments
 (0)