Skip to content

Commit d63931b

Browse files
committed
add github workflows for test, deploy, and pr previews.
Squashed commit of the following: commit 02a28a076c28ea436d24ba1ebd52bd3683946be3 Author: Jacob Phillips <[email protected]> Date: Mon Nov 18 12:11:42 2024 -0500 skip draft PRs commit c8b32d2 Author: Jacob Phillips <[email protected]> Date: Mon Nov 18 12:06:28 2024 -0500 workflow fixes commit 6210589 Author: Jacob Phillips <[email protected]> Date: Mon Nov 18 12:01:27 2024 -0500 add empty header and footer to test PR previews deploy test: more logs, no obfuscation (#2) * deploy test: more logs, no obfuscation * Adjust base url for svelte when running from github pages. only run unit tests * let pr preview make comments on prs * temp remove obfuscation disable github pages from using jekyll obfuscate and remove .nojekyll (was repo setting on github) set prod log level to info (#4) * set prod log level to info * try removing obfuscate from preview PR * and remove obfuscate from deploy/main include base in init message if it is not empty. (#5) do a clean gh-pages build fix log this context try to figure out why log levels are ignored on gh-pages
1 parent 2377be6 commit d63931b

File tree

8 files changed

+115
-3
lines changed

8 files changed

+115
-3
lines changed

.github/workflows/deploy.yml

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Deploy to GitHub Pages.
2+
#
3+
# Based on https://github.com/JamesIves/github-pages-deploy-action
4+
# and https://github.com/marketplace/actions/deploy-pr-preview#ensure-your-main-deployment-is-compatible
5+
6+
name: Deploy
7+
on:
8+
push:
9+
branches:
10+
- main
11+
permissions:
12+
contents: write
13+
jobs:
14+
build-and-deploy:
15+
concurrency: ci-${{ github.ref }}
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout 🛎️
19+
uses: actions/checkout@v4
20+
21+
- name: Set BASE_PATH
22+
run: echo "BASE_PATH=/${{ github.event.repository.name }}" >> $GITHUB_ENV
23+
24+
- name: Install and Build 🔧
25+
run: |
26+
npm ci
27+
npm run build
28+
npm run obfuscate
29+
30+
- name: Deploy 🚀
31+
uses: JamesIves/github-pages-deploy-action@v4
32+
with:
33+
folder: build
34+
clean-exclude: pr-preview/
35+
force: false

.github/workflows/preview.yml

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Preview PRs by deploying to a pemanent subdirectory in GitHub Pages.
2+
#
3+
# Based on https://github.com/marketplace/actions/deploy-pr-preview#usage.
4+
5+
name: Deploy PR previews
6+
on:
7+
pull_request:
8+
draft: false
9+
branches:
10+
- main
11+
types:
12+
- opened
13+
- synchronize
14+
paths:
15+
- '**.js'
16+
- '**.ts'
17+
- '**.json'
18+
- 'src/**'
19+
- 'static/**'
20+
- '.env'
21+
- '.env.*'
22+
permissions:
23+
contents: write
24+
pull-requests: write
25+
concurrency: preview-${{ github.ref }}
26+
27+
jobs:
28+
deploy-preview:
29+
runs-on: ubuntu-latest
30+
steps:
31+
- name: Checkout
32+
uses: actions/checkout@v3
33+
34+
- name: Set BASE_PATH
35+
run: echo "BASE_PATH=/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }}" >> $GITHUB_ENV
36+
37+
- name: Install and Build
38+
run: |
39+
npm ci
40+
npm run build
41+
npm run obfuscate
42+
43+
- name: Deploy preview
44+
uses: rossjrw/pr-preview-action@v1
45+
with:
46+
source-dir: ./build/
47+
action: deploy

.github/workflows/test.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Run unit and integration tests.
2+
#
3+
# Based on https://playwright.dev/docs/next/ci#github-actions.
4+
name: Test
5+
on:
6+
push:
7+
branches: main
8+
pull_request:
9+
draft: false
10+
branches: main
11+
jobs:
12+
test:
13+
timeout-minutes: 5
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: actions/setup-node@v4
18+
with:
19+
node-version: lts/*
20+
- name: Install dependencies
21+
run: npm ci
22+
- name: Run unit tests
23+
run: npx vitest --run

src/lib/advertising/service_mock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export class AdvertisingServiceMock extends AdvertisingService {
55
element.classList.add('block', 'bg-neutral-500', 'rounded-lg', 'overflow-hidden');
66
element.innerHTML = `
77
<div class="flex items-center justify-center h-full">
8-
<span>Ad Placeholder ${element.clientWidth}x${element.clientHeight}</span>
8+
<span>Ad Placeholder ${element.offsetWidth}x${element.offsetHeight}</span>
99
</div>
1010
`;
1111
return Promise.resolve();

src/lib/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// place files you want to import through the `$lib` alias in this folder.
22

3+
import { base } from '$app/paths';
4+
35
import { AdvertisingServiceGoogleAdsense } from './advertising/service_google_adsense';
46
import { AdvertisingServiceMock } from './advertising/service_mock';
57
import { App } from './app';
@@ -38,4 +40,4 @@ export const app = new App(
3840
: new TelemetryServiceMock()
3941
);
4042

41-
log.debug(performance.now(), 'Initialized.');
43+
log.info(performance.now(), base ? `Initialized at ${base}.` : 'Initialized.');

src/routes/+layout.svelte

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
});
99
</script>
1010

11+
<header></header>
1112
<main>
1213
<slot />
1314
</main>
15+
<footer></footer>

static/.nojekyll

Whitespace-only changes.

svelte.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ const config = {
1111
// adapter-auto only supports some environments, see https://svelte.dev/docs/kit/adapter-auto for a list.
1212
// If your environment is not supported, or you settled on a specific environment, switch out the adapter.
1313
// See https://svelte.dev/docs/kit/adapters for more information about adapters.
14-
adapter: adapter()
14+
adapter: adapter(),
15+
paths: {
16+
base: process.env.BASE_PATH || ''
17+
}
1518
}
1619
};
1720

0 commit comments

Comments
 (0)