Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 32 additions & 78 deletions .github/workflows/generate-sandboxes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,11 @@ name: Generate and publish sandboxes
on:
schedule:
- cron: '2 2 */1 * *'
# When triggered manually, GitHub's workflow_dispatch UI provides a native
# branch selector ("Use workflow from") that lists every branch on the
# remote. The selected branch is exposed as `github.ref_name` and is used
# below to decide which branch to generate sandboxes for.
workflow_dispatch:
# To test fixes on push rather than wait for the scheduling, do the following:
# 1. Uncomment the lines below and add your branch.
# push:
# branches:
# - <your-branch-name>
# 2. Change the "ref" value to <your-branch-name> in the actions/checkout step below.
# 3. Comment out the whole "generate-main" job starting at line 77
# 4. 👉 DON'T FORGET TO UNDO THE STEPS BEFORE YOU MERGE YOUR CHANGES!

env:
YARN_ENABLE_IMMUTABLE_INSTALLS: 'false'
Expand All @@ -22,81 +18,37 @@ defaults:
run:
working-directory: ./code


jobs:
generate-next:
name: Generate to next
set-branches:
name: Resolve target branches
if: github.repository_owner == 'storybookjs'
runs-on: ubuntu-latest
outputs:
branches: ${{ steps.set.outputs.branches }}
steps:
- name: Remove unnecessary files to release disk space
- id: set
working-directory: ${{ github.workspace }}
run: |
sudo rm -rf \
/opt/ghc \
/opt/google/chrome \
/opt/microsoft/msedge \
/opt/microsoft/powershell \
/usr/lib/mono \
/usr/local/julia* \
/usr/local/lib/android \
/usr/local/share/chromium \
/usr/local/share/powershell \
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift

- uses: actions/checkout@v4
with:
ref: next

- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'

- name: Setup git user
run: |
git config --global user.name "storybook-bot"
git config --global user.email "32066757+storybook-bot@users.noreply.github.com"

- name: Install dependencies
working-directory: ./scripts
run: node --experimental-modules ./check-dependencies.js

- name: Compile Storybook libraries
run: yarn task --task compile --start-from=auto --no-link

- name: Publish to local registry
run: yarn local-registry --publish

- name: Run local registry
run: yarn local-registry --open &

- name: Wait for registry
run: yarn wait-on tcp:127.0.0.1:6001

- name: Generate
id: generate
run: yarn generate-sandboxes --local-registry

- name: Publish
# publish sandboxes even if the generation fails, as some sandboxes might have been generated successfully
if: ${{ !cancelled() }}
run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT }}@github.com/storybookjs/sandboxes.git --push --branch=next

- name: Report failure to Discord
if: failure()
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_MONITORING_URL }}
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554
with:
args: |
The generation of some or all sandboxes on the **next** branch has failed.
[See the job summary for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})

generate-main:
name: Generate to main
EVENT_NAME: ${{ github.event_name }}
REF_NAME: ${{ github.ref_name }}
run: |
if [ "$EVENT_NAME" = "workflow_dispatch" ]; then
branches=$(jq -nc --arg ref "$REF_NAME" '[$ref]')
else
branches='["next","main"]'
fi
Comment thread
coderabbitai[bot] marked this conversation as resolved.
echo "branches=$branches" >> "$GITHUB_OUTPUT"

generate:
name: Generate to ${{ matrix.branch }}
needs: set-branches
if: github.repository_owner == 'storybookjs'
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
branch: ${{ fromJson(needs.set-branches.outputs.branches) }}
steps:
- name: Remove unnecessary files to release disk space
working-directory: ${{ github.workspace }}
Expand All @@ -114,9 +66,10 @@ jobs:
/usr/local/share/powershell \
/usr/share/dotnet \
/usr/share/swift

- uses: actions/checkout@v4
with:
ref: main
ref: ${{ matrix.branch }}

- uses: actions/setup-node@v4
with:
Expand Down Expand Up @@ -149,8 +102,9 @@ jobs:

- name: Publish
# publish sandboxes even if the generation fails, as some sandboxes might have been generated successfully
# when triggered manually, always publish to the `next` branch on the sandboxes repo
if: ${{ !cancelled() }}
run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT }}@github.com/storybookjs/sandboxes.git --push --branch=main
run: yarn publish-sandboxes --remote=https://storybook-bot:${{ secrets.PAT_STORYBOOK_BOT }}@github.com/storybookjs/sandboxes.git --push --branch=${{ github.event_name == 'workflow_dispatch' && 'next' || matrix.branch }}

- name: Report failure to Discord
if: failure()
Expand All @@ -159,5 +113,5 @@ jobs:
uses: Ilshidur/action-discord@d2594079a10f1d6739ee50a2471f0ca57418b554
with:
args: |
The generation of some or all sandboxes on the **main** branch has failed.
The generation of some or all sandboxes on the **${{ matrix.branch }}** branch has failed.
[See the job summary for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})
Loading