Skip to content

Storybook publish for add-no-injection-qas #3432

Storybook publish for add-no-injection-qas

Storybook publish for add-no-injection-qas #3432

name: Storybook Preview Publish
run-name: Storybook publish for ${{ github.event.workflow_run.head_branch }}
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 run metadata"
uses: actions/download-artifact@v4
with:
name: metadata
path: ./METADATA
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}
- name: Get branch for Chromatic
uses: actions/github-script@v7
id: run_metadata
with:
script: |
const fs = require("fs");
const branchName = fs.readFileSync("./METADATA/branch-name", "utf8").trim();
core.setOutput("branchName", branchName);
- 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: "Delete stats.json if it exists"
run: rm -f ./storybook-static/preview-stats.json
- 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: ${{ steps.run_metadata.outputs.branchName }}
- name: Update deploy status (success)
uses: actions/github-script@v7
if: success()
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()
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 }}"
});