|
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 | + # Save to output for next step |
| 46 | + { |
| 47 | + echo "files_yaml<<EOF" |
| 48 | + echo "$files_yaml" |
| 49 | + echo "EOF" |
| 50 | + } >> $GITHUB_OUTPUT |
| 51 | + |
| 52 | + - name: Get changed files with dynamic config |
| 53 | + id: changes |
| 54 | + uses: tj-actions/changed-files@v41 |
| 55 | + with: |
| 56 | + files_yaml: ${{ steps.generate-files-config.outputs.files_yaml }} |
| 57 | + |
| 58 | + - name: Generate deployment matrix |
| 59 | + id: generate-matrix |
| 60 | + shell: bash |
| 61 | + run: | |
| 62 | + # Read locale config |
| 63 | + locale_config=$(cat .github/locales-config.json) |
| 64 | + |
| 65 | + # Initialize matrix |
| 66 | + matrix_include="[]" |
| 67 | + |
| 68 | + # Check core changes |
| 69 | + core_changed="${{ steps.changes.outputs.core }}" |
| 70 | + |
| 71 | + echo "Core changed: $core_changed" |
| 72 | + |
| 73 | + # Get all change outputs as JSON for easier parsing |
| 74 | + changes_json='${{ toJSON(steps.changes.outputs) }}' |
| 75 | + |
| 76 | + # Check each locale dynamically from config |
| 77 | + for locale in $(echo "$locale_config" | jq -r 'keys[]'); do |
| 78 | + # Get locale configuration |
| 79 | + enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled") |
| 80 | + secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id") |
| 81 | + |
| 82 | + # Get locale change status dynamically from the changes JSON |
| 83 | + locale_changed=$(echo "$changes_json" | jq -r ".[\"$locale\"] // \"false\"") |
| 84 | + |
| 85 | + echo "Checking $locale: enabled=$enabled, changed=$locale_changed, core_changed=$core_changed" |
| 86 | + |
| 87 | + # Add to matrix if enabled and (core changed or locale changed) |
| 88 | + if [ "$enabled" == "true" ] && ([ "$core_changed" == "true" ] || [ "$locale_changed" == "true" ]); then |
| 89 | + echo "Adding $locale to deployment matrix" |
| 90 | + matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]') |
| 91 | + fi |
| 92 | + done |
| 93 | + |
| 94 | + echo "Final matrix: $matrix_include" |
| 95 | + echo "include=$matrix_include" >> $GITHUB_OUTPUT |
| 96 | +
|
10 | 97 | deploy-and-update-index: |
| 98 | + needs: check-changes |
| 99 | + if: needs.check-changes.outputs.matrix-include != '[]' |
11 | 100 | runs-on: ubuntu-latest |
12 | 101 | strategy: |
13 | 102 | 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 |
| 103 | + include: ${{ fromJson(needs.check-changes.outputs.matrix-include) }} |
21 | 104 | name: Deploy ${{ matrix.locale }} |
22 | 105 | steps: |
23 | 106 | - name: Checkout code |
|
0 commit comments