From 28df14b7347eeaff1c06eb9b5b2b1b1102ce3f9a Mon Sep 17 00:00:00 2001 From: brecert Date: Fri, 10 Sep 2021 14:48:48 -0400 Subject: [PATCH 1/4] Add pull request preview actions --- .github/workflows/preview_cleanup.yml | 36 +++++++++++++++++ .github/workflows/preview_pull_request.yml | 47 ++++++++++++++++++++++ 2 files changed, 83 insertions(+) create mode 100644 .github/workflows/preview_cleanup.yml create mode 100644 .github/workflows/preview_pull_request.yml diff --git a/.github/workflows/preview_cleanup.yml b/.github/workflows/preview_cleanup.yml new file mode 100644 index 00000000..18ac1de2 --- /dev/null +++ b/.github/workflows/preview_cleanup.yml @@ -0,0 +1,36 @@ +name: Clean Preview + +#! Safety: +#! this workflow should not execute any code at all +#! see githubs docs on pull_request_target for more +on: + pull_request_target: + types: [unlabeled] + +jobs: + clean: + runs-on: ubuntu-latest + if: github.event.label.name == 'use-preview' + + steps: + - uses: actions/checkout@v2 + with: + ref: build-previews + persist-credentials: false + + - name: clean previews + run: 'rm -rf "./refs/pull/${{ github.event.pull_request.number }}"' + + - name: publish cleaned previews + uses: JamesIves/github-pages-deploy-action@4.1.5 + with: + folder: . + branch: build-previews + + - name: send comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: Preview environment + message: | + ## Preview environment + There is no longer a preview enviroment for this pull request due to the `use-preview` label being removed diff --git a/.github/workflows/preview_pull_request.yml b/.github/workflows/preview_pull_request.yml new file mode 100644 index 00000000..8d35f838 --- /dev/null +++ b/.github/workflows/preview_pull_request.yml @@ -0,0 +1,47 @@ +name: Preview Pull Request + +on: + pull_request: + types: [synchronize, reopened, labeled] + +jobs: + build: + runs-on: ubuntu-latest + # make sure the pull request is labeled with 'use-preview' + if: github.event.label.name == 'use-preview' || contains(github.event.pull_request.labels.*.name, 'use-preview') + + steps: + - uses: actions/checkout@v2 + with: + # Head commit of the pull request + ref: ${{ github.event.pull_request.head.sha }} + submodules: recursive + + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 15 + cache: "yarn" + + - run: yarn install + - run: yarn check + + - name: build + run: yarn build + + - name: publish preview + uses: JamesIves/github-pages-deploy-action@4.1.5 + with: + branch: build-previews + folder: dist + target-folder: ${{ github.ref }} + + - name: send comment + uses: marocchino/sticky-pull-request-comment@v2 + with: + header: Preview environment + message: | + ## Preview environment + https://${{ github.repository_owner }}.github.io/revite/${{ github.ref }}/index.html + + This link will remain active until the `use-preview` label is removed. From 08e226cd0cb014aaa2babe4f165d53ec5c78b36a Mon Sep 17 00:00:00 2001 From: brecert Date: Fri, 10 Sep 2021 14:59:37 -0400 Subject: [PATCH 2/4] Disable `yarn check` temporarily --- .github/workflows/preview_pull_request.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview_pull_request.yml b/.github/workflows/preview_pull_request.yml index 8d35f838..d01061b5 100644 --- a/.github/workflows/preview_pull_request.yml +++ b/.github/workflows/preview_pull_request.yml @@ -24,7 +24,7 @@ jobs: cache: "yarn" - run: yarn install - - run: yarn check + # - run: yarn check - name: build run: yarn build From 9bd31c4c7e81139a6dc61589e98c0fd3acd8bd92 Mon Sep 17 00:00:00 2001 From: brecert Date: Fri, 10 Sep 2021 18:03:06 -0400 Subject: [PATCH 3/4] Use base url for building actions --- .github/workflows/preview_pull_request.yml | 2 +- src/context/index.tsx | 2 +- src/env.d.ts | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview_pull_request.yml b/.github/workflows/preview_pull_request.yml index d01061b5..3f7d4019 100644 --- a/.github/workflows/preview_pull_request.yml +++ b/.github/workflows/preview_pull_request.yml @@ -27,7 +27,7 @@ jobs: # - run: yarn check - name: build - run: yarn build + run: yarn build --base "/revite/${{ github.ref }}/" - name: publish preview uses: JamesIves/github-pages-deploy-action@4.1.5 diff --git a/src/context/index.tsx b/src/context/index.tsx index 60f3694c..0abdbdb8 100644 --- a/src/context/index.tsx +++ b/src/context/index.tsx @@ -11,7 +11,7 @@ import Client from "./revoltjs/RevoltClient"; export default function Context({ children }: { children: Children }) { return ( - + diff --git a/src/env.d.ts b/src/env.d.ts index bcd82398..3cbd1274 100644 --- a/src/env.d.ts +++ b/src/env.d.ts @@ -1,6 +1,7 @@ interface ImportMetaEnv { VITE_API_URL: string; VITE_THEMES_URL: string; + BASE_URL: string; } interface ImportMeta { From 4a5d78d909b1bbcb787ec1d9e0433e8fed97ffe1 Mon Sep 17 00:00:00 2001 From: brecert Date: Sat, 11 Sep 2021 10:12:14 -0400 Subject: [PATCH 4/4] Use `single-commit` for build-previews --- .github/workflows/preview_cleanup.yml | 1 + .github/workflows/preview_pull_request.yml | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/preview_cleanup.yml b/.github/workflows/preview_cleanup.yml index 18ac1de2..b7aa1d9a 100644 --- a/.github/workflows/preview_cleanup.yml +++ b/.github/workflows/preview_cleanup.yml @@ -26,6 +26,7 @@ jobs: with: folder: . branch: build-previews + single-commit: true - name: send comment uses: marocchino/sticky-pull-request-comment@v2 diff --git a/.github/workflows/preview_pull_request.yml b/.github/workflows/preview_pull_request.yml index 3f7d4019..6a0a239a 100644 --- a/.github/workflows/preview_pull_request.yml +++ b/.github/workflows/preview_pull_request.yml @@ -32,9 +32,10 @@ jobs: - name: publish preview uses: JamesIves/github-pages-deploy-action@4.1.5 with: - branch: build-previews folder: dist + branch: build-previews target-folder: ${{ github.ref }} + single-commit: true - name: send comment uses: marocchino/sticky-pull-request-comment@v2 @@ -42,6 +43,6 @@ jobs: header: Preview environment message: | ## Preview environment - https://${{ github.repository_owner }}.github.io/revite/${{ github.ref }}/index.html + https://${{ github.repository_owner }}.github.io/revite/${{ github.ref }}/ This link will remain active until the `use-preview` label is removed.