Storybook Preview Publish #1235
This file contains 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: Storybook Preview Publish | |
on: | |
workflow_run: | |
workflows: ["Build Storybook"] | |
types: | |
- completed | |
jobs: | |
deploy: | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read | |
deployments: write | |
pull-requests: write | |
statuses: write | |
name: Deploy Storybook to Cloudflare Pages | |
steps: | |
- name: Set initial commit status | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
await github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: "${{ github.event.workflow_run.head_commit.id }}", | |
state: "pending", | |
description: "Pending", | |
context: "Storybook" | |
}) | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Use Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20" | |
cache: "yarn" | |
- name: Install dependencies | |
run: yarn | |
- name: "Download build artifact" | |
uses: actions/download-artifact@v4 | |
with: | |
name: storybook-build | |
path: ./storybook-static | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
run-id: ${{ github.event.workflow_run.id }} | |
- name: Publish | |
uses: cloudflare/pages-action@v1 | |
id: publish | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_SALT_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_SALT_ACCOUNT_ID }} | |
projectName: "saltdesignsystem-storybook" | |
directory: ./storybook-static | |
gitHubToken: ${{ secrets.GITHUB_TOKEN }} | |
branch: ${{ github.head_ref || github.ref_name }} | |
- name: Update deploy status (success) | |
uses: actions/github-script@v7 | |
if: success() && github.event.workflow_run.event == 'pull_request' | |
with: | |
script: | | |
await github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: "${{ github.event.workflow_run.head_commit.id }}", | |
state: "success", | |
description: "Successfully deployed", | |
context: "Storybook", | |
target_url: "${{ steps.publish.outputs.url }}" | |
}); | |
- name: Update deploy status (failure) | |
uses: actions/github-script@v7 | |
if: failure() && github.event.workflow_run.event == 'pull_request' | |
with: | |
script: | | |
await github.rest.repos.createCommitStatus({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
sha: "${{ github.event.workflow_run.head_commit.id }}", | |
state: "error", | |
description: "Failed to deploy", | |
context: "Storybook", | |
target_url: "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" | |
}); |