From 5eb2732c00e2bdbb9f48a3bca27c8b61f94f76c9 Mon Sep 17 00:00:00 2001 From: ROBOT Date: Fri, 19 Dec 2025 20:39:28 +0900 Subject: [PATCH 1/4] add: pull request page preview --- .github/workflows/preview.yml | 45 +++++++++++++++++++++++++++++++++++ 1 file changed, 45 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 0000000..64c788d --- /dev/null +++ b/.github/workflows/preview.yml @@ -0,0 +1,45 @@ +name: Preview + +on: + pull_request: + types: [opened, synchronize, reopened, closed] + +concurrency: preview-${{ github.ref }} + +jobs: + preview: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Checkout mdbook + uses: peaceiris/actions-mdbook@v2 + with: + mdbook-version: "latest" + - name: Build mdbook + run: mdbook build --dest-dir out + + - name: Cache Cargo registry and Cargo bin + id: cargo-cache + uses: actions/cache@v5 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock','**/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Install mdbook-utils + if: steps.cargo-cache.outputs.cache-hit != 'true' + run: cargo install mdbook-utils + + - name: Generate sitemap + run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y + + - name: Deploy preview + uses: rossjrw/pr-preview-action@v1 + with: + source-dir: ./out/ From 02e2d596d52cad1e9a024c697d1ec1e68a16c77a Mon Sep 17 00:00:00 2001 From: ROBOT Date: Sat, 3 Jan 2026 15:00:15 +0900 Subject: [PATCH 2/4] fix: preview site action --- .github/workflows/gh-pages.yml | 40 +++++++++++++++++++++ .github/workflows/preview.yml | 66 ++++++++++++++++++++++++++++++---- 2 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/gh-pages.yml diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 0000000..72141c0 --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,40 @@ +name: Deploy site to Github Pages + +on: + push: + branches: ["gh-pages"] + workflow_dispatch: + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + deploy: + name: Deploy + + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./out + + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 \ No newline at end of file diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 64c788d..4dde78b 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -1,22 +1,33 @@ -name: Preview +name: Deploy PR previews on: pull_request: types: [opened, synchronize, reopened, closed] -concurrency: preview-${{ github.ref }} +permissions: + contents: write + pull-requests: write + +concurrency: + group: pr-${{ github.event.pull_request.number }} + cancel-in-progress: true + +env: + PAGE_DIR: pr-preview-${{ github.event.pull_request.number }} jobs: - preview: + build-and-commit: + if: github.event.action != 'closed' runs-on: ubuntu-latest steps: - - name: Checkout repo + - name: Checkout repository uses: actions/checkout@v4 - name: Checkout mdbook uses: peaceiris/actions-mdbook@v2 with: mdbook-version: "latest" + - name: Build mdbook run: mdbook build --dest-dir out @@ -39,7 +50,48 @@ jobs: - name: Generate sitemap run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y - - name: Deploy preview - uses: rossjrw/pr-preview-action@v1 + - name: Move out directory + run: mv out /tmp/out + + - name: Checkout gh-pages + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Commit changes to gh-pages branch + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "action@github.com" + mkdir -p /out/preview/${{ env.PAGE_DIR }} + mv /tmp/out /out/preview/${{ env.PAGE_DIR }} + git add . + git commit -m "Deploy PR preview for #${{ github.event.pull_request.number }}" + git push origin gh-pages + + - name: Comment PR + uses: actions/github-script@v7 with: - source-dir: ./out/ + script: | + github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: `Preview deployed to: https://${context.repo.owner}.github.io/preview/${process.env.PAGE_DIR}` + }) + + cleanup: + if: github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - name: Checkout gh-pages + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Remove preview directory + run: | + rm -rf /out/preview/${{ env.PAGE_DIR }} || exit 0 + git config user.name github-actions + git config user.email github-actions@github.com + git add . + git commit -m "Remove PR preview for #${{ github.event.pull_request.number }}" && git push origin gh-pages || echo "No changes to commit" From 4d21912616309be378b38db6c8acbdd42aafafc4 Mon Sep 17 00:00:00 2001 From: ROBOT Date: Sun, 4 Jan 2026 07:58:46 +0900 Subject: [PATCH 3/4] add: deploy.yml --- .github/workflows/CI.yml | 19 +------- .github/workflows/deploy.yml | 87 +++++++++++++++++++++++++++++++++++ .github/workflows/preview.yml | 16 ++++--- 3 files changed, 97 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index cd2dc9b..b1a0618 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -1,9 +1,8 @@ name: CI on: + pull_request: push: - branches: - - main permissions: contents: read @@ -41,19 +40,3 @@ jobs: - name: Generate sitemap run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y - - - name: Upload Pages artifact - uses: actions/upload-pages-artifact@v4 - with: - path: ./out - - deploy: - needs: build - runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - steps: - - name: Deploy - id: deployment - uses: actions/deploy-pages@v4 diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..c4c67fb --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,87 @@ +name: Deploy site to Github Pages + +on: + push: + branches: ["main"] + workflow_dispatch: + +permissions: + contents: write + +concurrency: + group: "pages" + cancel-in-progress: true + +jobs: + build-and-commit: + name: Deploy + + runs-on: ubuntu-latest + + steps: + - name: Checkout main + uses: actions/checkout@v4 + + - name: Checkout mdbook + uses: peaceiris/actions-mdbook@v2 + with: + mdbook-version: "latest" + + - name: Build mdbook + run: mdbook build --dest-dir out + + - name: Cache Cargo registry and Cargo bin + id: cargo-cache + uses: actions/cache@v5 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock','**/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Install mdbook-utils + if: steps.cargo-cache.outputs.cache-hit != 'true' + run: cargo install mdbook-utils + + - name: Generate sitemap + run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y + + - name: Move out directory + run: | + mkdir -p tmp/out + mv out tmp/out + + - name: Checkout gh-pages + uses: actions/checkout@v4 + with: + ref: gh-pages + + - name: Preserve specific directories + run: | + mkdir -p preserve + mv out/preview preserve/preview + + - name: Adapt new build + run: | + mv -f tmp/out out + mv -f preserve/preview out/preview + + - name: Clean + run: | + find . -type f ! -path "./.github/*" ! -path "./out/*" ! -path "./.git/*" -delete + + - name: Commit changes to gh-pages branch + run: | + git config --global user.name "GitHub Actions" + git config --global user.email "action@github.com" + git add -N . + set +e + git diff --exit-code --quiet + if [[ $? -eq 1 ]]; then + git add . + git commit -m "Deploy to gh-pages: ${{ github.sha }}" + git push origin gh-pages + fi diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 4dde78b..88c3e21 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -51,7 +51,9 @@ jobs: run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y - name: Move out directory - run: mv out /tmp/out + run: | + mkdir -p tmp/out + mv -f out tmp/out - name: Checkout gh-pages uses: actions/checkout@v4 @@ -62,8 +64,8 @@ jobs: run: | git config --global user.name "GitHub Actions" git config --global user.email "action@github.com" - mkdir -p /out/preview/${{ env.PAGE_DIR }} - mv /tmp/out /out/preview/${{ env.PAGE_DIR }} + mkdir -p out/preview/${{ env.PAGE_DIR }} + mv tmp/out /out/preview/${{ env.PAGE_DIR }} git add . git commit -m "Deploy PR preview for #${{ github.event.pull_request.number }}" git push origin gh-pages @@ -90,8 +92,8 @@ jobs: - name: Remove preview directory run: | - rm -rf /out/preview/${{ env.PAGE_DIR }} || exit 0 - git config user.name github-actions - git config user.email github-actions@github.com - git add . + rm -rf ./out/preview/${{ env.PAGE_DIR }} || exit 0 + git config user.name github-actions + git config user.email github-actions@github.com + git add . git commit -m "Remove PR preview for #${{ github.event.pull_request.number }}" && git push origin gh-pages || echo "No changes to commit" From b40e49b93d745236eee720b527b2087b2ff74177 Mon Sep 17 00:00:00 2001 From: ROBOT Date: Sun, 4 Jan 2026 08:03:05 +0900 Subject: [PATCH 4/4] add: build component --- .github/workflows/CI.yml | 30 ++++---------------------- .github/workflows/build/action.yml | 34 ++++++++++++++++++++++++++++++ .github/workflows/deploy.yml | 30 +++----------------------- .github/workflows/preview.yml | 30 +++----------------------- 4 files changed, 44 insertions(+), 80 deletions(-) create mode 100644 .github/workflows/build/action.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b1a0618..0df2b5f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -13,30 +13,8 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 + - name: Checkout repo + uses: actions/checkout@v4 - - uses: peaceiris/actions-mdbook@v2 - with: - mdbook-version: "latest" - - - name: Build mdbook - run: mdbook build --dest-dir out - - - name: Cache Cargo registry and Cargo bin - id: cargo-cache - uses: actions/cache@v5 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock','**/Cargo.toml') }} - restore-keys: | - ${{ runner.os }}-cargo- - - - name: Install mdbook-utils - if: steps.cargo-cache.outputs.cache-hit != 'true' - run: cargo install mdbook-utils - - - name: Generate sitemap - run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y + - name: Build Check + uses: ./.github/workflows/build diff --git a/.github/workflows/build/action.yml b/.github/workflows/build/action.yml new file mode 100644 index 0000000..6e4d091 --- /dev/null +++ b/.github/workflows/build/action.yml @@ -0,0 +1,34 @@ +name: Build + +runs: + using: 'composite' + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Install mdbook + uses: peaceiris/actions-mdbook@v2 + with: + mdbook-version: "latest" + + - name: Build mdbook + run: mdbook build --dest-dir out + + - name: Cache Cargo registry and Cargo bin + id: cargo-cache + uses: actions/cache@v5 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + ~/.cargo/bin + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock','**/Cargo.toml') }} + restore-keys: | + ${{ runner.os }}-cargo- + + - name: Install mdbook-utils + if: steps.cargo-cache.outputs.cache-hit != 'true' + run: cargo install mdbook-utils + + - name: Generate sitemap + run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c4c67fb..5b0a7f3 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -19,35 +19,11 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout main + - name: Checkout repo uses: actions/checkout@v4 - - name: Checkout mdbook - uses: peaceiris/actions-mdbook@v2 - with: - mdbook-version: "latest" - - - name: Build mdbook - run: mdbook build --dest-dir out - - - name: Cache Cargo registry and Cargo bin - id: cargo-cache - uses: actions/cache@v5 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock','**/Cargo.toml') }} - restore-keys: | - ${{ runner.os }}-cargo- - - - name: Install mdbook-utils - if: steps.cargo-cache.outputs.cache-hit != 'true' - run: cargo install mdbook-utils - - - name: Generate sitemap - run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y + - name: Build Check + uses: ./.github/workflows/build - name: Move out directory run: | diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 88c3e21..6018fe4 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -20,35 +20,11 @@ jobs: if: github.event.action != 'closed' runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: Checkout repo uses: actions/checkout@v4 - - name: Checkout mdbook - uses: peaceiris/actions-mdbook@v2 - with: - mdbook-version: "latest" - - - name: Build mdbook - run: mdbook build --dest-dir out - - - name: Cache Cargo registry and Cargo bin - id: cargo-cache - uses: actions/cache@v5 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - ~/.cargo/bin - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock','**/Cargo.toml') }} - restore-keys: | - ${{ runner.os }}-cargo- - - - name: Install mdbook-utils - if: steps.cargo-cache.outputs.cache-hit != 'true' - run: cargo install mdbook-utils - - - name: Generate sitemap - run: mdbook-utils sitemap -o out/sitemap.xml -b https://rsdocsjp.org/ -y + - name: Build Check + uses: ./.github/workflows/build - name: Move out directory run: |