Skip to content

Commit b29213d

Browse files
authored
Hellovai/beps (#2753)
# Pull Request Template Thanks for taking the time to fill out this pull request! ## Issue Reference Please link to any related issues - [ ] This PR fixes/closes #[issue number] ## Changes Please describe the changes proposed in this pull request [Describe your changes here...] ## Testing Please describe how you tested these changes - [ ] Unit tests added/updated - [ ] Manual testing performed - [ ] Tested in [environment] ## Screenshots If applicable, add screenshots to help explain your changes [Add screenshots here...] ## PR Checklist Please ensure you've completed these items - [ ] I have read and followed the contributing guidelines - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ## Additional Notes Add any other context about the PR here [Add any additional notes here...]
1 parent e6251f2 commit b29213d

File tree

26 files changed

+3702
-2
lines changed

26 files changed

+3702
-2
lines changed

.github/workflows/ci.yaml

Lines changed: 174 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
name: CI - BAML Language
2-
permissions: {}
2+
permissions:
3+
contents: read
4+
id-token: write
5+
pull-requests: write
36
on:
47
push:
58
branches: [main, canary]
@@ -40,6 +43,8 @@ jobs:
4043
thir: ${{ steps.check_thir.outputs.changed }}
4144
# Flag for codegen changes
4245
codegen: ${{ steps.check_codegen.outputs.changed }}
46+
# Flag for BEP changes
47+
beps: ${{ steps.check_beps.outputs.changed }}
4348
steps:
4449
- uses: actions/checkout@v4
4550
with:
@@ -146,6 +151,156 @@ jobs:
146151
echo "changed=true" >> "$GITHUB_OUTPUT"
147152
fi
148153
154+
- name: Check if BEPs changed
155+
id: check_beps
156+
env:
157+
MERGE_BASE: ${{ steps.merge_base.outputs.sha }}
158+
run: |
159+
if git diff --quiet "${MERGE_BASE}...HEAD" -- \
160+
':beps/**' \
161+
; then
162+
echo "changed=false" >> "$GITHUB_OUTPUT"
163+
else
164+
echo "changed=true" >> "$GITHUB_OUTPUT"
165+
fi
166+
167+
check-beps:
168+
name: "check beps"
169+
runs-on: ubuntu-latest
170+
needs: determine_changes
171+
if: ${{ needs.determine_changes.outputs.beps == 'true' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/canary' }}
172+
steps:
173+
- uses: actions/checkout@v4
174+
with:
175+
persist-credentials: false
176+
177+
- name: Fetch BEP file history
178+
run: git fetch --depth=500 origin ${{ github.ref }} -- beps/
179+
180+
- name: Install uv
181+
uses: astral-sh/setup-uv@v5
182+
with:
183+
enable-cache: true
184+
cache-dependency-glob: "uv.lock"
185+
186+
- name: "Check BEP index"
187+
run: ./beps/scripts/update_bep_readme.py --check
188+
189+
deploy-beps-canary:
190+
name: "deploy beps (canary)"
191+
runs-on: ubuntu-latest
192+
needs: [determine_changes, check-beps]
193+
if: github.event_name == 'push' && github.ref == 'refs/heads/canary'
194+
steps:
195+
- uses: actions/checkout@v4
196+
with:
197+
persist-credentials: false
198+
199+
- name: Fetch BEP file history
200+
run: git fetch --depth=500 origin ${{ github.ref }} -- beps/
201+
202+
- name: Setup Python
203+
uses: actions/setup-python@v5
204+
with:
205+
python-version: 3.x
206+
207+
- name: Install MkDocs and dependencies
208+
run: |
209+
pip install mkdocs-material mkdocs-awesome-pages-plugin mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2
210+
211+
- name: Build MkDocs
212+
working-directory: beps
213+
run: mkdocs build
214+
215+
- name: Configure AWS credentials
216+
uses: aws-actions/configure-aws-credentials@v4 # v4
217+
with:
218+
role-to-assume: ${{ secrets.BEPS_AWS_ROLE_ARN }}
219+
aws-region: us-east-1
220+
221+
- name: Deploy to S3
222+
run: |
223+
aws s3 sync _site s3://${{ secrets.BEPS_S3_BUCKET }}/canary/ --delete --cache-control "public, max-age=3600"
224+
225+
- name: Invalidate CloudFront cache
226+
run: |
227+
aws cloudfront create-invalidation --distribution-id ${{ secrets.BEPS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/canary/*"
228+
229+
deploy-beps-preview:
230+
name: "deploy beps (preview)"
231+
runs-on: ubuntu-latest
232+
needs: [determine_changes, check-beps]
233+
if: github.event_name == 'pull_request' && needs.determine_changes.outputs.beps == 'true'
234+
steps:
235+
- uses: actions/checkout@v4
236+
with:
237+
persist-credentials: false
238+
239+
- name: Fetch BEP file history
240+
run: git fetch --depth=500 origin ${{ github.ref }} -- beps/
241+
242+
- name: Get branch name
243+
id: branch
244+
run: |
245+
BRANCH_NAME="${{ github.head_ref }}"
246+
SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g' | tr '[:upper:]' '[:lower:]')
247+
echo "name=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT
248+
249+
- name: Comment - Building Preview
250+
uses: thollander/[email protected] # v3.0.1
251+
with:
252+
message: |
253+
🏗️ **Building BEPs preview...** (run [${{ github.run_id }}](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}))
254+
comment-tag: beps-preview
255+
256+
- name: Fetch canary branch for diff
257+
run: |
258+
git fetch origin canary:canary || true
259+
260+
- name: Setup Python
261+
uses: actions/setup-python@v5
262+
with:
263+
python-version: 3.x
264+
265+
- name: Install MkDocs and dependencies
266+
run: |
267+
pip install mkdocs-material mkdocs-awesome-pages-plugin mkdocs-git-revision-date-localized-plugin mkdocs-git-committers-plugin-2
268+
269+
- name: Build MkDocs
270+
working-directory: beps
271+
run: mkdocs build
272+
273+
- name: Configure AWS credentials
274+
uses: aws-actions/configure-aws-credentials@v4 # v4
275+
with:
276+
role-to-assume: ${{ secrets.BEPS_AWS_ROLE_ARN }}
277+
aws-region: us-east-1
278+
279+
- name: Deploy to S3
280+
run: |
281+
aws s3 sync _site s3://${{ secrets.BEPS_S3_BUCKET }}/${{ steps.branch.outputs.name }}/ --delete --cache-control "public, max-age=300"
282+
283+
- name: Invalidate CloudFront cache
284+
run: |
285+
aws cloudfront create-invalidation --distribution-id ${{ secrets.BEPS_CLOUDFRONT_DISTRIBUTION_ID }} --paths "/${{ steps.branch.outputs.name }}/*"
286+
287+
- name: Update Building Comment
288+
uses: thollander/[email protected] # v3.0.1
289+
with:
290+
message: |
291+
✅ **Latest build complete** • [View logs](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})
292+
comment-tag: beps-preview
293+
294+
- name: Comment Preview URL
295+
uses: thollander/[email protected] # v3.0.1
296+
with:
297+
message: |
298+
🐑 **BEPs Preview Ready**
299+
300+
**Preview URL**: https://${{ secrets.BEPS_DOMAIN }}/${{ steps.branch.outputs.name }}/
301+
302+
<sub>Commit: `${{ github.event.pull_request.head.sha }}` • [Workflow run](${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }})</sub>
303+
149304
cargo-fmt:
150305
name: "cargo fmt"
151306
runs-on: ubuntu-latest
@@ -506,9 +661,27 @@ jobs:
506661
- cargo-test-wasm
507662
- cargo-build-msrv
508663
- snapshot-tests
664+
- check-beps
665+
- deploy-beps-canary
666+
- deploy-beps-preview
509667
steps:
510668
- name: "Check test results"
511669
run: |
670+
if [[ "${{ needs.check-beps.result }}" != "success" && "${{ needs.check-beps.result }}" != "skipped" ]]; then
671+
echo "::error::BEP check failed"
672+
exit 1
673+
fi
674+
675+
if [[ "${{ needs.deploy-beps-canary.result }}" != "success" && "${{ needs.deploy-beps-canary.result }}" != "skipped" ]]; then
676+
echo "::error::BEP canary deploy failed"
677+
exit 1
678+
fi
679+
680+
if [[ "${{ needs.deploy-beps-preview.result }}" != "success" && "${{ needs.deploy-beps-preview.result }}" != "skipped" ]]; then
681+
echo "::error::BEP preview deploy failed"
682+
exit 1
683+
fi
684+
512685
if [[ "${{ needs.cargo-fmt.result }}" != "success" && "${{ needs.cargo-fmt.result }}" != "skipped" ]]; then
513686
echo "::error::Formatting check failed"
514687
exit 1
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Cleanup BEPs Preview
2+
3+
on:
4+
delete:
5+
6+
permissions:
7+
contents: read
8+
id-token: write
9+
10+
jobs:
11+
cleanup:
12+
if: github.event.ref_type == 'branch'
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Get branch name
16+
id: branch
17+
run: |
18+
# Get the deleted branch name from the event
19+
BRANCH_NAME="${{ github.event.ref }}"
20+
SANITIZED_BRANCH=$(echo "$BRANCH_NAME" | sed 's/[^a-zA-Z0-9-]/-/g' | tr '[:upper:]' '[:lower:]')
21+
echo "name=$SANITIZED_BRANCH" >> $GITHUB_OUTPUT
22+
23+
- name: Configure AWS credentials
24+
uses: aws-actions/configure-aws-credentials@v4
25+
with:
26+
role-to-assume: ${{ secrets.BEPS_AWS_ROLE_ARN }}
27+
aws-region: us-east-1
28+
29+
- name: Delete S3 preview files
30+
run: |
31+
echo "Deleting preview files for branch: ${{ steps.branch.outputs.name }}"
32+
aws s3 rm s3://${{ secrets.BEPS_S3_BUCKET }}/${{ steps.branch.outputs.name }}/ --recursive
33+
echo "✓ Preview files deleted"
34+
35+
- name: Invalidate CloudFront cache
36+
run: |
37+
aws cloudfront create-invalidation \
38+
--distribution-id ${{ secrets.BEPS_CLOUDFRONT_DISTRIBUTION_ID }} \
39+
--paths "/${{ steps.branch.outputs.name }}/*"
40+
echo "✓ CloudFront cache invalidated"
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
name: Cleanup Stale BEPs Previews
2+
3+
on:
4+
schedule:
5+
# Run daily at 2 AM UTC
6+
- cron: "0 2 * * *"
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
id-token: write
12+
13+
jobs:
14+
cleanup:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0 # Get all branches
20+
21+
- name: Configure AWS credentials
22+
uses: aws-actions/configure-aws-credentials@v4
23+
with:
24+
role-to-assume: ${{ secrets.BEPS_AWS_ROLE_ARN }}
25+
aws-region: us-east-1
26+
27+
- name: Find and cleanup stale previews
28+
run: |
29+
echo "🔍 Scanning for stale preview deployments..."
30+
31+
# Get all "folders" (prefixes) in S3, excluding root files
32+
PREFIXES=$(aws s3 ls s3://${{ secrets.BEPS_S3_BUCKET }}/ | grep "PRE" | awk '{print $2}' | sed 's/\///g')
33+
34+
if [ -z "$PREFIXES" ]; then
35+
echo "No preview folders found in S3"
36+
exit 0
37+
fi
38+
39+
echo "Found preview folders: $PREFIXES"
40+
echo ""
41+
42+
# Get all current branches (sanitized names)
43+
echo "Getting current branches..."
44+
CURRENT_BRANCHES=$(git branch -r | grep -v HEAD | sed 's/origin\///' | sed 's/^[[:space:]]*//' | sed 's/[^a-zA-Z0-9-]/-/g' | tr '[:upper:]' '[:lower:]')
45+
46+
echo "Current branches (sanitized):"
47+
echo "$CURRENT_BRANCHES"
48+
echo ""
49+
50+
# Also check modification date (14 days ago)
51+
CUTOFF_DATE=$(date -u -d '14 days ago' +%s 2>/dev/null || date -u -v-14d +%s)
52+
53+
# Check each S3 prefix
54+
DELETED_COUNT=0
55+
for PREFIX in $PREFIXES; do
56+
# Skip canary (production) and other non-branch files
57+
if [[ "$PREFIX" == "canary" ]] || [[ "$PREFIX" == "index.html" ]] || [[ "$PREFIX" == "404.html" ]] || [[ "$PREFIX" == "assets" ]] || [[ "$PREFIX" == "sitemap.xml" ]]; then
58+
echo "⏭️ Skipping protected folder: $PREFIX"
59+
continue
60+
fi
61+
62+
# Check if branch still exists
63+
BRANCH_EXISTS=$(echo "$CURRENT_BRANCHES" | grep -x "$PREFIX" || echo "")
64+
65+
if [ -z "$BRANCH_EXISTS" ]; then
66+
echo "🗑️ Branch '$PREFIX' no longer exists - deleting preview..."
67+
aws s3 rm s3://${{ secrets.BEPS_S3_BUCKET }}/$PREFIX/ --recursive
68+
69+
# Invalidate CloudFront cache
70+
aws cloudfront create-invalidation \
71+
--distribution-id ${{ secrets.BEPS_CLOUDFRONT_DISTRIBUTION_ID }} \
72+
--paths "/$PREFIX/*" > /dev/null
73+
74+
DELETED_COUNT=$((DELETED_COUNT + 1))
75+
echo "✓ Deleted preview for '$PREFIX'"
76+
else
77+
# Check if files are older than 14 days
78+
LAST_MODIFIED=$(aws s3api list-objects-v2 \
79+
--bucket ${{ secrets.BEPS_S3_BUCKET }} \
80+
--prefix "$PREFIX/" \
81+
--query 'sort_by(Contents, &LastModified)[-1].LastModified' \
82+
--output text)
83+
84+
if [ ! -z "$LAST_MODIFIED" ]; then
85+
LAST_MODIFIED_EPOCH=$(date -u -d "$LAST_MODIFIED" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%S" "${LAST_MODIFIED%.*}" +%s)
86+
87+
if [ "$LAST_MODIFIED_EPOCH" -lt "$CUTOFF_DATE" ]; then
88+
echo "🗑️ Preview '$PREFIX' is older than 14 days (last modified: $LAST_MODIFIED) - deleting..."
89+
aws s3 rm s3://${{ secrets.BEPS_S3_BUCKET }}/$PREFIX/ --recursive
90+
91+
# Invalidate CloudFront cache
92+
aws cloudfront create-invalidation \
93+
--distribution-id ${{ secrets.BEPS_CLOUDFRONT_DISTRIBUTION_ID }} \
94+
--paths "/$PREFIX/*" > /dev/null
95+
96+
DELETED_COUNT=$((DELETED_COUNT + 1))
97+
echo "✓ Deleted stale preview for '$PREFIX'"
98+
else
99+
echo "✓ Preview '$PREFIX' is current (last modified: $LAST_MODIFIED)"
100+
fi
101+
fi
102+
fi
103+
done
104+
105+
echo ""
106+
echo "=================================================="
107+
if [ $DELETED_COUNT -eq 0 ]; then
108+
echo "✅ No stale previews found"
109+
else
110+
echo "✅ Cleaned up $DELETED_COUNT stale preview(s)"
111+
fi
112+
echo "=================================================="

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,7 @@ result
176176

177177
target/
178178

179-
baml-graph/
179+
baml-graph/_site/
180+
181+
# beps
182+
_site/

0 commit comments

Comments
 (0)