-
Notifications
You must be signed in to change notification settings - Fork 671
Storybook Deployment: Add automatic workflows #33570
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
r-farkhutdinov
wants to merge
5
commits into
DevExpress:26_1
Choose a base branch
from
r-farkhutdinov:26_1_sb_deploy_auto
base: 26_1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+215
−0
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
823eb7e
Storybook Deployment: Add automatic workflows
8845b76
Storybook Deployment: Fix deploy job permissions & order issues
762e478
Update environment name
r-farkhutdinov 657bcbe
Storybook Deployment: Create meta file after checkout
dc2c8b3
Storybook Deployment: Add wait-for-pages-deployment flag & add enviro…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| 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 | ||
|
|
||
| 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 | ||
|
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 | ||
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
| 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: | ||
|
r-farkhutdinov marked this conversation as resolved.
|
||
| contents: write | ||
| actions: read | ||
|
|
||
|
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 | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.