From 276290df8eb5355e24b6e28284218645673cce5b Mon Sep 17 00:00:00 2001 From: Arthurk12 Date: Thu, 15 Oct 2026 13:46:04 -0300 Subject: [PATCH] ci(storybook): deploy develop to a /develop subpath alongside main Only main is published to GitHub Pages, so changes merged into develop can't be browsed or reviewed in Storybook until they are released. Trigger the deploy on pushes to develop as well, publishing it into a develop/ subdirectory of gh-pages while main stays at the root: - Before the main deploy, copy the current develop/ from gh-pages into the build output. The main deploy uses keep_files: false, which cleans the whole branch root, so without this copy it would remove develop/. If gh-pages doesn't exist yet (new repository or fork), skip the copy and let the deploy create the branch. - Run the job in a shared concurrency group with queue: max, so main and develop runs, which both push to gh-pages, wait in line instead of rejecting each other's push. With the default single pending slot, a newer pending run would cancel an older one. - Skip the job when it is dispatched manually from any branch other than main or develop, so a feature branch can never overwrite the published root. Deploying develop to a separate branch was considered and discarded: GitHub Pages serves a single site per repository, so another branch would not be published. --- .github/workflows/storybook-deploy.yml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/.github/workflows/storybook-deploy.yml b/.github/workflows/storybook-deploy.yml index 9d9af42..c41fdbe 100644 --- a/.github/workflows/storybook-deploy.yml +++ b/.github/workflows/storybook-deploy.yml @@ -4,6 +4,7 @@ on: push: branches: - main + - develop workflow_dispatch: {} permissions: @@ -13,6 +14,13 @@ permissions: jobs: build-and-deploy: + if: ${{ github.ref_name == 'main' || github.ref_name == 'develop' }} + # Both branches push to gh-pages; overlapping runs would reject each other's + # push, and the default single pending slot would drop a queued deploy. + concurrency: + group: gh-pages-deploy + cancel-in-progress: false + queue: max runs-on: ubuntu-latest steps: @@ -44,10 +52,20 @@ jobs: echo "storybook-static does not exist at ./storybook-static" fi + # The main deploy cleans the whole gh-pages root, develop/ included. + - name: Preserve the develop Storybook + if: ${{ github.ref_name == 'main' }} + run: | + git fetch --depth=1 origin gh-pages || exit 0 + if git ls-tree -d --name-only FETCH_HEAD develop | grep -q .; then + git archive FETCH_HEAD develop | tar -x -C ./storybook-static + fi + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v4 with: publish_dir: ./storybook-static + destination_dir: ${{ github.ref_name == 'develop' && 'develop' || '' }} github_token: ${{ secrets.GITHUB_TOKEN }} publish_branch: gh-pages keep_files: false