From 5efdee6445b5fdf592d9393f79d45a7c13889939 Mon Sep 17 00:00:00 2001 From: John Dunning Date: Sat, 30 Nov 2024 11:58:50 -0800 Subject: [PATCH 1/3] Update preview.yml to use same build steps as deploy.yml Add test.md. --- .github/workflows/deploy.yml | 1 + .github/workflows/preview.yml | 55 +++++++++++++++++++++++++++++++---- src/pages/test.md | 8 +++++ 3 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 src/pages/test.md diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 27b1c16..2c30b73 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -58,6 +58,7 @@ jobs: node-version: "20" cache: ${{ steps.detect-package-manager.outputs.manager }} cache-dependency-path: ${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} + - name: Setup Pages id: pages uses: actions/configure-pages@v5 diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 97d4ad5..53a22e7 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -15,13 +15,58 @@ jobs: runs-on: ubuntu-20.04 steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - - name: Install and Build - if: github.event.action != 'closed' # You might want to skip the build if the PR has been closed + - name: Detect package manager + id: detect-package-manager run: | - npm install - npm run build + if [ -f "${{ github.workspace }}/yarn.lock" ]; then + echo "manager=yarn" >> $GITHUB_OUTPUT + echo "command=install" >> $GITHUB_OUTPUT + echo "runner=yarn" >> $GITHUB_OUTPUT + echo "lockfile=yarn.lock" >> $GITHUB_OUTPUT + exit 0 + elif [ -f "${{ github.workspace }}/package.json" ]; then + echo "manager=npm" >> $GITHUB_OUTPUT + echo "command=ci" >> $GITHUB_OUTPUT + echo "runner=npx --no-install" >> $GITHUB_OUTPUT + echo "lockfile=package-lock.json" >> $GITHUB_OUTPUT + exit 0 + else + echo "Unable to determine package manager" + exit 1 + fi + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: "20" + cache: ${{ steps.detect-package-manager.outputs.manager }} + cache-dependency-path: ${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} + + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 + + - name: Install dependencies + run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} + working-directory: ${{ env.BUILD_PATH }} + + - name: Build with Astro + run: | + ${{ steps.detect-package-manager.outputs.runner }} astro build \ + --site "${{ steps.pages.outputs.origin }}" \ + --base "${{ steps.pages.outputs.base_path }}" + working-directory: ${{ env.BUILD_PATH }} + +# - name: Checkout +# uses: actions/checkout@v3 +# +# - name: Install and Build +# if: github.event.action != 'closed' # You might want to skip the build if the PR has been closed +# run: | +# npm install +# npm run build - name: Deploy preview uses: rossjrw/pr-preview-action@v1 diff --git a/src/pages/test.md b/src/pages/test.md new file mode 100644 index 0000000..73a8b73 --- /dev/null +++ b/src/pages/test.md @@ -0,0 +1,8 @@ +--- +layout: "@/layouts/BaseLayout.astro" +title: Testy Test Test +--- + +## Hello, world + +This is a test page in a PR preview. From 4e8c846fb38a50e36e0d6685e105efc9436f9cb1 Mon Sep 17 00:00:00 2001 From: John Dunning Date: Sat, 30 Nov 2024 12:02:10 -0800 Subject: [PATCH 2/3] Add ref to cache path --- .github/workflows/preview.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 53a22e7..80c7817 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -42,7 +42,7 @@ jobs: with: node-version: "20" cache: ${{ steps.detect-package-manager.outputs.manager }} - cache-dependency-path: ${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} + cache-dependency-path: preview-${{ github.ref }}/${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} - name: Setup Pages id: pages From 4277e09572bb899201b1784b4d782011ddabb2fd Mon Sep 17 00:00:00 2001 From: John Dunning Date: Sat, 30 Nov 2024 12:06:51 -0800 Subject: [PATCH 3/3] Fix BUILD_PATH env in preview.yml --- .github/workflows/preview.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 80c7817..7502d48 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -10,6 +10,11 @@ on: concurrency: preview-${{ github.ref }} +env: + BUILD_PATH: "." # default value when not using subfolders + POSTHOG_API_KEY: ${{ secrets.POSTHOG_API_KEY }} + ACTIONS_STEP_DEBUG: true + jobs: deploy-preview: runs-on: ubuntu-20.04 @@ -42,7 +47,7 @@ jobs: with: node-version: "20" cache: ${{ steps.detect-package-manager.outputs.manager }} - cache-dependency-path: preview-${{ github.ref }}/${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} + cache-dependency-path: ${{ env.BUILD_PATH }}/${{ steps.detect-package-manager.outputs.lockfile }} - name: Setup Pages id: pages