From 95f772df2bd579a90f4935623396855754b933c9 Mon Sep 17 00:00:00 2001 From: Timo <16718859+toger5@users.noreply.github.com> Date: Tue, 5 May 2026 21:46:11 +0800 Subject: [PATCH] Add storybook to CI (#3948) * add storybook to CI only add storybook with storybook label test names another env name test TestName new default name remove label condition Update pr-deploy.yaml * rename things to check if we actually run the latests ci * cleanup things used for testing * Update deploy-to-netlify.yaml * use package instead of custom environment_name * final cleanup --- .github/workflows/build.yaml | 28 ++++++++++++++++++++++++ .github/workflows/deploy-to-netlify.yaml | 10 ++++++--- .github/workflows/pr-deploy.yaml | 20 ++++++++++++++++- 3 files changed, 54 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 32ce25c9..ba7cde51 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -85,3 +85,31 @@ jobs: SENTRY_URL: ${{ secrets.SENTRY_URL }} SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }} CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + + build_storybook: + name: Build Storybook + if: contains(github.event.pull_request.labels.*.name, 'storybook build') + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4 + with: + persist-credentials: false + - name: Enable Corepack + run: corepack enable + - name: pnpm cache + uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4 + with: + cache: "pnpm" + node-version-file: ".node-version" + - name: Install dependencies + run: "pnpm install --frozen-lockfile --ignore-pnpmfile" + - name: Build Storybook + run: pnpm run build-storybook + - name: Upload Artifact + uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4 + with: + name: build-output-storybook + path: storybook-static + # We'll only use this in a triggered job, then we're done with it + retention-days: 1 diff --git a/.github/workflows/deploy-to-netlify.yaml b/.github/workflows/deploy-to-netlify.yaml index 76609328..554e384b 100644 --- a/.github/workflows/deploy-to-netlify.yaml +++ b/.github/workflows/deploy-to-netlify.yaml @@ -17,7 +17,7 @@ on: package: required: true type: string - description: Which package to deploy - 'full', 'embedded', or 'sdk' + description: Which package to deploy - 'full', 'embedded', 'sdk', or 'storybook' artifact_run_id: required: false type: string @@ -43,7 +43,7 @@ jobs: with: step: start token: ${{ secrets.GITHUB_TOKEN }} - env: Netlify + env: ${{ inputs.package}} ref: ${{ inputs.deployment_ref }} desc: | Do you trust the author of this PR? Maybe this build will steal your keys or give you malware. @@ -59,9 +59,13 @@ jobs: - name: Add redirects file # We fetch from github directly as we don't bother checking out the repo + # Not needed for storybook deployments + if: inputs.package != 'storybook' run: curl -s https://raw.githubusercontent.com/element-hq/element-call/main/config/netlify_redirects > webapp/_redirects - name: Add config file + # Not needed for storybook deployments + if: inputs.package != 'storybook' run: | if [ "${INPUTS_PACKAGE}" = "full" ]; then curl -s "https://raw.githubusercontent.com/${INPUTS_PR_HEAD_FULL_NAME}/${INPUTS_PR_HEAD_REF}/config/config_netlify_preview.json" > webapp/config.json @@ -78,7 +82,7 @@ jobs: with: publish-dir: webapp deploy-message: "Deploy from GitHub Actions" - alias: ${{ inputs.package == 'sdk' && format('pr{0}-sdk', inputs.pr_number) || format('pr{0}', inputs.pr_number) }} + alias: ${{ inputs.package == 'sdk' && format('pr{0}-sdk', inputs.pr_number) || inputs.package == 'storybook' && format('pr{0}-storybook', inputs.pr_number) || format('pr{0}', inputs.pr_number) }} env: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} diff --git a/.github/workflows/pr-deploy.yaml b/.github/workflows/pr-deploy.yaml index 0084b76b..3d88b083 100644 --- a/.github/workflows/pr-deploy.yaml +++ b/.github/workflows/pr-deploy.yaml @@ -14,7 +14,7 @@ jobs: # 2. Event must be a pull_request # 3. Head repository must be the SAME as the base repository (No Forks!) if: > - github.event.workflow_run.conclusion == 'success' && + github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.head_repository.full_name == github.repository runs-on: ubuntu-latest @@ -63,6 +63,24 @@ jobs: NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + netlify-storybook: + needs: prdetails + if: ${{ needs.prdetails.outputs.pr_data_json && contains(fromJSON(needs.prdetails.outputs.pr_data_json).labels.*.name, 'storybook build') }} + permissions: + deployments: write + uses: ./.github/workflows/deploy-to-netlify.yaml + with: + artifact_run_id: ${{ github.event.workflow_run.id || github.run_id }} + pr_number: ${{ needs.prdetails.outputs.pr_number }} + pr_head_full_name: ${{ github.event.workflow_run.head_repository.full_name }} + pr_head_ref: ${{ needs.prdetails.outputs.pr_data_json && fromJSON(needs.prdetails.outputs.pr_data_json).head.ref }} + deployment_ref: ${{ needs.prdetails.outputs.pr_data_json && fromJSON(needs.prdetails.outputs.pr_data_json).head.sha || github.ref || github.head_ref }} + package: storybook + secrets: + ELEMENT_BOT_TOKEN: ${{ secrets.ELEMENT_BOT_TOKEN }} + NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }} + NETLIFY_SITE_ID: ${{ secrets.NETLIFY_SITE_ID }} + docker: if: ${{ needs.prdetails.outputs.pr_data_json && contains(fromJSON(needs.prdetails.outputs.pr_data_json).labels.*.name, 'docker build') }} needs: prdetails