|
7 | 7 | - main |
8 | 8 |
|
9 | 9 | jobs: |
| 10 | + check-changes: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + outputs: |
| 13 | + matrix-include: ${{ steps.generate-matrix.outputs.include }} |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v3 |
| 17 | + with: |
| 18 | + fetch-depth: 0 |
| 19 | + |
| 20 | + - name: Generate dynamic files config |
| 21 | + id: generate-files-config |
| 22 | + shell: bash |
| 23 | + run: | |
| 24 | + # Read locale config |
| 25 | + locale_config=$(cat .github/locales-config.json) |
| 26 | + |
| 27 | + # Start with core files config |
| 28 | + files_yaml="core: |
| 29 | + - 'apps/docs/**' |
| 30 | + - 'packages/**' |
| 31 | + - '!apps/docs/content/**' |
| 32 | + - '!apps/docs/messages/**'" |
| 33 | + |
| 34 | + # Add each locale from config dynamically |
| 35 | + for locale in $(echo "$locale_config" | jq -r 'keys[]'); do |
| 36 | + files_yaml="$files_yaml |
| 37 | + $locale: |
| 38 | + - 'apps/docs/content/$locale/**' |
| 39 | + - 'apps/docs/messages/$locale.json'" |
| 40 | + done |
| 41 | + |
| 42 | + echo "Generated files_yaml:" |
| 43 | + echo "$files_yaml" |
| 44 | + |
| 45 | + # Debug: Also log the exact content that will be passed to changed-files |
| 46 | + echo "=== Debug: files_yaml content ===" |
| 47 | + echo "$files_yaml" |
| 48 | + echo "=================================" |
| 49 | + |
| 50 | + # Save to output for next step |
| 51 | + { |
| 52 | + echo "files_yaml<<EOF" |
| 53 | + echo "$files_yaml" |
| 54 | + echo "EOF" |
| 55 | + } >> $GITHUB_OUTPUT |
| 56 | + |
| 57 | + - name: Get changed files with dynamic config |
| 58 | + id: changes |
| 59 | + uses: tj-actions/changed-files@v41 |
| 60 | + with: |
| 61 | + files_yaml: ${{ steps.generate-files-config.outputs.files_yaml }} |
| 62 | + |
| 63 | + - name: Generate deployment matrix |
| 64 | + id: generate-matrix |
| 65 | + shell: bash |
| 66 | + run: | |
| 67 | + # Read locale config |
| 68 | + locale_config=$(cat .github/locales-config.json) |
| 69 | + |
| 70 | + # Initialize matrix |
| 71 | + matrix_include="[]" |
| 72 | + |
| 73 | + echo "=== Debug: All changes outputs ===" |
| 74 | + changes_json='${{ toJSON(steps.changes.outputs) }}' |
| 75 | + echo "Changes JSON: $changes_json" |
| 76 | + |
| 77 | + # Check what keys were actually changed |
| 78 | + echo "Changed keys: $(echo "$changes_json" | jq -r '.changed_keys // "none"')" |
| 79 | + echo "Modified keys: $(echo "$changes_json" | jq -r '.modified_keys // "none"')" |
| 80 | + echo "==================================" |
| 81 | + |
| 82 | + # Check core changes - use the correct output format for files_yaml |
| 83 | + core_changed="${{ steps.changes.outputs.core_any_changed }}" |
| 84 | + |
| 85 | + echo "Core changed: '$core_changed'" |
| 86 | + |
| 87 | + # Check each locale dynamically from config |
| 88 | + for locale in $(echo "$locale_config" | jq -r 'keys[]'); do |
| 89 | + # Get locale configuration |
| 90 | + enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled") |
| 91 | + secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id") |
| 92 | + |
| 93 | + # Get locale change status dynamically from the changes JSON |
| 94 | + # Use the correct output format: {locale}_any_changed |
| 95 | + locale_changed=$(echo "$changes_json" | jq -r ".[\"${locale}_any_changed\"] // \"false\"") |
| 96 | + |
| 97 | + echo "Checking $locale: enabled=$enabled, changed=$locale_changed, core_changed=$core_changed" |
| 98 | + |
| 99 | + # Add to matrix if enabled and (core changed or locale changed) |
| 100 | + if [ "$enabled" == "true" ] && ([ "$core_changed" == "true" ] || [ "$locale_changed" == "true" ]); then |
| 101 | + echo "Adding $locale to deployment matrix" |
| 102 | + matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]') |
| 103 | + fi |
| 104 | + done |
| 105 | + |
| 106 | + echo "Final matrix: $matrix_include" |
| 107 | + |
| 108 | + # Ensure the matrix is properly formatted as a single line |
| 109 | + matrix_output=$(echo "$matrix_include" | jq -c '.') |
| 110 | + echo "Matrix output (compact): $matrix_output" |
| 111 | + echo "include=$matrix_output" >> $GITHUB_OUTPUT |
| 112 | +
|
10 | 113 | deploy-and-update-index: |
| 114 | + needs: check-changes |
| 115 | + if: needs.check-changes.outputs.matrix-include != '[]' |
11 | 116 | runs-on: ubuntu-latest |
12 | 117 | strategy: |
13 | 118 | matrix: |
14 | | - include: |
15 | | - - locale: en |
16 | | - secret_project_id: VERCEL_PROJECT_EN_ID |
17 | | - - locale: zh-hans |
18 | | - secret_project_id: VERCEL_PROJECT_ZH_HANS_ID |
19 | | - - locale: zh-hant |
20 | | - secret_project_id: VERCEL_PROJECT_ZH_HANT_ID |
| 119 | + include: ${{ fromJson(needs.check-changes.outputs.matrix-include) }} |
21 | 120 | name: Deploy ${{ matrix.locale }} |
22 | 121 | steps: |
23 | 122 | - name: Checkout code |
|
0 commit comments