Skip to content

feat: prerelease read config from locales-config #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 1, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 51 additions & 35 deletions .github/workflows/prerelease.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,57 +15,76 @@ permissions:
issues: write

jobs:
deploy:
generate-matrix:
if: |
github.event_name == 'pull_request' &&
contains(github.event.pull_request.labels.*.name, 'prerelease')
(contains(github.event.pull_request.labels.*.name, 'prerelease') ||
contains(toJSON(github.event.pull_request.labels.*.name), 'prerelease:'))
runs-on: ubuntu-latest
strategy:
matrix:
include:
- locale: en
secret_project_id: VERCEL_PROJECT_EN_ID
- locale: zh-hans
secret_project_id: VERCEL_PROJECT_ZH_HANS_ID
- locale: zh-hant
secret_project_id: VERCEL_PROJECT_ZH_HANT_ID
name: Deploy ${{ matrix.locale }}
outputs:
matrix: ${{ steps.set-matrix.outputs.matrix }}
steps:
# Calculate if this matrix job should run based on PR labels
#
# This job will deploy if:
# - The event is NOT a pull_request (e.g., workflow_dispatch)
# - OR the PR has the label 'prerelease'
# - OR the PR has the label 'prerelease:<locale>' matching the current matrix locale
- name: Calculate should_deploy
id: should_deploy
shell: bash
- name: Checkout code
uses: actions/checkout@v3
- name: Generate matrix from locales config
id: set-matrix
run: |
LABELS_JSON='${{ toJson(github.event.pull_request.labels.*.name) }}'
echo "LABELS_JSON: $LABELS_JSON"
SHOULD_DEPLOY=false

# Check if we should deploy all locales (general prerelease)
SHOULD_DEPLOY_GENERAL=false
if [[ "${{ github.event_name }}" != "pull_request" ]]; then
SHOULD_DEPLOY=true
SHOULD_DEPLOY_GENERAL=true
elif echo "$LABELS_JSON" | grep -E '"prerelease"' > /dev/null; then
SHOULD_DEPLOY=true
elif echo "$LABELS_JSON" | grep -E '"prerelease:'"${{ matrix.locale }}"'"' > /dev/null; then
SHOULD_DEPLOY=true
SHOULD_DEPLOY_GENERAL=true
fi

echo "Should deploy all locales: $SHOULD_DEPLOY_GENERAL"

# Read the locales config and generate matrix for enabled locales that should deploy
MATRIX=$(jq -c --argjson should_deploy_general "$SHOULD_DEPLOY_GENERAL" --argjson labels "$LABELS_JSON" '
to_entries |
map(select(.value.enabled == true)) |
map(. as $item | {
locale: $item.key,
secret_project_id: $item.value.secret_project_id,
should_deploy: (
$should_deploy_general or
($labels | any(. == ("prerelease:" + $item.key)))
)
}) |
map(select(.should_deploy == true)) |
map({locale: .locale, secret_project_id: .secret_project_id})
' .github/locales-config.json)

echo "matrix={\"include\":$MATRIX}" >> $GITHUB_OUTPUT
echo "Generated matrix: {\"include\":$MATRIX}"

# Check if there are any enabled locales
ENABLED_COUNT=$(echo "$MATRIX" | jq length)
if [ "$ENABLED_COUNT" -eq 0 ]; then
echo "No enabled locales found in locales-config.json"
exit 1
fi
echo "should_deploy=$SHOULD_DEPLOY" >> $GITHUB_OUTPUT

deploy:
needs: generate-matrix
runs-on: ubuntu-latest
strategy:
matrix: ${{ fromJson(needs.generate-matrix.outputs.matrix) }}
name: Deploy ${{ matrix.locale }}
steps:
- name: Checkout code
if: steps.should_deploy.outputs.should_deploy == 'true'
uses: actions/checkout@v3
with:
fetch-depth: 1
ref: ${{ github.head_ref }}
- name: Log checked out commit
if: steps.should_deploy.outputs.should_deploy == 'true'
run: git log -1
- name: Setup Tools
if: steps.should_deploy.outputs.should_deploy == 'true'
uses: ./.github/actions/setup
- name: Deploy to Vercel (${{ matrix.locale }})
if: steps.should_deploy.outputs.should_deploy == 'true'
id: deploy
uses: ./.github/actions/vercel-deploy
with:
Expand All @@ -74,29 +93,26 @@ jobs:
vercel_org_id: ${{ secrets.VERCEL_ORG_ID }}
vercel_token: ${{ secrets.VERCEL_TOKEN }}
- name: Set deploy outputs
if: steps.should_deploy.outputs.should_deploy == 'true'
id: set_outputs
run: |
echo "preview_url=${{ steps.deploy.outputs.prod_url }}" >> $GITHUB_OUTPUT
echo "inspect_url=${{ steps.deploy.outputs.inspect_url }}" >> $GITHUB_OUTPUT
echo "label=${{ matrix.locale }}" >> $GITHUB_OUTPUT
- name: Write deploy result to file
if: steps.should_deploy.outputs.should_deploy == 'true'
run: |
jq -n \
--arg label "${{ steps.set_outputs.outputs.label }}" \
--arg preview_url "${{ steps.set_outputs.outputs.preview_url }}" \
--arg inspect_url "${{ steps.set_outputs.outputs.inspect_url }}" \
'{label: $label, preview_url: $preview_url, inspect_url: $inspect_url}' > deploy-result.json
- name: Upload deploy result artifact
if: steps.should_deploy.outputs.should_deploy == 'true'
uses: actions/upload-artifact@v4
with:
name: deploy-result-${{ matrix.locale }}
path: deploy-result.json

comment-vercel-previews:
needs: deploy
needs: [generate-matrix, deploy]
name: Comment Vercel Previews
runs-on: ubuntu-latest
steps:
Expand Down