|
| 1 | +name: Submit Sitemaps |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + locales: |
| 7 | + description: 'Comma-separated list of locales to submit sitemaps for (e.g., en,zh-hans). Leave empty to submit all locales with sitemaps.' |
| 8 | + required: false |
| 9 | + type: string |
| 10 | + default: '' |
| 11 | + domain: |
| 12 | + description: 'Domain for Google Search Console (e.g., sc-domain:nextjs.im)' |
| 13 | + required: false |
| 14 | + type: string |
| 15 | + default: 'sc-domain:nextjs.im' |
| 16 | + dry_run: |
| 17 | + description: 'Preview what would be submitted without making requests' |
| 18 | + required: false |
| 19 | + type: boolean |
| 20 | + default: false |
| 21 | + workflow_dispatch: |
| 22 | + inputs: |
| 23 | + locales: |
| 24 | + description: 'Comma-separated list of locales to submit sitemaps for (e.g., en,zh-hans). Leave empty to submit all locales with sitemaps.' |
| 25 | + required: false |
| 26 | + type: string |
| 27 | + default: '' |
| 28 | + domain: |
| 29 | + description: 'Domain for Google Search Console (e.g., sc-domain:nextjs.im)' |
| 30 | + required: false |
| 31 | + type: string |
| 32 | + default: 'sc-domain:nextjs.im' |
| 33 | + dry_run: |
| 34 | + description: 'Preview what would be submitted without making requests' |
| 35 | + required: false |
| 36 | + type: boolean |
| 37 | + default: false |
| 38 | + |
| 39 | +jobs: |
| 40 | + submit-sitemaps: |
| 41 | + runs-on: ubuntu-latest |
| 42 | + name: Submit Sitemaps to Google Search Console |
| 43 | + steps: |
| 44 | + - name: Checkout code |
| 45 | + uses: actions/checkout@v3 |
| 46 | + with: |
| 47 | + fetch-depth: 1 |
| 48 | + |
| 49 | + - name: Setup Tools |
| 50 | + uses: ./.github/actions/setup |
| 51 | + |
| 52 | + - name: Collect and Submit Sitemaps |
| 53 | + shell: bash |
| 54 | + env: |
| 55 | + GOOGLE_SERVICE_ACCOUNT_EMAIL: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_EMAIL }} |
| 56 | + GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY: ${{ secrets.GOOGLE_SERVICE_ACCOUNT_PRIVATE_KEY }} |
| 57 | + run: | |
| 58 | + echo "🔍 Collecting sitemap URLs..." |
| 59 | + |
| 60 | + # Read locales config |
| 61 | + LOCALES_CONFIG=$(cat .github/locales-config.json) |
| 62 | + |
| 63 | + # Determine which locales to process |
| 64 | + if [ -n "${{ inputs.locales }}" ]; then |
| 65 | + # Use specified locales |
| 66 | + IFS=',' read -ra SELECTED_LOCALES <<< "${{ inputs.locales }}" |
| 67 | + echo "📝 Processing specified locales: ${{ inputs.locales }}" |
| 68 | + else |
| 69 | + # Get all enabled locales with sitemaps |
| 70 | + SELECTED_LOCALES=($(echo "$LOCALES_CONFIG" | jq -r 'to_entries[] | select(.value.enabled == true and .value.sitemap != null) | .key')) |
| 71 | + echo "📝 Processing all enabled locales with sitemaps: ${SELECTED_LOCALES[*]}" |
| 72 | + fi |
| 73 | + |
| 74 | + # Collect sitemap URLs |
| 75 | + SITEMAP_URLS=() |
| 76 | + |
| 77 | + for locale in "${SELECTED_LOCALES[@]}"; do |
| 78 | + # Check if locale has sitemap |
| 79 | + SITEMAP_URL=$(echo "$LOCALES_CONFIG" | jq -r --arg locale "$locale" '.[$locale].sitemap // empty') |
| 80 | + |
| 81 | + if [ -n "$SITEMAP_URL" ]; then |
| 82 | + SITEMAP_URLS+=("$SITEMAP_URL") |
| 83 | + echo "✅ Found sitemap for $locale: $SITEMAP_URL" |
| 84 | + else |
| 85 | + echo "⚠️ Skipping $locale - no sitemap configured" |
| 86 | + fi |
| 87 | + done |
| 88 | + |
| 89 | + if [ ${#SITEMAP_URLS[@]} -eq 0 ]; then |
| 90 | + echo "❌ No sitemaps found to submit" |
| 91 | + exit 1 |
| 92 | + fi |
| 93 | + |
| 94 | + # Join sitemap URLs with commas |
| 95 | + SITEMAP_URLS_STRING=$(IFS=','; echo "${SITEMAP_URLS[*]}") |
| 96 | + |
| 97 | + echo "🚀 Submitting ${#SITEMAP_URLS[@]} sitemaps to Google Search Console" |
| 98 | + echo "🌐 Domain: ${{ inputs.domain }}" |
| 99 | + echo "📄 Sitemap URLs: $SITEMAP_URLS_STRING" |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | + DRY_RUN_FLAG="" |
| 104 | + if [ "${{ inputs.dry_run }}" = "true" ]; then |
| 105 | + DRY_RUN_FLAG="--dry-run" |
| 106 | + echo "🔍 Running in dry-run mode" |
| 107 | + fi |
| 108 | + |
| 109 | + pnpm run docs:submit-sitemap "${{ inputs.domain }}" --sitemap-urls "$SITEMAP_URLS_STRING" $DRY_RUN_FLAG |
0 commit comments