From 92d50050ccc4ddd6b170c713fb6ec49daef9d0bf Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Mon, 27 May 2024 22:50:05 +0530 Subject: [PATCH 1/7] Create deploypr.yml --- .github/workflows/deploypr.yml | 1 + 1 file changed, 1 insertion(+) create mode 100644 .github/workflows/deploypr.yml diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/.github/workflows/deploypr.yml @@ -0,0 +1 @@ + From 885c135d2570c0803cec4d7e19289c5885e23094 Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Mon, 27 May 2024 23:11:42 +0530 Subject: [PATCH 2/7] Update deploypr.yml --- .github/workflows/deploypr.yml | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml index 8b137891..50c95b30 100644 --- a/.github/workflows/deploypr.yml +++ b/.github/workflows/deploypr.yml @@ -1 +1,65 @@ +name: Deploy Preview +on: + pull_request: + branches: + - main + - dev + types: [opened, synchronize, reopened, closed] + +jobs: + build: + if: github.event.action != 'closed' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: '16' + + - name: Install dependencies + run: npm install + + - name: Build project + run: npm run build + + - name: Deploy to GitHub Pages + uses: peaceiris/actions-gh-pages@v3 + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + publish_dir: ./build + destination_dir: preview/${{ github.event.pull_request.number }} + + - name: Post preview link as a comment + uses: actions/github-script@v6 + with: + script: | + const prNumber = context.issue.number; + const comment = `Preview your changes [here](https://.github.io//preview/${prNumber})`; + github.rest.issues.createComment({ + ...context.repo, + issue_number: prNumber, + body: comment + }); + + cleanup: + if: github.event.action == 'closed' + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: Delete preview directory + run: | + git fetch + git checkout gh-pages + git rm -rf preview/${{ github.event.pull_request.number }} + git commit -m "Delete preview for PR #${{ github.event.pull_request.number }}" + git push origin gh-pages + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From b813e91a86018e172e0a2a843734b1d0315e4460 Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Mon, 27 May 2024 23:16:57 +0530 Subject: [PATCH 3/7] Update deploypr.yml --- .github/workflows/deploypr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml index 50c95b30..21ae4ebd 100644 --- a/.github/workflows/deploypr.yml +++ b/.github/workflows/deploypr.yml @@ -4,7 +4,7 @@ on: pull_request: branches: - main - - dev + - uptane_docusaurus types: [opened, synchronize, reopened, closed] jobs: @@ -19,7 +19,7 @@ jobs: - name: Set up Node.js uses: actions/setup-node@v3 with: - node-version: '16' + node-version: '20' - name: Install dependencies run: npm install From 3cf04299211c574900801ac0041399a72fd33647 Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Tue, 28 May 2024 09:29:40 +0530 Subject: [PATCH 4/7] Update deploypr.yml --- .github/workflows/deploypr.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml index 21ae4ebd..a6e15b66 100644 --- a/.github/workflows/deploypr.yml +++ b/.github/workflows/deploypr.yml @@ -22,10 +22,10 @@ jobs: node-version: '20' - name: Install dependencies - run: npm install + run: yarn install - name: Build project - run: npm run build + run: yarn build - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 From 6dc8aa8d34824f99c734e4e60af235ec2dcef749 Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Tue, 28 May 2024 09:47:13 +0530 Subject: [PATCH 5/7] Update deploypr.yml --- .github/workflows/deploypr.yml | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml index a6e15b66..29f12682 100644 --- a/.github/workflows/deploypr.yml +++ b/.github/workflows/deploypr.yml @@ -11,6 +11,8 @@ jobs: build: if: github.event.action != 'closed' runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout code @@ -27,6 +29,14 @@ jobs: - name: Build project run: yarn build + - name: Checkout gh-pages branch + run: | + git fetch + git checkout gh-pages + + - name: Ensure preview directory exists + run: mkdir -p preview/${{ github.event.pull_request.number }} + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: @@ -39,16 +49,18 @@ jobs: with: script: | const prNumber = context.issue.number; - const comment = `Preview your changes [here](https://.github.io//preview/${prNumber})`; + const previewUrl = `https://${{ github.repository_owner }}.github.io/${{ github.repository }}/preview/${prNumber}`; github.rest.issues.createComment({ ...context.repo, issue_number: prNumber, - body: comment + body: `Preview your changes [here](${previewUrl})` }); cleanup: if: github.event.action == 'closed' runs-on: ubuntu-latest + permissions: + contents: write steps: - name: Checkout code @@ -58,8 +70,10 @@ jobs: run: | git fetch git checkout gh-pages - git rm -rf preview/${{ github.event.pull_request.number }} - git commit -m "Delete preview for PR #${{ github.event.pull_request.number }}" - git push origin gh-pages + if [ -d "preview/${{ github.event.pull_request.number }}" ]; then + git rm -rf preview/${{ github.event.pull_request.number }} + git commit -m "Delete preview for PR #${{ github.event.pull_request.number }}" + git push origin gh-pages + fi env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 0dac963de82a35769b59bd89879db3837cc1ae87 Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Tue, 28 May 2024 10:34:10 +0530 Subject: [PATCH 6/7] Update deploypr.yml --- .github/workflows/deploypr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml index 29f12682..d7743628 100644 --- a/.github/workflows/deploypr.yml +++ b/.github/workflows/deploypr.yml @@ -40,7 +40,7 @@ jobs: - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: - github_token: ${{ secrets.GITHUB_TOKEN }} + github_token: ${{ secrets.DEPLOYMENT_TOKEN }} publish_dir: ./build destination_dir: preview/${{ github.event.pull_request.number }} From 5a6206dff7b387bdccdc3f3541c82a3485b9071a Mon Sep 17 00:00:00 2001 From: SHUBHAM SHARMA <96301987+shubhusion@users.noreply.github.com> Date: Tue, 28 May 2024 15:23:56 +0530 Subject: [PATCH 7/7] Update deploypr.yml --- .github/workflows/deploypr.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploypr.yml b/.github/workflows/deploypr.yml index d7743628..29f12682 100644 --- a/.github/workflows/deploypr.yml +++ b/.github/workflows/deploypr.yml @@ -40,7 +40,7 @@ jobs: - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 with: - github_token: ${{ secrets.DEPLOYMENT_TOKEN }} + github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./build destination_dir: preview/${{ github.event.pull_request.number }}