-
Notifications
You must be signed in to change notification settings - Fork 6
91 lines (76 loc) · 3.15 KB
/
pr-preview.yml
File metadata and controls
91 lines (76 loc) · 3.15 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
name: PR Preview
on:
pull_request:
types: [opened, synchronize, reopened]
jobs:
preview:
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout PR Branch
uses: actions/checkout@v4
- name: Checkout main branch
uses: actions/checkout@v4
with:
ref: main
path: main-branch
- uses: pnpm/action-setup@v4
with:
run_install: true
- name: Find new theme
id: get-theme
run: |
# Extract themes from both branches
PR_THEMES=$(pnpm tsx -e "import { preset } from './src/theme'; console.log(Object.keys(preset).join(','))")
MAIN_THEMES=$(pnpm tsx -e "import { preset } from './main-branch/src/theme'; console.log(Object.keys(preset).join(','))")
# Convert to arrays
IFS=',' read -ra PR_ARRAY <<< "$PR_THEMES"
IFS=',' read -ra MAIN_ARRAY <<< "$MAIN_THEMES"
# Find new themes
NEW_THEMES=()
for theme in "${PR_ARRAY[@]}"; do
if [[ ! " ${MAIN_ARRAY[@]} " =~ " ${theme} " ]]; then
NEW_THEMES+=("$theme")
fi
done
if [ ${#NEW_THEMES[@]} -eq 0 ]; then
THEME="light"
echo "No new theme found, using default: $THEME"
else
THEME="${NEW_THEMES[0]}"
echo "New theme found: $THEME"
fi
echo "theme=$THEME" >> $GITHUB_OUTPUT
# Store all new themes for the comment
if [ ${#NEW_THEMES[@]} -gt 0 ]; then
echo "new_themes=${NEW_THEMES[*]}" >> $GITHUB_OUTPUT
fi
- name: Generate preview grid
run: |
pnpm generate --grid --theme ${{ steps.get-theme.outputs.theme }} -o preview.png || {
echo "::error::Failed to generate preview cards"
exit 1
}
- name: Upload preview artifact
uses: actions/upload-artifact@v4
with:
name: preview-image
path: preview.png
retention-days: 1
- name: Save PR info
run: |
echo "${{ github.event.pull_request.number }}" > pr_number.txt
echo "${{ github.event.pull_request.head.sha }}" > commit_sha.txt
echo "${{ steps.get-theme.outputs.new_themes }}" > new_themes.txt
echo "${{ steps.get-theme.outputs.theme }}" > theme.txt
- name: Upload PR info artifact
uses: actions/upload-artifact@v4
with:
name: pr-info
path: |
pr_number.txt
commit_sha.txt
new_themes.txt
theme.txt
retention-days: 1