Skip to content

Commit c1a8a48

Browse files
committed
feat: release trigger with inputs
1 parent 158ad7d commit c1a8a48

File tree

1 file changed

+89
-7
lines changed

1 file changed

+89
-7
lines changed

.github/workflows/release.yml

Lines changed: 89 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ name: Release
22

33
on:
44
workflow_dispatch:
5+
inputs:
6+
locales:
7+
description: 'Comma-separated list of locales to deploy (e.g., en,zh-hans). Leave empty to deploy all enabled locales.'
8+
required: false
9+
type: string
510
push:
611
branches:
712
- main
@@ -10,14 +15,79 @@ jobs:
1015
check-changes:
1116
runs-on: ubuntu-latest
1217
outputs:
13-
matrix-include: ${{ steps.generate-matrix.outputs.include }}
18+
matrix-include: ${{ github.event_name == 'workflow_dispatch' && steps.generate-matrix-manual.outputs.include || steps.generate-matrix-auto.outputs.include }}
1419
steps:
1520
- name: Checkout code
1621
uses: actions/checkout@v3
1722
with:
18-
fetch-depth: 0
23+
fetch-depth: ${{ github.event_name == 'push' && 0 || 1 }}
1924

20-
- name: Generate dynamic files config
25+
- name: Generate deployment matrix (manual trigger)
26+
if: github.event_name == 'workflow_dispatch'
27+
id: generate-matrix-manual
28+
shell: bash
29+
run: |
30+
# Read locale config
31+
locale_config=$(cat .github/locales-config.json)
32+
33+
# Initialize matrix
34+
matrix_include="[]"
35+
36+
# Get manual input
37+
manual_locales="${{ github.event.inputs.locales }}"
38+
39+
if [ -z "$manual_locales" ]; then
40+
echo "No specific locales provided, deploying all enabled locales"
41+
# Deploy all enabled locales
42+
for locale in $(echo "$locale_config" | jq -r 'keys[]'); do
43+
enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled")
44+
secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id")
45+
46+
if [ "$enabled" == "true" ]; then
47+
echo "Adding $locale to deployment matrix"
48+
matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]')
49+
fi
50+
done
51+
else
52+
echo "Manual locales specified: $manual_locales"
53+
# Parse comma-separated locales
54+
IFS=',' read -ra LOCALE_ARRAY <<< "$manual_locales"
55+
for locale in "${LOCALE_ARRAY[@]}"; do
56+
# Trim whitespace
57+
locale=$(echo "$locale" | xargs)
58+
59+
# Check if locale exists and is enabled
60+
enabled=$(echo "$locale_config" | jq -r ".[\"$locale\"].enabled // \"false\"")
61+
secret_project_id=$(echo "$locale_config" | jq -r ".[\"$locale\"].secret_project_id // \"\"")
62+
63+
if [ "$enabled" == "true" ] && [ -n "$secret_project_id" ]; then
64+
echo "Adding $locale to deployment matrix"
65+
matrix_include=$(echo "$matrix_include" | jq --arg locale "$locale" --arg secret_id "$secret_project_id" '. + [{"locale": $locale, "secret_project_id": $secret_id}]')
66+
else
67+
echo "Skipping $locale (not enabled or not found in config)"
68+
fi
69+
done
70+
fi
71+
72+
echo "Final matrix: $matrix_include"
73+
74+
# Ensure the matrix is properly formatted as a single line
75+
matrix_output=$(echo "$matrix_include" | jq -c '.')
76+
echo "Matrix output (compact): $matrix_output"
77+
78+
# Debug: Check if it's valid JSON
79+
echo "Validating JSON..."
80+
if echo "$matrix_output" | jq . >/dev/null 2>&1; then
81+
echo "JSON is valid"
82+
echo "include=$matrix_output" >> $GITHUB_OUTPUT
83+
else
84+
echo "Invalid JSON generated: $matrix_output"
85+
echo "Outputting empty array instead"
86+
echo "include=[]" >> $GITHUB_OUTPUT
87+
fi
88+
89+
- name: Generate dynamic files config (automatic trigger)
90+
if: github.event_name == 'push'
2191
id: generate-files-config
2292
shell: bash
2393
run: |
@@ -54,14 +124,16 @@ jobs:
54124
echo "EOF"
55125
} >> $GITHUB_OUTPUT
56126
57-
- name: Get changed files with dynamic config
127+
- name: Get changed files with dynamic config (automatic trigger)
128+
if: github.event_name == 'push'
58129
id: changes
59130
uses: tj-actions/changed-files@v41
60131
with:
61132
files_yaml: ${{ steps.generate-files-config.outputs.files_yaml }}
62133

63-
- name: Generate deployment matrix
64-
id: generate-matrix
134+
- name: Generate deployment matrix (automatic trigger)
135+
if: github.event_name == 'push'
136+
id: generate-matrix-auto
65137
shell: bash
66138
run: |
67139
# Read locale config
@@ -108,7 +180,17 @@ jobs:
108180
# Ensure the matrix is properly formatted as a single line
109181
matrix_output=$(echo "$matrix_include" | jq -c '.')
110182
echo "Matrix output (compact): $matrix_output"
111-
echo "include=$matrix_output" >> $GITHUB_OUTPUT
183+
184+
# Debug: Check if it's valid JSON
185+
echo "Validating JSON..."
186+
if echo "$matrix_output" | jq . >/dev/null 2>&1; then
187+
echo "JSON is valid"
188+
echo "include=$matrix_output" >> $GITHUB_OUTPUT
189+
else
190+
echo "Invalid JSON generated: $matrix_output"
191+
echo "Outputting empty array instead"
192+
echo "include=[]" >> $GITHUB_OUTPUT
193+
fi
112194
113195
deploy-and-update-index:
114196
needs: check-changes

0 commit comments

Comments
 (0)