From 38ea6b1a4088485965c9242516fadd7ee7c6492c Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Sun, 11 Aug 2024 17:18:26 +0530 Subject: [PATCH 1/4] PR deploy testing Fixes #34 Add GitHub Action to deploy PR on GitHub Pages. * **Update `src/App.tsx`** - Change `BrowserRouter` `basename` prop to use `process.env.PUBLIC_URL`. * **Modify `.github/workflows/pr-check.yml`** - Add permissions for `pages: write` and `id-token: write`. - Add step to set up Pages using `actions/configure-pages@v4`. - Add step to upload artifact using `actions/upload-pages-artifact@v3`. - Add step to deploy to GitHub Pages using `actions/deploy-pages@v4`. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/TechPaliyal/LibraryManagement/issues/34?shareId=XXXX-XXXX-XXXX-XXXX). --- .github/workflows/pr-check.yml | 12 +++++++++++- src/App.tsx | 3 +-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 20cb768..e497308 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -7,6 +7,8 @@ on: # Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages permissions: contents: read + pages: write + id-token: write # Allow one concurrent deployment concurrency: @@ -28,4 +30,12 @@ jobs: 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 diff --git a/src/App.tsx b/src/App.tsx index 0636f08..2a72162 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,3 @@ - import './App.css' import LoginForm from './Pages/LoginForm/LoginForm'; import Register from './Pages/register/Register'; @@ -9,7 +8,7 @@ import Users from './Pages/Users'; function App() { return ( - + } /> } /> From 14183484fc284ba4946d83fef915b222efb0f434 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Sun, 11 Aug 2024 17:21:04 +0530 Subject: [PATCH 2/4] Add new route for PR deployment URL and update GitHub Actions workflows * **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. --- .github/workflows/deploy.yml | 129 ++++++++++++++++++++------------- .github/workflows/pr-check.yml | 28 +++++++ src/App.tsx | 52 +++++++------ 3 files changed, 132 insertions(+), 77 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index b5ed4a6..a96ad81 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index e497308..0c2e4c6 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -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 diff --git a/src/App.tsx b/src/App.tsx index 2a72162..c463676 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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 ( - - - } /> - } /> - } /> - }/> - }/> - }/> - - - - - - ) -} - -export default App; +1 import './App.css' +2 import LoginForm from './Pages/LoginForm/LoginForm'; +3 import Register from './Pages/register/Register'; +4 import LandingPage from './Pages/LandingPage' +5 import { BrowserRouter, Routes, Route } from 'react-router-dom'; +6 import Librarylist from './Pages/Librarylist'; +7 import Users from './Pages/Users'; +8 +9 function App() { +10 return ( +11 +12 +13 } /> +14 } /> +15 } /> +16 }/> +17 }/> +18 }/> +19 } /> +20 +21 +22 ) +23 } +24 +25 export default App; From c5d449064b4ea15dd0ecf9302ae1bcd60efa3182 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Sun, 11 Aug 2024 17:23:02 +0530 Subject: [PATCH 3/4] --- src/App.tsx | 50 +++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index c463676..0aef6ce 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,25 +1,25 @@ -1 import './App.css' -2 import LoginForm from './Pages/LoginForm/LoginForm'; -3 import Register from './Pages/register/Register'; -4 import LandingPage from './Pages/LandingPage' -5 import { BrowserRouter, Routes, Route } from 'react-router-dom'; -6 import Librarylist from './Pages/Librarylist'; -7 import Users from './Pages/Users'; -8 -9 function App() { -10 return ( -11 -12 -13 } /> -14 } /> -15 } /> -16 }/> -17 }/> -18 }/> -19 } /> -20 -21 -22 ) -23 } -24 -25 export default App; +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 ( + + + } /> + } /> + } /> + }/> + }/> + }/> + } /> + + + ) +} + +export default App; From 159d08a19b69a0807cc2327a760e506306961d77 Mon Sep 17 00:00:00 2001 From: Yogesh Choudhary Paliyal Date: Sun, 11 Aug 2024 17:25:00 +0530 Subject: [PATCH 4/4] --- .github/workflows/pr-check.yml | 140 +++++++++++++++++---------------- 1 file changed, 71 insertions(+), 69 deletions(-) diff --git a/.github/workflows/pr-check.yml b/.github/workflows/pr-check.yml index 0c2e4c6..8e74ec1 100644 --- a/.github/workflows/pr-check.yml +++ b/.github/workflows/pr-check.yml @@ -1,69 +1,71 @@ -name: PR Check - -on: - pull_request: - branches: ['main'] - -# 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: false - -jobs: - build: - 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 - - 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 +1 name: PR Check +2 +3 on: +4 pull_request: +5 branches: ['main'] +6 +7 # Sets the GITHUB_TOKEN permissions to allow deployment to GitHub Pages +8 permissions: +9 contents: read +10 pages: write +11 id-token: write +12 +13 # Allow one concurrent deployment +14 concurrency: +15 group: 'pages' +16 cancel-in-progress: false +17 +18 jobs: +19 build: +20 runs-on: ubuntu-latest +21 steps: +22 - name: Checkout +23 uses: actions/checkout@v4 +24 - name: Set up Node +25 uses: actions/setup-node@v4 +26 with: +27 node-version: 20 +28 cache: 'npm' +29 - name: Install dependencies +30 run: npm ci +31 - name: Build +32 run: npm run build +33 - name: Setup Pages +34 uses: actions/configure-pages@v4 +35 - name: Upload artifact +36 uses: actions/upload-pages-artifact@v3 +37 with: +38 path: './dist' +39 - name: Deploy to GitHub Pages +40 id: deployment +41 uses: actions/deploy-pages@v4 +42 +43 pr-deploy: +44 if: github.event_name == 'pull_request' +45 environment: +46 name: github-pages-pr-${{ github.event.pull_request.number }} +47 url: ${{ steps.deployment.outputs.page_url }} +48 runs-on: ubuntu-latest +49 steps: +50 - name: Checkout +51 uses: actions/checkout@v4 +52 - name: Set up Node +53 uses: actions/setup-node@v4 +54 with: +55 node-version: 20 +56 cache: 'npm' +57 - name: Install dependencies +58 run: npm ci +59 - name: Build +60 run: npm run build +61 - name: Setup Pages +62 uses: actions/configure-pages@v4 +63 - name: Delete existing artifact +64 run: rm -rf ./dist +65 - name: Upload artifact +66 uses: actions/upload-pages-artifact@v3 +67 with: +68 path: './dist' +69 - name: Deploy to GitHub Pages +70 id: deployment +71 uses: actions/deploy-pages@v4