From 5a60020a7ac222f23fdd7eb22450318349bb27be Mon Sep 17 00:00:00 2001 From: Shimo-1999 <63487964+Shimo-1999@users.noreply.github.com> Date: Tue, 7 Oct 2025 09:36:58 +0900 Subject: [PATCH 1/6] ci: switch to gh-pages workflow and remove static.yml --- .github/workflows/gh-pages.yml | 75 ++++++++++++++++++++++++++++++++++ .github/workflows/static.yml | 43 ------------------- 2 files changed, 75 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/gh-pages.yml delete mode 100644 .github/workflows/static.yml diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml new file mode 100644 index 0000000..b0cbf2c --- /dev/null +++ b/.github/workflows/gh-pages.yml @@ -0,0 +1,75 @@ +name: Deploy to GitHub Pages + +on: + push: + branches: [main] + pull_request: {} + workflow_dispatch: {} + +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - uses: actions/cache@v4 + with: + path: | + ~/.cargo/registry + ~/.cargo/git + target + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: jetli/wasm-pack-action@v0.4.0 + - name: Build wasm (target web) + working-directory: wasm_project + run: wasm-pack build --release --target web + + - name: Prepare dist + run: | + mkdir -p dist + cp index.html dist/ + cp -r js dist/js + cp gif.js dist/gif.js + cp gif.worker.js dist/gif.worker.js + mkdir -p dist/wasm_project + cp -r wasm_project/pkg dist/wasm_project/pkg + mkdir -p dist/test/images + cp -r test/images/* dist/test/images/ || true + + - name: Upload artifact for Pages + uses: actions/upload-pages-artifact@v3 + with: + path: dist + + deploy-preview: + if: ${{ github.event_name == 'pull_request' }} + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy preview + id: deployment + uses: actions/deploy-pages@v4 + + deploy: + if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + needs: build + runs-on: ubuntu-latest + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/static.yml b/.github/workflows/static.yml deleted file mode 100644 index f2c9e97..0000000 --- a/.github/workflows/static.yml +++ /dev/null @@ -1,43 +0,0 @@ -# Simple workflow for deploying static content to GitHub Pages -name: Deploy static content to Pages - -on: - # Runs on pushes targeting the default branch - push: - branches: ["main"] - - # Allows you to run this workflow manually from the Actions tab - workflow_dispatch: - -# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages -permissions: - contents: read - pages: write - id-token: write - -# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. -# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. -concurrency: - group: "pages" - cancel-in-progress: false - -jobs: - # Single deploy job since we're just deploying - deploy: - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - name: Setup Pages - uses: actions/configure-pages@v5 - - name: Upload artifact - uses: actions/upload-pages-artifact@v3 - with: - # Upload entire repository - path: '.' - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 From ca3124a8d306b571622845fc33c19cb6c46e97a8 Mon Sep 17 00:00:00 2001 From: Shimo-1999 <63487964+Shimo-1999@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:30:08 +0900 Subject: [PATCH 2/6] ci(pages): enable PR preview with separate environment --- .github/workflows/gh-pages.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index b0cbf2c..7b2d855 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -12,7 +12,7 @@ permissions: id-token: write concurrency: - group: "pages" + group: pages-${{ github.event_name }}-${{ github.ref }} cancel-in-progress: false jobs: @@ -55,15 +55,17 @@ jobs: needs: build runs-on: ubuntu-latest environment: - name: github-pages + name: github-pages-preview url: ${{ steps.deployment.outputs.page_url }} steps: - name: Deploy preview id: deployment uses: actions/deploy-pages@v4 + with: + preview: true deploy: - if: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} + if: ${{ github.ref == 'refs/heads/main' }} needs: build runs-on: ubuntu-latest environment: From a3d4f26f196660d18afad2a0eb17e11f6988c2dd Mon Sep 17 00:00:00 2001 From: Shimo-1999 <63487964+Shimo-1999@users.noreply.github.com> Date: Tue, 7 Oct 2025 10:33:30 +0900 Subject: [PATCH 3/6] Update .github/workflows/gh-pages.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- .github/workflows/gh-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 7b2d855..eff2e33 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -43,7 +43,7 @@ jobs: mkdir -p dist/wasm_project cp -r wasm_project/pkg dist/wasm_project/pkg mkdir -p dist/test/images - cp -r test/images/* dist/test/images/ || true + if [ -d "test/images" ]; then cp -r test/images/* dist/test/images/; else echo "Warning: test/images directory does not exist, skipping image copy."; fi - name: Upload artifact for Pages uses: actions/upload-pages-artifact@v3 From b40120e8249ed153f45ae2c5130bb1bc5909361e Mon Sep 17 00:00:00 2001 From: Shimo-1999 <63487964+Shimo-1999@users.noreply.github.com> Date: Tue, 7 Oct 2025 11:27:01 +0900 Subject: [PATCH 4/6] ci(gh-pages): add branch-based Pages deploy with PR previews --- .github/workflows/gh-pages.yml | 148 ++++++++++++++++++++++++--------- 1 file changed, 109 insertions(+), 39 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index eff2e33..85e24bc 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -1,25 +1,29 @@ -name: Deploy to GitHub Pages +name: Deploy (branch-based GitHub Pages) on: push: branches: [main] - pull_request: {} - workflow_dispatch: {} + pull_request: + types: [opened, synchronize, reopened] + pull_request_target: + types: [closed] permissions: - contents: read - pages: write - id-token: write + contents: write + pages: read + id-token: none -concurrency: - group: pages-${{ github.event_name }}-${{ github.ref }} - cancel-in-progress: false +env: + DIST_DIR: dist + GH_PAGES_DIR: ghp_worktree + PREVIEW_DIR: pr-preview-${{ github.event.pull_request.number }} jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable - uses: actions/cache@v4 with: @@ -28,50 +32,116 @@ jobs: ~/.cargo/git target key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - uses: jetli/wasm-pack-action@v0.4.0 + - name: Build wasm (target web) working-directory: wasm_project run: wasm-pack build --release --target web - name: Prepare dist run: | - mkdir -p dist - cp index.html dist/ - cp -r js dist/js - cp gif.js dist/gif.js - cp gif.worker.js dist/gif.worker.js - mkdir -p dist/wasm_project - cp -r wasm_project/pkg dist/wasm_project/pkg - mkdir -p dist/test/images - if [ -d "test/images" ]; then cp -r test/images/* dist/test/images/; else echo "Warning: test/images directory does not exist, skipping image copy."; fi - - - name: Upload artifact for Pages - uses: actions/upload-pages-artifact@v3 + mkdir -p $DIST_DIR + cp index.html $DIST_DIR/ + cp -r js $DIST_DIR/js + cp gif.js $DIST_DIR/gif.js + cp gif.worker.js $DIST_DIR/gif.worker.js + mkdir -p $DIST_DIR/wasm_project + cp -r wasm_project/pkg $DIST_DIR/wasm_project/pkg + if [ -d test/images ]; then + mkdir -p $DIST_DIR/test/images + cp -r test/images/* $DIST_DIR/test/images/ + fi + touch $DIST_DIR/.nojekyll + + - name: Upload dist + uses: actions/upload-artifact@v4 with: - path: dist + name: site + path: ${{ env.DIST_DIR }} - deploy-preview: - if: ${{ github.event_name == 'pull_request' }} + deploy: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' needs: build runs-on: ubuntu-latest - environment: - name: github-pages-preview - url: ${{ steps.deployment.outputs.page_url }} steps: - - name: Deploy preview - id: deployment - uses: actions/deploy-pages@v4 + - uses: actions/checkout@v4 with: - preview: true + ref: gh-pages + path: ${{ env.GH_PAGES_DIR }} - deploy: - if: ${{ github.ref == 'refs/heads/main' }} + - uses: actions/download-artifact@v4 + with: + name: site + path: ${{ env.DIST_DIR }} + + - name: Commit prod to gh-pages root + run: | + rsync -a --delete "${DIST_DIR}/" "${GH_PAGES_DIR}/" + cd "${GH_PAGES_DIR}" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + if git status --porcelain | grep .; then + git add -A + git commit -m "deploy: main → gh-pages (prod)" + git push + else + echo "No changes." + fi + + deploy-preview: + if: github.event_name == 'pull_request' needs: build runs-on: ubuntu-latest - environment: - name: github-pages - url: ${{ steps.deployment.outputs.page_url }} steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 + - uses: actions/checkout@v4 + with: + ref: gh-pages + path: ${{ env.GH_PAGES_DIR }} + + - uses: actions/download-artifact@v4 + with: + name: site + path: ${{ env.DIST_DIR }} + + - name: Commit preview to pr subdir + run: | + mkdir -p "${GH_PAGES_DIR}/${PREVIEW_DIR}" + rsync -a --delete "${DIST_DIR}/" "${GH_PAGES_DIR}/${PREVIEW_DIR}/" + cd "${GH_PAGES_DIR}" + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + if git status --porcelain | grep .; then + git add -A + git commit -m "deploy: preview for PR #${{ github.event.pull_request.number }}" + git push + else + echo "No changes." + fi + + - name: Preview URL + run: echo "🔗 https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${PREVIEW_DIR}/" + + cleanup-preview: + if: github.event_name == 'pull_request_target' && github.event.action == 'closed' + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: gh-pages + path: ${{ env.GH_PAGES_DIR }} + + - name: Remove preview dir and push + env: + PREVIEW_DIR: pr-preview-${{ github.event.pull_request.number }} + run: | + cd "${GH_PAGES_DIR}" + if [ -d "${PREVIEW_DIR}" ]; then + git config user.name "github-actions[bot]" + git config user.email "41898282+github-actions[bot]@users.noreply.github.com" + git rm -r "${PREVIEW_DIR}" + git commit -m "cleanup: preview for PR #${{ github.event.pull_request.number }}" + git push + else + echo "Preview dir not found (already cleaned)." + fi From 7b34aea336cf28514ddd086b6e25ac0fdea7731e Mon Sep 17 00:00:00 2001 From: Shimo-1999 <63487964+Shimo-1999@users.noreply.github.com> Date: Tue, 7 Oct 2025 11:41:01 +0900 Subject: [PATCH 5/6] ci(gh-pages): comment PR preview URL via actions/github-script --- .github/workflows/gh-pages.yml | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 85e24bc..0ec71de 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -119,8 +119,33 @@ jobs: echo "No changes." fi - - name: Preview URL - run: echo "🔗 https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${PREVIEW_DIR}/" + - name: Compute preview URL + id: preview + run: echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${PREVIEW_DIR}/" >> $GITHUB_OUTPUT + + - name: Post preview URL as PR comment + if: ${{ github.event.pull_request.head.repo.fork == false }} + uses: actions/github-script@v7 + with: + script: | + const url = core.getInput('url'); + const number = context.payload.pull_request.number; + const body = `🚀 **Preview** is ready:\n\n${url}\n\n_This link auto-updates on every push to this PR._`; + await github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: number, + body + }); + result-encoding: string + github-token: ${{ secrets.GITHUB_TOKEN }} + env: + url: ${{ steps.preview.outputs.url }} + + - name: Write preview URL to job summary + run: | + echo "### Preview" >> $GITHUB_STEP_SUMMARY + echo "${{ steps.preview.outputs.url }}" >> $GITHUB_STEP_SUMMARY cleanup-preview: if: github.event_name == 'pull_request_target' && github.event.action == 'closed' From a608157fcc5b9decd04a4234fd4c3f4ca0759637 Mon Sep 17 00:00:00 2001 From: Shimo-1999 <63487964+Shimo-1999@users.noreply.github.com> Date: Tue, 7 Oct 2025 12:13:49 +0900 Subject: [PATCH 6/6] ci(pages): allow posting preview URL comments on PRs --- .github/workflows/gh-pages.yml | 46 +++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index 0ec71de..4b93b39 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -9,7 +9,7 @@ on: types: [closed] permissions: - contents: write + contents: read pages: read id-token: none @@ -21,6 +21,8 @@ env: jobs: build: runs-on: ubuntu-latest + permissions: + contents: read steps: - uses: actions/checkout@v4 @@ -41,18 +43,19 @@ jobs: - name: Prepare dist run: | - mkdir -p $DIST_DIR - cp index.html $DIST_DIR/ - cp -r js $DIST_DIR/js - cp gif.js $DIST_DIR/gif.js - cp gif.worker.js $DIST_DIR/gif.worker.js - mkdir -p $DIST_DIR/wasm_project - cp -r wasm_project/pkg $DIST_DIR/wasm_project/pkg + set -euo pipefail + mkdir -p "$DIST_DIR" + cp index.html "$DIST_DIR/" + cp -r js "$DIST_DIR/js" + cp gif.js "$DIST_DIR/gif.js" + cp gif.worker.js "$DIST_DIR/gif.worker.js" + mkdir -p "$DIST_DIR/wasm_project" + cp -r wasm_project/pkg "$DIST_DIR/wasm_project/pkg" if [ -d test/images ]; then - mkdir -p $DIST_DIR/test/images - cp -r test/images/* $DIST_DIR/test/images/ + mkdir -p "$DIST_DIR/test/images" + cp -r test/images/* "$DIST_DIR/test/images/" fi - touch $DIST_DIR/.nojekyll + touch "$DIST_DIR/.nojekyll" - name: Upload dist uses: actions/upload-artifact@v4 @@ -64,6 +67,8 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' needs: build runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v4 with: @@ -77,6 +82,7 @@ jobs: - name: Commit prod to gh-pages root run: | + set -euo pipefail rsync -a --delete "${DIST_DIR}/" "${GH_PAGES_DIR}/" cd "${GH_PAGES_DIR}" git config user.name "github-actions[bot]" @@ -93,6 +99,10 @@ jobs: if: github.event_name == 'pull_request' needs: build runs-on: ubuntu-latest + permissions: + contents: write + issues: write + pull-requests: write steps: - uses: actions/checkout@v4 with: @@ -106,6 +116,7 @@ jobs: - name: Commit preview to pr subdir run: | + set -euo pipefail mkdir -p "${GH_PAGES_DIR}/${PREVIEW_DIR}" rsync -a --delete "${DIST_DIR}/" "${GH_PAGES_DIR}/${PREVIEW_DIR}/" cd "${GH_PAGES_DIR}" @@ -124,23 +135,19 @@ jobs: run: echo "url=https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/${PREVIEW_DIR}/" >> $GITHUB_OUTPUT - name: Post preview URL as PR comment - if: ${{ github.event.pull_request.head.repo.fork == false }} + if: ${{ github.event.pull_request.head.repo.full_name == github.repository }} uses: actions/github-script@v7 with: script: | - const url = core.getInput('url'); + const url = `${{ toJSON(steps.preview.outputs.url) }}`; const number = context.payload.pull_request.number; - const body = `🚀 **Preview** is ready:\n\n${url}\n\n_This link auto-updates on every push to this PR._`; + const body = `🚀 **Preview is ready**\n\n${url}\n\n_This link auto-updates on every push to this PR._`; await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: number, body }); - result-encoding: string - github-token: ${{ secrets.GITHUB_TOKEN }} - env: - url: ${{ steps.preview.outputs.url }} - name: Write preview URL to job summary run: | @@ -150,6 +157,8 @@ jobs: cleanup-preview: if: github.event_name == 'pull_request_target' && github.event.action == 'closed' runs-on: ubuntu-latest + permissions: + contents: write steps: - uses: actions/checkout@v4 with: @@ -160,6 +169,7 @@ jobs: env: PREVIEW_DIR: pr-preview-${{ github.event.pull_request.number }} run: | + set -euo pipefail cd "${GH_PAGES_DIR}" if [ -d "${PREVIEW_DIR}" ]; then git config user.name "github-actions[bot]"