Skip to content
Open
Show file tree
Hide file tree
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
131 changes: 131 additions & 0 deletions .github/workflows/pr-storybook-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
name: PR Storybook - Build

on:
pull_request:
branches:
- 26_1
types:
- opened
- reopened
- synchronize
- labeled
- unlabeled
- closed

permissions:
contents: read
Comment thread
r-farkhutdinov marked this conversation as resolved.

concurrency:
group: preview-build-${{ github.event.pull_request.number }}
cancel-in-progress: true

env:
SOURCE_DIR: ./apps/react-storybook/storybook-static

jobs:
build:
name: Build preview artifacts
runs-on: ubuntu-latest
timeout-minutes: 20
environment: github-pages

steps:
- name: Decide action (deploy/remove/none)
id: meta
shell: bash
run: |
set -euo pipefail

PR_NUMBER="${{ github.event.pull_request.number }}"
EVENT_ACTION="${{ github.event.action }}"
CHANGED_LABEL="${{ github.event.label.name || '' }}"
HAS_LABEL="${{ contains(github.event.pull_request.labels.*.name, 'storybook') }}"

ACTION="none"

# Cleanup cases
if [[ "$EVENT_ACTION" == "closed" ]]; then
ACTION="remove"
elif [[ "$EVENT_ACTION" == "unlabeled" && "$CHANGED_LABEL" == "storybook" ]]; then
ACTION="remove"
# Deploy cases
elif [[ "$EVENT_ACTION" == "labeled" && "$CHANGED_LABEL" == "storybook" ]]; then
ACTION="deploy"
elif [[ "$EVENT_ACTION" == "opened" || "$EVENT_ACTION" == "reopened" || "$EVENT_ACTION" == "synchronize" ]]; then
if [[ "$HAS_LABEL" == "true" ]]; then
ACTION="deploy"
fi
fi

echo "action=$ACTION" >> "$GITHUB_OUTPUT"
echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"

- name: Checkout repository
if: steps.meta.outputs.action == 'deploy'
uses: actions/checkout@v4
with:
submodules: true
Comment thread
r-farkhutdinov marked this conversation as resolved.
fetch-depth: 1

- name: Write meta artifact
if: always()
shell: bash
run: |
mkdir -p preview_meta
printf '{ "pr_number": %s, "action": "%s" }\n' \
'${{ steps.meta.outputs.pr_number }}' \
'${{ steps.meta.outputs.action }}' > preview_meta/meta.json

- name: Use Node.js
if: steps.meta.outputs.action == 'deploy'
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Setup pnpm
if: steps.meta.outputs.action == 'deploy'
uses: pnpm/action-setup@v4
with:
run_install: false

- name: Get pnpm store directory
if: steps.meta.outputs.action == 'deploy'
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path --silent)" >> $GITHUB_ENV

- name: Setup pnpm + nx cache
if: steps.meta.outputs.action == 'deploy'
uses: actions/cache@v4
with:
path: |
${{ env.STORE_PATH }}
.nx/cache
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store

- name: Install dependencies
if: steps.meta.outputs.action == 'deploy'
run: pnpm install --frozen-lockfile

- name: Build Storybook preview (static)
if: steps.meta.outputs.action == 'deploy'
run: |
pnpm nx build devextreme-react-storybook

- name: Upload meta artifact (always)
if: always()
uses: actions/upload-artifact@v4
with:
name: preview-meta
path: preview_meta/meta.json
retention-days: 1

- name: Upload static artifact (deploy only)
if: steps.meta.outputs.action == 'deploy'
uses: actions/upload-artifact@v4
with:
name: preview-static
path: ${{ env.SOURCE_DIR }}
retention-days: 1
84 changes: 84 additions & 0 deletions .github/workflows/pr-storybook-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: PR Storybook - Deploy

on:
workflow_run:
workflows:
- PR Storybook - Build
types:
- completed

permissions:
Comment thread
r-farkhutdinov marked this conversation as resolved.
contents: write
actions: read

Comment thread
r-farkhutdinov marked this conversation as resolved.
env:
SOURCE_DIR: dist/static

jobs:
prepare:
name: Read build meta
if: github.event.workflow_run.conclusion == 'success'
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
action: ${{ steps.meta.outputs.action }}
pr_number: ${{ steps.meta.outputs.pr_number }}

steps:
- name: Download meta artifact
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
name: preview-meta
path: artifacts

- name: Read meta
id: meta
shell: bash
run: |
set -euo pipefail
META="artifacts/meta.json"
echo "Meta:"
cat "$META"

PR_NUMBER="$(jq -r '.pr_number' "$META")"
ACTION="$(jq -r '.action' "$META")"

echo "pr_number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
echo "action=$ACTION" >> "$GITHUB_OUTPUT"

deploy:
name: Deploy/remove preview
needs: prepare
if: needs.prepare.outputs.action != 'none'
runs-on: ubuntu-latest
timeout-minutes: 10
environment: github-pages

concurrency:
group: preview-deploy-${{ needs.prepare.outputs.pr_number }}
cancel-in-progress: true

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Download static artifact
if: needs.prepare.outputs.action == 'deploy'
uses: dawidd6/action-download-artifact@v6
with:
run_id: ${{ github.event.workflow_run.id }}
name: preview-static
path: ${{ env.SOURCE_DIR }}

- name: Deploy/remove PR preview
uses: rossjrw/pr-preview-action@ffa7509e91a3ec8dfc2e5536c4d5c1acdf7a6de9 # v1.8.1
with:
action: ${{ needs.prepare.outputs.action }}
pr-number: ${{ needs.prepare.outputs.pr_number }}
source-dir: ${{ env.SOURCE_DIR }}
preview-branch: gh-pages
umbrella-dir: preview
comment: false
token: ${{ github.token }}
wait-for-pages-deployment: true
Loading