-
Notifications
You must be signed in to change notification settings - Fork 1
109 lines (97 loc) · 3.79 KB
/
storybook.yml
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
101
102
103
104
105
106
107
108
109
name: Storybook
on:
pull_request:
branches:
- main
- 'feature/**'
paths:
- "apps/admin-panel/**"
push:
branches: [main]
paths:
- "apps/admin-panel/**"
jobs:
storybook-preview:
name: Storybook Preview
runs-on: ubuntu-latest
steps:
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@v4
- name: Run the Magic Nix Cache
uses: DeterminateSystems/magic-nix-cache-action@v8
- name: Checkout code
uses: actions/checkout@v4
- name: Build Storybook
run: nix develop -c make build-storybook-admin-panel
- name: Install Netlify CLI
run: npm install -g netlify-cli
- name: Deploy to Netlify (Pull Request)
id: netlify_deploy
if: github.event_name == 'pull_request'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 8f3d8282-da53-4b6d-8d3c-708c7d7030c9
run: |
GITHUB_SHA="${{ github.sha }}"
SHORT_SHA="${GITHUB_SHA::7}"
ALIAS="pr-${{ github.event.pull_request.number }}-commit-${SHORT_SHA}"
netlify deploy \
--dir=apps/admin-panel/storybook-static \
--site=$NETLIFY_SITE_ID \
--auth=$NETLIFY_AUTH_TOKEN \
--alias="$ALIAS" \
--message="Storybook Preview for PR #${{ github.event.pull_request.number }} Commit $GITHUB_SHA" \
--json > deploy-info.json
DEPLOY_URL=$(jq -r '.deploy_url' deploy-info.json)
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
- name: Deploy to Netlify (Push to Main)
if: github.event_name == 'push'
env:
NETLIFY_AUTH_TOKEN: ${{ secrets.NETLIFY_AUTH_TOKEN }}
NETLIFY_SITE_ID: 8f3d8282-da53-4b6d-8d3c-708c7d7030c9
run: |
netlify deploy \
--prod \
--dir=apps/admin-panel/storybook-static \
--site=$NETLIFY_SITE_ID \
--auth=$NETLIFY_AUTH_TOKEN \
--message="Storybook Build for Commit ${{ github.sha }}" \
--json > deploy-info.json
DEPLOY_URL=$(jq -r '.deploy_url' deploy-info.json)
echo "deploy_url=$DEPLOY_URL" >> $GITHUB_OUTPUT
- name: Create or Update Preview Comment
if: github.event_name == 'pull_request'
uses: actions/github-script@v6
with:
script: |
const prNumber = context.payload.pull_request.number;
const deployUrl = '${{ steps.netlify_deploy.outputs.deploy_url }}';
const commentBody = `<!-- Storybook Preview Comment -->\nStorybook preview: [Link to Storybook](${deployUrl})`;
// Fetch existing comments on the PR
const { data: comments } = await github.rest.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
});
// Identify if the bot has already made a comment
const botLogin = 'github-actions[bot]'
const existingComment = comments.find(
comment => comment.user.login === botLogin && comment.body.includes('<!-- Storybook Preview Comment -->')
);
if (existingComment) {
// Update the existing comment
await github.rest.issues.updateComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: existingComment.id,
body: commentBody,
});
} else {
// Create a new comment
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: prNumber,
body: commentBody,
});
}