feat: release action config #36
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: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| check-changes: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| matrix-include: ${{ steps.generate-matrix.outputs.include }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| with: | |
| fetch-depth: 0 | |
| - name: Generate dynamic files config | |
| 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" | |
| # Save to output for next step | |
| { | |
| echo "files_yaml<<EOF" | |
| echo "$files_yaml" | |
| echo "EOF" | |
| } >> $GITHUB_OUTPUT | |
| - name: Get changed files with dynamic config | |
| id: changes | |
| uses: tj-actions/changed-files@v41 | |
| with: | |
| files_yaml: ${{ steps.generate-files-config.outputs.files_yaml }} | |
| - name: Generate deployment matrix | |
| id: generate-matrix | |
| shell: bash | |
| run: | | |
| # Read locale config | |
| locale_config=$(cat .github/locales-config.json) | |
| # Initialize matrix | |
| matrix_include="[]" | |
| # Check core changes | |
| core_changed="${{ steps.changes.outputs.core }}" | |
| echo "Core changed: $core_changed" | |
| # Get all change outputs as JSON for easier parsing | |
| changes_json='${{ toJSON(steps.changes.outputs) }}' | |
| # 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 | |
| locale_changed=$(echo "$changes_json" | jq -r ".[\"$locale\"] // \"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" | |
| echo "include=$matrix_include" >> $GITHUB_OUTPUT | |
| 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 |