CivicTechTO / polis-storybook

https://civictechto.github.io/polis-storybook/
GNU Affero General Public License v3.0
1 stars 0 forks source link

Deploy storybook for every pull request #6

Closed patcon closed 1 month ago

patcon commented 1 month ago

We can use this branch-switcher addon for storybook to allow the single storybook site to switch between code from different branches/PRs: https://github.com/utarwyn/storybook-branch-switcher

It can have each PR generate a build of storybook for its branch: https://github.com/utarwyn/storybook-branch-switcher?tab=readme-ov-file#with-github-opened-prs

Unlike traditional PR flows, it's not deployable a new app for PRs, but instead pushing to the github pages main site (usually only deployed from main branch) for every commit to both mainline and pull request branches.

To Dos

patcon commented 1 month ago

This might require some silliness and edge cases when adding new packages in a PR, because they might be missing if that packages are only pulled in from package-lock.json in mainline. To make this work, packages may need to be added to mainline for work happening on branches.

Alternatively, we could gradefully exit the storybook build for branches where diffs exist between the package-lock.json in mainline and a PR branch

patcon commented 1 month ago

Yay, working (ish)

First branch deploy is #7 at https://civictechto.github.io/polis-storybook/PR-7/

Automation runs on each push to mainline and to PRs.

patcon commented 1 month ago

Took a bit to figure this out, as it's a little messy (with submodules and checking out branches based on remote branch hashes on github), but this is now working fine!

Will likely have some funny edge-cases for git submodules when the commits update between branches, but works really well for now!

patcon commented 1 month ago

In future, might also want to consider using the pull_request_target workflow trigger instead of the default pull_request

patcon commented 1 month ago

This is done now, as far as I can tell 🎉