-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (151 loc) · 5.45 KB
/
deploy.yml
File metadata and controls
176 lines (151 loc) · 5.45 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
name: Deploy to GitHub Pages
on:
workflow_run:
workflows: ['Release']
types:
- completed
branches:
- master
workflow_dispatch:
permissions:
contents: read
pages: write
id-token: write
pull-requests: read
concurrency:
group: 'pages'
cancel-in-progress: false
jobs:
# This job finds the SHA of the last successful deployment
find_last_deployment:
runs-on: ubuntu-latest
outputs:
last_sha: ${{ steps.get_sha.outputs.sha }}
steps:
- name: Get last deployment SHA
id: get_sha
run: |
# Install GitHub CLI if not available
if ! command -v gh &> /dev/null; then
echo "Installing GitHub CLI..."
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh
fi
# Authenticate with GitHub token
echo "${{ github.token }}" | gh auth login --with-token
# Get the last successful deployment workflow run
WORKFLOW_ID=$(gh api /repos/${{ github.repository }}/actions/workflows/deploy.yml | jq -r '.id')
# Find the last successful run of the deploy workflow
LAST_SHA=$(gh api "/repos/${{ github.repository }}/actions/workflows/$WORKFLOW_ID/runs?status=success&per_page=1" | jq -r '.workflow_runs[0].head_sha')
# If no previous successful run, use a fallback
if [ "$LAST_SHA" = "null" ] || [ -z "$LAST_SHA" ]; then
echo "No previous successful deployment found. Using current SHA as reference."
LAST_SHA="${{ github.sha }}"
fi
echo "Last successful deployment SHA: $LAST_SHA"
echo "sha=$LAST_SHA" >> $GITHUB_OUTPUT
check_changes:
runs-on: ubuntu-latest
needs: find_last_deployment
outputs:
should_build: ${{ steps.filter.outputs.should_build }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
# For workflow_dispatch events, we always want to build
- name: Set manual trigger output
if: github.event_name == 'workflow_dispatch'
run: |
echo "SHOULD_BUILD=true" >> $GITHUB_ENV
# Only run the filter if not manually triggered
- name: Filter changes
if: github.event_name != 'workflow_dispatch'
uses: dorny/paths-filter@v3
id: filter
with:
# Compare against the last successful deployment SHA
base: ${{ needs.find_last_deployment.outputs.last_sha }}
# Look for changes in these patterns
filters: |
should_build:
- '.stories.tsx'
- 'landing/**'
- '.storybook/**'
- 'package.json'
- 'landing/package.json'
# Set the output for use by the build job
- name: Set final output
id: set_output
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
echo "should_build=true" >> $GITHUB_OUTPUT
else
echo "should_build=${{ steps.filter.outputs.should_build || 'false' }}" >> $GITHUB_OUTPUT
fi
build:
runs-on: ubuntu-latest
needs: check_changes
if: needs.check_changes.outputs.should_build == 'true'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Restore Bun cache
uses: actions/cache@v4
id: bun-cache
with:
path: ~/.bun/install/cache
key: ${{ runner.os }}-bun-${{ hashFiles('**/bun.lockb') }}
restore-keys: |
${{ runner.os }}-bun-
# Build the component library and Storybook
- name: Install root dependencies
run: bun install
- name: Build component library
run: bun run build
- name: Build Storybook
run: bun run build-storybook
env:
NODE_OPTIONS: '--max_old_space_size=4096'
# Build the landing page (Vike site)
- name: Install landing page dependencies
working-directory: ./landing
run: bun install
- name: Build Vike site
working-directory: ./landing
run: bun run build
# Prepare the deployment directory
- name: Prepare deployment directory
run: |
mkdir -p ./deploy
# Move Vike site to root of deployment directory
cp -r ./landing/dist/client/* ./deploy/
# Ensure Storybook directory exists
mkdir -p ./deploy/storybook
# Move Storybook to /storybook subfolder
cp -r ./storybook-static/* ./deploy/storybook/
# Create CNAME file for the custom domain
echo "ui.bizar.re" > ./deploy/CNAME
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: ./deploy
deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4