-
Notifications
You must be signed in to change notification settings - Fork 17
[FF-50] Picasso Storybook docs deployment #4814
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
vedrani
wants to merge
8
commits into
master
Choose a base branch
from
PF-deploy-picasso-docs
base: master
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.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4740fd4
Initial version
vedrani 57d0389
Initial version
vedrani dd82885
Initial version
vedrani f585d6f
Initial version
vedrani a2b7e23
Initial version
vedrani 188f88e
Initial version
vedrani 5d7d63d
Initial version
vedrani 92ca545
Initial version
vedrani 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
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,175 @@ | ||
| name: Cleanup PR Previews | ||
|
|
||
| on: | ||
| # Immediate cleanup when PR closes | ||
| pull_request: | ||
| types: [closed] | ||
| branches: | ||
| - master | ||
| - 'feature/**' | ||
|
|
||
| # Scheduled garbage collection (runs weekly on Sundays at 2 AM UTC) | ||
| schedule: | ||
| - cron: '0 2 * * 0' | ||
|
|
||
| # Manual trigger for emergency cleanup | ||
| workflow_dispatch: | ||
| inputs: | ||
| cleanup_mode: | ||
| description: 'Cleanup mode' | ||
| required: true | ||
| default: 'single' | ||
| type: choice | ||
| options: | ||
| - single | ||
| - all_closed | ||
| - force_all | ||
|
|
||
| concurrency: | ||
| group: gh-pages-deployment | ||
| cancel-in-progress: false | ||
|
|
||
| jobs: | ||
| cleanup-single-pr: | ||
| if: ${{ github.event_name == 'pull_request' }} | ||
| name: Cleanup Single PR Preview | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| pages: write | ||
| id-token: write | ||
| steps: | ||
| - name: Checkout gh-pages branch | ||
| id: checkout-gh-pages | ||
| uses: actions/checkout@v4 | ||
| continue-on-error: true | ||
| with: | ||
| ref: gh-pages | ||
| path: gh-pages-content | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Remove PR preview directory | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| run: | | ||
| PR_DIR="gh-pages-content/prs/${{ github.event.pull_request.number }}" | ||
| if [ -d "$PR_DIR" ]; then | ||
| echo "🗑️ Removing preview directory: $PR_DIR" | ||
| rm -rf "$PR_DIR" | ||
| echo "✅ Cleanup successful" | ||
| else | ||
| echo "ℹ️ Preview directory $PR_DIR does not exist" | ||
| fi | ||
|
|
||
| - name: Deploy cleanup to GitHub Pages | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| uses: actions/upload-pages-artifact@v3 | ||
| with: | ||
| path: gh-pages-content | ||
|
|
||
| - name: Deploy to GitHub Pages | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| uses: actions/deploy-pages@v4 | ||
|
|
||
| - name: Comment cleanup notification | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| body: '🗑️ **Storybook preview cleaned up**\n\nThe preview deployment has been automatically removed since this PR was closed.' | ||
| }); | ||
|
|
||
| garbage-collection: | ||
| if: ${{ github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' }} | ||
| name: Garbage Collection | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: write | ||
| pages: write | ||
| id-token: write | ||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Checkout gh-pages branch | ||
| id: checkout-gh-pages | ||
| uses: actions/checkout@v4 | ||
| continue-on-error: true | ||
| with: | ||
| ref: gh-pages | ||
| path: gh-pages-content | ||
| token: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Garbage collect orphaned previews | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const fs = require('fs'); | ||
| const path = require('path'); | ||
|
|
||
| // Get all open PRs | ||
| const { data: openPRs } = await github.rest.pulls.list({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| state: 'open' | ||
| }); | ||
|
|
||
| const openPRNumbers = new Set(openPRs.map(pr => pr.number.toString())); | ||
| console.log(`📊 Found ${openPRNumbers.size} open PRs:`, Array.from(openPRNumbers).join(', ')); | ||
|
|
||
| // Check prs directory | ||
| const prsDir = 'gh-pages-content/prs'; | ||
| if (!fs.existsSync(prsDir)) { | ||
| console.log('ℹ️ No prs directory found'); | ||
| return; | ||
| } | ||
|
|
||
| const existingPreviews = fs.readdirSync(prsDir); | ||
| console.log(`📁 Found ${existingPreviews.length} preview directories:`, existingPreviews.join(', ')); | ||
|
|
||
| let cleanedCount = 0; | ||
| for (const prDir of existingPreviews) { | ||
| const prNumber = prDir; | ||
|
|
||
| // Skip if PR is still open (unless force mode) | ||
| if (openPRNumbers.has(prNumber) && '${{ github.event.inputs.cleanup_mode }}' !== 'force_all') { | ||
| console.log(`⏭️ Skipping ${prNumber} (PR still open)`); | ||
| continue; | ||
| } | ||
|
|
||
| // Remove closed PR preview | ||
| const fullPath = path.join(prsDir, prDir); | ||
| try { | ||
| fs.rmSync(fullPath, { recursive: true, force: true }); | ||
| console.log(`🗑️ Cleaned up preview: ${prNumber}`); | ||
| cleanedCount++; | ||
| } catch (error) { | ||
| console.error(`❌ Failed to clean ${prNumber}:`, error.message); | ||
| } | ||
| } | ||
|
|
||
| console.log(`✅ Garbage collection complete: ${cleanedCount} previews cleaned`); | ||
|
|
||
| // Set output for summary | ||
| core.setOutput('cleaned_count', cleanedCount); | ||
| core.setOutput('total_found', existingPreviews.length); | ||
|
|
||
| - name: Deploy cleanup to GitHub Pages | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| uses: actions/upload-pages-artifact@v3 | ||
| with: | ||
| path: gh-pages-content | ||
|
|
||
| - name: Deploy to GitHub Pages | ||
| if: steps.checkout-gh-pages.outcome == 'success' | ||
| uses: actions/deploy-pages@v4 | ||
|
|
||
| - name: Summary | ||
| run: | | ||
| echo "🧹 **Garbage Collection Summary**" >> $GITHUB_STEP_SUMMARY | ||
| echo "- Trigger: ${{ github.event_name }}" >> $GITHUB_STEP_SUMMARY | ||
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
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.