Skip to content

Commit

Permalink
Add documentation for Vercel build step
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Feb 9, 2025
1 parent aeaddf7 commit cee2289
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 9 deletions.
5 changes: 4 additions & 1 deletion apps/web/src/contexts/docs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,10 @@ export function DocsProvider({ children }: { children: React.ReactNode }) {
},
{
title: t("ci"),
items: [{ href: "/docs/github-actions", label: t("github-actions") }],
items: [
{ href: "/docs/github-actions", label: t("github-actions") },
{ href: "/docs/vercel", label: t("vercel") },
],
},
// {
// title: t("presets"),
Expand Down
13 changes: 5 additions & 8 deletions apps/web/src/markdown/docs/en/github-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
With the github action, you can easily translate your code by just pushing your code to the repository, the github action will then translate your new keys, either create a pull request or commit your changes.
This saves you a lot of time and effort while maintaining high quality translations.

---

## How it works




---

## Installation
Expand Down Expand Up @@ -96,4 +89,8 @@ When set to `true`, the action will:
When set to `false` (default), the action will:
- Commit the changes directly to the current branch
- Push the changes without creating a pull request
- Push the changes without creating a pull request
## Using with Vercel
If you're using Vercel for deployments, you can combine this GitHub Action with our [Vercel build validation](./vercel) to ensure your translations are always synchronized before deployment. This prevents deployments with missing or outdated translations.
79 changes: 79 additions & 0 deletions apps/web/src/markdown/docs/en/vercel.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Vercel Build Validation

This guide explains how to use our build validation script with Vercel's "Ignored Build Step" feature to ensure proper localization file updates.

## Overview

When deploying to Vercel, it's important to ensure that all localization files are properly synchronized. We provide a build script that validates localization file changes and determines whether a deployment should proceed.

## Using the Ignored Build Step

In your Vercel project settings, you can use our validation script in the "Ignored Build Step" field. This will prevent unnecessary builds when localization files aren't properly synchronized.

Set the following in the "Ignored Build Step" field:
```bash
bash vercel-build.sh
```

**Note:** Make sure the script is in your repository's root directory or adjust the path accordingly.

## Build Script

The build script (`vercel-build.sh`) checks if changes to the source localization file (`en.json`) are properly reflected in other locale files:

```bash
#!/bin/bash

# Change these to your source paths
LOCALES_DIR="src/locales"
SOURCE_FILE="${LOCALES_DIR}/en.json"

# Check if there are any changes at all
if git diff HEAD^ HEAD --quiet; then
echo "No changes detected. Skipping build."
exit 0
fi

# Check if there are changes in source file
if git diff --name-only HEAD^ HEAD | grep -q "^${SOURCE_FILE}$"; then
echo "Changes detected in ${SOURCE_FILE}"
# Check if other files in source directory were also changed
if git diff --name-only HEAD^ HEAD | grep -q "^${LOCALES_DIR}/[^/]*\.json$" | grep -v "^${SOURCE_FILE}$"; then
echo "Other locale files were also changed. Proceeding with build..."
exit 1
else
echo "${SOURCE_FILE} was changed but other locale files were not. Failing build."
exit 0
fi
else
# If no changes in source file, proceed with build
echo "No changes in ${SOURCE_FILE}. Proceeding with build..."
exit 1
fi
```

## How It Works

The script follows Vercel's "Ignored Build Step" convention:

- Returns `exit 0`: Skip the build (when validation fails or no changes detected)
- Returns `exit 1`: Proceed with the build (when changes are valid)

The script performs these checks:

1. Detects if any changes were made in the current commit
2. If the source locale file (`en.json`) was modified:
- Checks if other locale files were also updated
- Prevents the build if only the source file was changed
3. Allows the build to proceed if:
- No changes were made to the source file
- Both source and other locale files were updated

## Important Notes

1. Vercel performs a shallow clone with `git clone --depth=10`, so the script will only have access to the last 10 commits
2. The script runs in the same directory as your project's "Root Directory" setting in Vercel
3. Make sure the script has executable permissions (`chmod +x vercel-build.sh`) before committing


For more information about setting up GitHub Actions for translation workflows, see our [GitHub Actions guide](./github-actions).
1 change: 1 addition & 0 deletions apps/web/src/messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@
"configuration": "Configuration",
"cli": "CLI",
"github-actions": "GitHub Actions",
"vercel": "Vercel",
"tuning": "Tuning",
"overrides": "Overrides",
"settings": "Settings",
Expand Down

0 comments on commit cee2289

Please sign in to comment.