diff --git a/.github/actions/build/action.yml b/.github/actions/build/action.yml new file mode 100644 index 00000000..2993627d --- /dev/null +++ b/.github/actions/build/action.yml @@ -0,0 +1,34 @@ +name: Build +description: Builds a project instance, assuming all the correct project files are in the build folder + +inputs: + base: + name: Base path + description: The path to use as a base for linking + required: true + default: / + folder: + name: Build Folder + description: The folder to try to build from + required: true + default: . + +runs: + using: composite + steps: + - name: Setup Node + uses: actions/setup-node@v2 + with: + node-version: 15 + cache: "yarn" + + - run: yarn install + # - run: yarn check + + - name: build + env: + BUILD_FOLDER: ${{ inputs.folder }} + BASE: ${{ inputs.base }} + run: | + cd "$BUILD_FOLDER" + yarn build --base "$BASE" diff --git a/.github/workflows/preview_cleanup.yml b/.github/workflows/preview_cleanup.yml index b7aa1d9a..9eb68100 100644 --- a/.github/workflows/preview_cleanup.yml +++ b/.github/workflows/preview_cleanup.yml @@ -1,8 +1,8 @@ name: Clean Preview #! Safety: -#! this workflow should not execute any code at all -#! see githubs docs on pull_request_target for more +#! this workflow should not execute any untrusted input at all +#! see the docs on `pull_request_target` for more on: pull_request_target: types: [unlabeled] diff --git a/.github/workflows/preview_pull_request.yml b/.github/workflows/preview_pull_request.yml index 6a0a239a..62512ddc 100644 --- a/.github/workflows/preview_pull_request.yml +++ b/.github/workflows/preview_pull_request.yml @@ -1,40 +1,43 @@ name: Preview Pull Request +#! Safety: +#! this workflow should not execute any untrusted input at all +#! see the docs on `pull_request_target` for more on: - pull_request: + pull_request_target: types: [synchronize, reopened, labeled] jobs: - build: + preview: 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') + env: + BASE: refs/pull/${{ github.event.pull_request.number }}/merge + REPO: ${{ github.event.repository.name }} steps: + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 with: # Head commit of the pull request ref: ${{ github.event.pull_request.head.sha }} + path: pull 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 --base "/revite/${{ github.ref }}/" + uses: ./.github/actions/build_preview + with: + base: /${{ env.REPO }}/${{ env.BASE }}/ + folder: pull - name: publish preview uses: JamesIves/github-pages-deploy-action@4.1.5 with: folder: dist branch: build-previews - target-folder: ${{ github.ref }} + target-folder: ${{ env.BASE }} single-commit: true - name: send comment @@ -43,6 +46,6 @@ jobs: header: Preview environment message: | ## Preview environment - https://${{ github.repository_owner }}.github.io/revite/${{ github.ref }}/ + https://${{ github.repository_owner }}.github.io/${{ env.REPO }}/${{ env.BASE }}/ This link will remain active until the `use-preview` label is removed.