Generate and publish sandboxes #13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | |
| env: | |
| YARN_ENABLE_IMMUTABLE_INSTALLS: 'false' | |
| CLEANUP_SANDBOX_NODE_MODULES: 'true' | |
| NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} | |
| defaults: | |
| run: | |
| working-directory: ./code | |
| jobs: | |
| set-branches: | |
| name: Resolve target branches | |
| if: github.repository_owner == 'storybookjs' | |
| runs-on: ubuntu-latest | |
| outputs: | |
| branches: ${{ steps.set.outputs.branches }} | |
| steps: | |
| - id: set | |
| working-directory: ${{ github.workspace }} | |
| env: | |
| 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 | |
| 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 }} | |
| 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: ${{ matrix.branch }} | |
| - 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 | |
| # 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=${{ github.event_name == 'workflow_dispatch' && 'next' || matrix.branch }} | |
| - 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 **${{ matrix.branch }}** branch has failed. | |
| [See the job summary for details](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |