Skip to content

Commit 9d8cd67

Browse files
authored
Merge pull request #7 from Roshanjossey/add-workflow-for-deploying-to-github-pages
add workflows for deploying to GitHub pages
2 parents b214f22 + d87a04f commit 9d8cd67

File tree

5 files changed

+182
-3
lines changed

5 files changed

+182
-3
lines changed
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Deploy Preview to GitHub Pages
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened]
6+
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
12+
concurrency:
13+
group: "pages-preview-${{ github.event.pull_request.number }}"
14+
cancel-in-progress: true
15+
16+
jobs:
17+
build:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout
21+
uses: actions/checkout@v4
22+
23+
- name: Setup Node.js
24+
uses: actions/setup-node@v4
25+
with:
26+
node-version: "20"
27+
28+
- name: Setup pnpm
29+
uses: pnpm/action-setup@v4
30+
with:
31+
version: latest
32+
33+
- name: Get pnpm store directory
34+
shell: bash
35+
run: |
36+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
37+
38+
- name: Setup pnpm cache
39+
uses: actions/cache@v4
40+
with:
41+
path: ${{ env.STORE_PATH }}
42+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
43+
restore-keys: |
44+
${{ runner.os }}-pnpm-store-
45+
46+
- name: Install dependencies
47+
run: pnpm install --frozen-lockfile
48+
49+
- name: Build
50+
run: pnpm build
51+
52+
- name: Setup Pages
53+
uses: actions/configure-pages@v4
54+
with:
55+
static_site_generator: svelte
56+
57+
- name: Upload artifact
58+
uses: actions/upload-pages-artifact@v3
59+
with:
60+
path: ./build
61+
62+
deploy:
63+
environment:
64+
name: github-pages-preview
65+
url: ${{ steps.deployment.outputs.page_url }}
66+
runs-on: ubuntu-latest
67+
needs: build
68+
steps:
69+
- name: Deploy to GitHub Pages
70+
id: deployment
71+
uses: actions/deploy-pages@v4
72+
73+
comment:
74+
runs-on: ubuntu-latest
75+
needs: deploy
76+
if: github.event_name == 'pull_request'
77+
steps:
78+
- name: Comment PR
79+
uses: actions/github-script@v7
80+
with:
81+
script: |
82+
github.rest.issues.createComment({
83+
issue_number: context.issue.number,
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
body: `🚀 **Preview deployed!**\n\nYour changes are now live at: ${{ needs.deploy.outputs.page_url }}\n\nThis preview will be automatically updated when you push new commits to this PR.`
87+
})
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: Deploy to GitHub Pages (Production)
2+
3+
on:
4+
push:
5+
branches: [main]
6+
workflow_dispatch:
7+
8+
permissions:
9+
contents: read
10+
pages: write
11+
id-token: write
12+
13+
concurrency:
14+
group: "pages"
15+
cancel-in-progress: false
16+
17+
jobs:
18+
build:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Setup Node.js
25+
uses: actions/setup-node@v4
26+
with:
27+
node-version: "20"
28+
29+
- name: Setup pnpm
30+
uses: pnpm/action-setup@v4
31+
with:
32+
version: latest
33+
34+
- name: Get pnpm store directory
35+
shell: bash
36+
run: |
37+
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV
38+
39+
- name: Setup pnpm cache
40+
uses: actions/cache@v4
41+
with:
42+
path: ${{ env.STORE_PATH }}
43+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
44+
restore-keys: |
45+
${{ runner.os }}-pnpm-store-
46+
47+
- name: Install dependencies
48+
run: pnpm install --frozen-lockfile
49+
50+
- name: Build
51+
run: pnpm build
52+
53+
- name: Setup Pages
54+
uses: actions/configure-pages@v4
55+
56+
- name: Upload artifact
57+
uses: actions/upload-pages-artifact@v3
58+
with:
59+
path: ./build
60+
61+
deploy:
62+
environment:
63+
name: github-pages
64+
url: ${{ steps.deployment.outputs.page_url }}
65+
runs-on: ubuntu-latest
66+
needs: build
67+
steps:
68+
- name: Deploy to GitHub Pages
69+
id: deployment
70+
uses: actions/deploy-pages@v4

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
},
1414
"devDependencies": {
1515
"@sveltejs/adapter-auto": "^4.0.0",
16+
"@sveltejs/adapter-static": "^3.0.10",
1617
"@sveltejs/kit": "^2.20.6",
1718
"@sveltejs/vite-plugin-svelte": "^5.0.0",
1819
"svelte": "^5.0.0",

pnpm-lock.yaml

Lines changed: 13 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

svelte.config.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import adapter from '@sveltejs/adapter-auto';
1+
import adapter from '@sveltejs/adapter-static';
22
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
33

44
/** @type {import('@sveltejs/kit').Config} */
@@ -11,7 +11,16 @@ 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+
pages: 'build',
16+
assets: 'build',
17+
fallback: 'index.html',
18+
precompress: false,
19+
strict: true
20+
}),
21+
paths: {
22+
base: process.env.NODE_ENV === 'production' ? '/devicons.dev' : ''
23+
}
1524
}
1625
};
1726

0 commit comments

Comments
 (0)