From 66c00f08dca62cf0a8cfe96f38c80e45a72b11d0 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 16 Feb 2025 22:40:31 +0900 Subject: [PATCH 1/4] Configure preview action copied from README at https://github.com/rossjrw/pr-preview-action and configured to build jekyll --- .github/workflows/preview.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/preview.yml diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml new file mode 100644 index 000000000..f60ca4f99 --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,33 @@ +name: Deploy PR previews + +on: + pull_request: + types: + - opened + - reopened + - synchronize + - closed + +concurrency: preview-${{ github.ref }} + +jobs: + deploy-preview: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: ruby/setup-ruby@v1 + with: + ruby-version: "3.3" + bundler-cache: true + + - name: Build with Jekyll + run: bundle exec jekyll build + env: + JEKYLL_ENV: production + + - name: Deploy preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./_site/ From 62b997ddf463bf7cfcf7b80c4e8c85f80ea00331 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 16 Feb 2025 22:44:12 +0900 Subject: [PATCH 2/4] Deploy previews to rubima/rubima-preview --- .github/workflows/preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index f60ca4f99..06e559e1e 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -31,3 +31,5 @@ jobs: uses: rossjrw/pr-preview-action@v1 with: source-dir: ./_site/ + deploy-repository: rubima/rubima-preview + token: ${{ secrets.PREVIEW_TOKEN }} From fd24e260af4246513ccd439ca6f1b432d095a411 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 16 Feb 2025 22:44:36 +0900 Subject: [PATCH 3/4] Fetch origin/master after checking out the repo so we can perform git-diff to know which files has been changed in the patch. --- .github/workflows/preview.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 06e559e1e..723ad8088 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -16,6 +16,13 @@ jobs: steps: - name: Checkout uses: actions/checkout@v4 + - name: Fetch master + run: | + commits=${{ github.event.pull_request.commits }} + if [[ -n "$commits" ]]; then + # Prepare enough depth for diffs with master + git fetch --depth="$(( commits + 1 ))" + fi - uses: ruby/setup-ruby@v1 with: From f0d0aa1c5786b10938f1bdc9d3cf59d7b3ed4b8e Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Sun, 16 Feb 2025 23:00:45 +0900 Subject: [PATCH 4/4] Remove unrelated images from _site before deploying to preview repo because the whole build result for 20 years of Rubima is too huge, and most of the size is taken up by images. --- .github/workflows/preview.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 723ad8088..73a4a9df5 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -34,6 +34,9 @@ jobs: env: JEKYLL_ENV: production + - name: Remove unrelated images + run: git diff --name-only origin/master --relative=articles | ruby -nle 'puts $_[%r([0-9]{4}-[0-9]{2}-[0-9]{2}-([0-9]{4}-.+)\.md), 1]' | tr '\n' ',' | ruby -rfileutils -nle 'Dir.chdir("_site/images") { Dir.glob("*").each { FileUtils.rm_r(_1) if File.directory?(_1) && !$_.split(",").include?(_1) } }' + - name: Deploy preview uses: rossjrw/pr-preview-action@v1 with: