Skip to content

Commit

Permalink
Add new route for PR deployment URL and update GitHub Actions workflows
Browse files Browse the repository at this point in the history
* **App.tsx**
  - Add a new route for the PR deployment URL (`/pr-deploy/:prNumber`).

* **.github/workflows/pr-check.yml**
  - Add a new job to deploy the PR to GitHub Pages.
  - Update the `environment` name to include the PR number.
  - Update the `url` to include the PR number.

* **.github/workflows/deploy.yml**
  - Add a new job to deploy the PR to GitHub Pages.
  - Update the `environment` name to include the PR number.
  - Update the `url` to include the PR number.
  • Loading branch information
yogeshpaliyal committed Aug 11, 2024
1 parent 38ea6b1 commit 1418348
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 77 deletions.
129 changes: 79 additions & 50 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,79 @@
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches: ['main']

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
permissions:
contents: read
pages: write
id-token: write

# Allow one concurrent deployment
concurrency:
group: 'pages'
cancel-in-progress: true

jobs:
# Single deploy job since we're just deploying
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
# Upload dist folder
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
1 name: Deploy static content to Pages
2
3 on:
4 # Runs on pushes targeting the default branch
5 push:
6 branches: ['main']
7
8 # Allows you to run this workflow manually from the Actions tab
9 workflow_dispatch:
10
11 # Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages
12 permissions:
13 contents: read
14 pages: write
15 id-token: write
16
17 # Allow one concurrent deployment
18 concurrency:
19 group: 'pages'
20 cancel-in-progress: true
21
22 jobs:
23 # Single deploy job since we're just deploying
24 deploy:
25 environment:
26 name: github-pages-${{ github.event.pull_request.number }}
27 url: ${{ steps.deployment.outputs.page_url }}
28 runs-on: ubuntu-latest
29 steps:
30 - name: Checkout
31 uses: actions/checkout@v4
32 - name: Set up Node
33 uses: actions/setup-node@v4
34 with:
35 node-version: 20
36 cache: 'npm'
37 - name: Install dependencies
38 run: npm ci
39 - name: Build
40 run: npm run build
41 - name: Setup Pages
42 uses: actions/configure-pages@v4
43 - name: Upload artifact
44 uses: actions/upload-pages-artifact@v3
45 with:
46 # Upload dist folder
47 path: './dist'
48 - name: Deploy to GitHub Pages
49 id: deployment
50 uses: actions/deploy-pages@v4
51
52 pr-deploy:
53 if: github.event_name == 'pull_request'
54 environment:
55 name: github-pages-pr-${{ github.event.pull_request.number }}
56 url: ${{ steps.deployment.outputs.page_url }}
57 runs-on: ubuntu-latest
58 steps:
59 - name: Checkout
60 uses: actions/checkout@v4
61 - name: Set up Node
62 uses: actions/setup-node@v4
63 with:
64 node-version: 20
65 cache: 'npm'
66 - name: Install dependencies
67 run: npm ci
68 - name: Build
69 run: npm run build
70 - name: Setup Pages
71 uses: actions/configure-pages@v4
72 - name: Upload artifact
73 uses: actions/upload-pages-artifact@v3
74 with:
75 path: './dist'
76 - name: Deploy to GitHub Pages
77 id: deployment
78 uses: actions/deploy-pages@v4
79
28 changes: 28 additions & 0 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,31 @@ jobs:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4

pr-deploy:
if: github.event_name == 'pull_request'
environment:
name: github-pages-pr-${{ github.event.pull_request.number }}
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Node
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Build
run: npm run build
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: './dist'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
52 changes: 25 additions & 27 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import './App.css'
import LoginForm from './Pages/LoginForm/LoginForm';
import Register from './Pages/register/Register';
import LandingPage from './Pages/LandingPage'
import { BrowserRouter, Routes, Route } from 'react-router-dom';
import Librarylist from './Pages/Librarylist';
import Users from './Pages/Users';

function App() {
return (
<BrowserRouter basename={process.env.PUBLIC_URL}>
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/library/login" element={<LoginForm up='library'/>} />
<Route path="/user/login" element={<LoginForm up='user'/>} />
<Route path='/register' element={<Register/>}/>
<Route path='/librarylist' element={<Librarylist/>}/>
<Route path='/users' element={<Users/>}/>



</Routes>
</BrowserRouter>
)
}

export default App;
1 import './App.css'

Check failure on line 1 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 1 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
2 import LoginForm from './Pages/LoginForm/LoginForm';

Check failure on line 2 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 2 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
3 import Register from './Pages/register/Register';

Check failure on line 3 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 3 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
4 import LandingPage from './Pages/LandingPage'

Check failure on line 4 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 4 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
5 import { BrowserRouter, Routes, Route } from 'react-router-dom';

Check failure on line 5 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 5 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
6 import Librarylist from './Pages/Librarylist';

Check failure on line 6 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 6 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
7 import Users from './Pages/Users';

Check failure on line 7 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 7 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
8
9 function App() {

Check failure on line 9 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 9 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
10 return (

Check failure on line 10 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

';' expected.

Check failure on line 10 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

';' expected.
11 <BrowserRouter basename={process.env.PUBLIC_URL}>

Check failure on line 11 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build

')' expected.

Check failure on line 11 in src/App.tsx

View workflow job for this annotation

GitHub Actions / pr-deploy

')' expected.
12 <Routes>
13 <Route path="/" element={<LandingPage />} />
14 <Route path="/library/login" element={<LoginForm up='library'/>} />
15 <Route path="/user/login" element={<LoginForm up='user'/>} />
16 <Route path='/register' element={<Register/>}/>
17 <Route path='/librarylist' element={<Librarylist/>}/>
18 <Route path='/users' element={<Users/>}/>
19 <Route path='/pr-deploy/:prNumber' element={<LandingPage />} />
20 </Routes>
21 </BrowserRouter>
22 )
23 }
24
25 export default App;

0 comments on commit 1418348

Please sign in to comment.