-
Notifications
You must be signed in to change notification settings - Fork 1
100 lines (85 loc) · 3.24 KB
/
preview.yml
File metadata and controls
100 lines (85 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# .github/workflows/preview.yml
name: Deploy PR previews
on:
pull_request:
types:
- opened
- reopened
- synchronize
- closed
concurrency: preview-${{ github.event.number }}
permissions:
contents: write
pull-requests: write
jobs:
deploy-preview:
if: ${{ github.event.action != 'closed' && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
fetch-depth: 0
- name: Derive appropriate SHAs for base and head for `nx affected` commands
uses: nrwl/nx-set-shas@afb73a62d26e41464e9254689e1fd6122ee683c1 # v5.0.1
- name: Set Node Version
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
with:
node-version: 24
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: |
echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- name: Restore yarn cache
uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-24-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-24-yarn-
- name: Install Dependencies
run: yarn install --immutable
- name: Build Packages
run: yarn build
- name: Build Docs
run: yarn build:storybook:ci
- name: Deploy PR Preview
uses: peaceiris/actions-gh-pages@4f9cc6602d3f66b9c108549d475ec49e8ef4d45e # v4.0.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: dist/storybook
destination_dir: pr-preview/pr-${{ github.event.number }}
keep_files: true
enable_jekyll: false
- name: Comment PR
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: '🚀 **Preview deployed!**\n\n📖 [View Storybook Preview](https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }}/pr-preview/pr-${{ github.event.number }}/)' })
cleanup-preview:
if: ${{ github.event.action == 'closed' && github.actor != 'dependabot[bot]' }}
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout gh-pages
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: gh-pages
- name: Remove PR preview
run: |
if [ -d "pr-preview/pr-${{ github.event.number }}" ]; then
rm -rf pr-preview/pr-${{ github.event.number }}
git config user.email ${{ secrets.GH_EMAIL }}
git config user.name ${{ secrets.GH_USER }}
git add .
git commit -m "Remove preview for PR #${{ github.event.number }}"
git push
else
echo "Preview directory not found, nothing to clean up"
fi