feat: update sync docs #56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| locales: | |
| description: 'Comma-separated list of locales to deploy (e.g., en,zh-hans). Leave empty to deploy all enabled locales.' | |
| required: false | |
| type: string | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| check-changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix-include: ${{ github.event_name == 'workflow_dispatch' && steps.generate-matrix-manual.outputs.include || steps.generate-matrix-auto.outputs.include }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: ${{ github.event_name == 'push' && 0 || 1 }} | |
| - name: Generate deployment matrix (manual trigger) | |
| if: github.event_name == 'workflow_dispatch' | |
| id: generate-matrix-manual | |
| shell: bash | |
| run: | | |
| # Read locale config | |
| locale_config=$(cat .github/locales-config.json) | |
| # Initialize matrix | |
| matrix_include="[]" | |
| # Get manual input | |
| manual_locales="${{ github.event.inputs.locales }}" | |
| if [ -z "$manual_locales" ]; then | |
| echo "No specific locales provided, deploying all enabled locales" | |
| # Deploy all enabled locales | |
| for locale in $(echo "$locale_config" | jq -r 'keys[]'); do | |
| enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled") | |
| secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id") | |
| if [ "$enabled" == "true" ]; then | |
| echo "Adding $locale to deployment matrix" | |
| matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]') | |
| fi | |
| done | |
| else | |
| echo "Manual locales specified: $manual_locales" | |
| # Parse comma-separated locales | |
| IFS=',' read -ra LOCALE_ARRAY <<< "$manual_locales" | |
| for locale in "${LOCALE_ARRAY[@]}"; do | |
| # Trim whitespace | |
| locale=$(echo "$locale" | xargs) | |
| # Check if locale exists and is enabled | |
| enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled // \"false\"") | |
| secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id // \"\"") | |
| if [ "$enabled" == "true" ] && [ -n "$secret_project_id" ]; then | |
| echo "Adding $locale to deployment matrix" | |
| matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]') | |
| else | |
| echo "Skipping $locale (not enabled or not found in config)" | |
| fi | |
| done | |
| fi | |
| - name: Generate dynamic files config (automatic trigger) | |
| if: github.event_name == 'push' | |
| id: generate-files-config | |
| shell: bash | |
| run: | | |
| # Read locale config | |
| locale_config=$(cat .github/locales-config.json) | |
| # Start with core files config | |
| files_yaml="core: | |
| - 'apps/docs/**' | |
| - 'packages/**' | |
| - '!apps/docs/content/**' | |
| - '!apps/docs/messages/**'" | |
| # Add each locale from config dynamically | |
| for locale in $(echo "$locale_config" | jq -r 'keys[]'); do | |
| files_yaml="$files_yaml | |
| $locale: | |
| - 'apps/docs/content/$locale/**' | |
| - 'apps/docs/messages/$locale.json'" | |
| done | |
| echo "Generated files_yaml:" | |
| echo "$files_yaml" | |
| # Debug: Also log the exact content that will be passed to changed-files | |
| echo "=== Debug: files_yaml content ===" | |
| echo "$files_yaml" | |
| echo "=================================" | |
| # Save to output for next step | |
| { | |
| echo "files_yaml<<EOF" | |
| echo "$files_yaml" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Get changed files with dynamic config (automatic trigger) | |
| if: github.event_name == 'push' | |
| id: changes | |
| uses: tj-actions/changed-files@v41 | |
| with: | |
| files_yaml: ${{ steps.generate-files-config.outputs.files_yaml }} | |
| - name: Generate deployment matrix (automatic trigger) | |
| if: github.event_name == 'push' | |
| id: generate-matrix-auto | |
| shell: bash | |
| run: | | |
| # Read locale config | |
| locale_config=$(cat .github/locales-config.json) | |
| # Initialize matrix | |
| matrix_include="[]" | |
| echo "=== Debug: All changes outputs ===" | |
| changes_json='${{ toJSON(steps.changes.outputs) }}' | |
| echo "Changes JSON: $changes_json" | |
| # Check what keys were actually changed | |
| echo "Changed keys: $(echo "$changes_json" | jq -r '.changed_keys // "none"')" | |
| echo "Modified keys: $(echo "$changes_json" | jq -r '.modified_keys // "none"')" | |
| echo "==================================" | |
| # Check core changes - use the correct output format for files_yaml | |
| core_changed="${{ steps.changes.outputs.core_any_changed }}" | |
| echo "Core changed: '$core_changed'" | |
| # Check each locale dynamically from config | |
| for locale in $(echo "$locale_config" | jq -r 'keys[]'); do | |
| # Get locale configuration | |
| enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled") | |
| secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id") | |
| # Get locale change status dynamically from the changes JSON | |
| # Use the correct output format: {locale}_any_changed | |
| locale_changed=$(echo "$changes_json" | jq -r ".[\"${locale}_any_changed\"] // \"false\"") | |
| echo "Checking $locale: enabled=$enabled, changed=$locale_changed, core_changed=$core_changed" | |
| # Add to matrix if enabled and (core changed or locale changed) | |
| if [ "$enabled" == "true" ] && ([ "$core_changed" == "true" ] || [ "$locale_changed" == "true" ]); then | |
| echo "Adding $locale to deployment matrix" | |
| matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]') | |
| fi | |
| done | |
| echo "Final matrix: $matrix_include" | |
| # Ensure the matrix is properly formatted as a single line | |
| matrix_output=$(echo "$matrix_include" | jq -c '.') | |
| echo "Matrix output (compact): $matrix_output" | |
| # Debug: Check if it's valid JSON | |
| echo "Validating JSON..." | |
| if echo "$matrix_output" | jq . >/dev/null 2>&1; then | |
| echo "JSON is valid" | |
| echo "include=$matrix_output" >> $GITHUB_OUTPUT | |
| else | |
| echo "Invalid JSON generated: $matrix_output" | |
| echo "Outputting empty array instead" | |
| echo "include=[]" >> $GITHUB_OUTPUT | |
| fi | |
| deploy-and-update-index: | |
| needs: check-changes | |
| if: needs.check-changes.outputs.matrix-include != '[]' | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| include: ${{ fromJson(needs.check-changes.outputs.matrix-include) }} | |
| name: Deploy ${{ matrix.locale }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 1 | |
| - name: Setup Tools | |
| uses: ./.github/actions/setup | |
| - name: Deploy to Vercel (${{ matrix.locale }}) | |
| id: deploy | |
| uses: ./.github/actions/vercel-deploy | |
| with: | |
| environment: production | |
| prodFlag: --prod | |
| vercel_project_id: ${{ secrets[matrix.secret_project_id] }} | |
| vercel_org_id: ${{ secrets.VERCEL_ORG_ID }} | |
| vercel_token: ${{ secrets.VERCEL_TOKEN }} | |
| - name: Copy .vercel/.env.production.local | |
| shell: bash | |
| run: | | |
| cp .vercel/.env.production.local apps/docs/.env | |
| - name: Update Search Index | |
| shell: bash | |
| run: pnpm run docs:update-search-index |