fix: format #6
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: 🏗️ Update Country Pages | |
on: | |
# Trigger when companies.json is modified | |
push: | |
branches: [main, master] | |
paths: | |
- "data/companies.json" | |
# Trigger when PRs are merged that modify companies.json | |
pull_request: | |
types: [closed] | |
paths: | |
- "data/companies.json" | |
# Allow manual triggering | |
workflow_dispatch: | |
inputs: | |
reason: | |
description: "Reason for manual update" | |
required: false | |
default: "Manual update requested" | |
jobs: | |
update-pages: | |
# Only run on merged PRs or direct pushes to main | |
if: github.event_name == 'workflow_dispatch' || github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.merged == true) | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
pull-requests: read | |
steps: | |
- name: 📥 Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
fetch-depth: 0 | |
- name: 🔧 Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "18" | |
cache: "npm" | |
- name: 📦 Install Dependencies | |
run: | | |
# Install jq for JSON processing if needed | |
sudo apt-get update && sudo apt-get install -y jq | |
- name: ✅ Validate JSON | |
run: | | |
echo "🔍 Validating companies.json structure..." | |
if ! jq empty data/companies.json; then | |
echo "❌ Invalid JSON in companies.json" | |
exit 1 | |
fi | |
echo "✅ JSON is valid" | |
- name: 🏗️ Generate Country Pages | |
run: | | |
echo "🚀 Generating country pages from companies.json..." | |
node scripts/generate-country-pages.js | |
- name: 📊 Run Validation Scripts | |
run: | | |
echo "🔍 Running validation scripts..." | |
if [ -f "scripts/validate_json.sh" ]; then | |
chmod +x scripts/validate_json.sh | |
./scripts/validate_json.sh | |
fi | |
- name: 📈 Generate Statistics | |
run: | | |
echo "📊 Generating updated statistics..." | |
if [ -f "scripts/generate_stats.sh" ]; then | |
chmod +x scripts/generate_stats.sh | |
./scripts/generate_stats.sh > /tmp/stats.txt | |
echo "Statistics generated successfully" | |
fi | |
- name: 🔍 Check for Changes | |
id: check-changes | |
run: | | |
git add docs/countries/ | |
if git diff --staged --quiet; then | |
echo "No changes detected in country pages" | |
echo "has-changes=false" >> $GITHUB_OUTPUT | |
else | |
echo "Changes detected in country pages" | |
echo "has-changes=true" >> $GITHUB_OUTPUT | |
fi | |
- name: 📝 Commit Changes | |
if: steps.check-changes.outputs.has-changes == 'true' | |
run: | | |
git config --local user.email "[email protected]" | |
git config --local user.name "GitHub Action Bot" | |
# Get commit info for better commit message | |
if [ "${{ github.event_name }}" == "pull_request" ]; then | |
COMMIT_MSG="🤖 Auto-update country pages from PR #${{ github.event.number }}" | |
COMMIT_BODY="Updated country pages based on changes to companies.json in PR #${{ github.event.number }}" | |
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
COMMIT_MSG="🤖 Manual update of country pages" | |
COMMIT_BODY="${{ github.event.inputs.reason }}" | |
else | |
COMMIT_MSG="🤖 Auto-update country pages" | |
COMMIT_BODY="Updated country pages based on latest changes to companies.json" | |
fi | |
git add docs/countries/ docs/countries.md | |
git commit -m "$COMMIT_MSG" -m "$COMMIT_BODY" -m " | |
📊 Changes: | |
- Regenerated all country pages from companies.json | |
- Updated company listings and statistics | |
- Maintained consistent formatting | |
🤖 This commit was automatically generated by GitHub Actions" | |
- name: 🚀 Push Changes | |
if: steps.check-changes.outputs.has-changes == 'true' | |
run: | | |
echo "Pushing changes to repository..." | |
git push origin ${{ github.ref_name }} | |
- name: 📋 Summary | |
if: always() | |
run: | | |
echo "## 📊 Country Pages Update Summary" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
if [ "${{ steps.check-changes.outputs.has-changes }}" == "true" ]; then | |
echo "✅ **Status**: Country pages updated successfully" >> $GITHUB_STEP_SUMMARY | |
echo "📝 **Changes**: Committed and pushed to main branch" >> $GITHUB_STEP_SUMMARY | |
else | |
echo "ℹ️ **Status**: No changes needed" >> $GITHUB_STEP_SUMMARY | |
echo "📝 **Reason**: Country pages are already up to date" >> $GITHUB_STEP_SUMMARY | |
fi | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "### 📈 Repository Stats" >> $GITHUB_STEP_SUMMARY | |
# Get stats from JSON | |
TOTAL_COMPANIES=$(jq -r '.metadata.total_companies' data/companies.json) | |
TOTAL_COUNTRIES=$(jq -r '.metadata.countries' data/companies.json) | |
LAST_UPDATED=$(jq -r '.metadata.last_updated' data/companies.json) | |
echo "- **Total Companies**: $TOTAL_COMPANIES" >> $GITHUB_STEP_SUMMARY | |
echo "- **Countries Covered**: $TOTAL_COUNTRIES" >> $GITHUB_STEP_SUMMARY | |
echo "- **Data Last Updated**: $LAST_UPDATED" >> $GITHUB_STEP_SUMMARY | |
echo "- **Pages Generated**: $(find docs/countries/ -name "*.md" | wc -l)" >> $GITHUB_STEP_SUMMARY | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "### 🔗 Generated Pages" >> $GITHUB_STEP_SUMMARY | |
echo "All country pages have been updated and are available at:" >> $GITHUB_STEP_SUMMARY | |
echo "- [Browse All Countries](../docs/countries.md)" >> $GITHUB_STEP_SUMMARY | |
# List top 5 countries by company count | |
echo "" >> $GITHUB_STEP_SUMMARY | |
echo "### 🏆 Top Countries by Company Count" >> $GITHUB_STEP_SUMMARY | |
jq -r '.companies | to_entries | sort_by(.value | length) | reverse | limit(5; .[]) | "- **\(.key | ascii_upcase)**: \(.value | length) companies"' data/companies.json >> $GITHUB_STEP_SUMMARY | |
- name: 💬 Comment on PR | |
if: github.event_name == 'pull_request' && steps.check-changes.outputs.has-changes == 'true' | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const fs = require('fs'); | |
// Get stats | |
const data = JSON.parse(fs.readFileSync('data/companies.json', 'utf8')); | |
const totalCompanies = data.metadata.total_companies; | |
const totalCountries = data.metadata.countries; | |
const comment = `## 🤖 Country Pages Auto-Updated | |
Your changes to \`companies.json\` have been processed and the country pages have been automatically updated! | |
### 📊 Current Stats | |
- **Total Companies**: ${totalCompanies} | |
- **Countries Covered**: ${totalCountries} | |
- **Pages Updated**: All country pages regenerated | |
### 🔗 View Changes | |
The following files have been updated: | |
- All country pages in \`docs/countries/\` | |
- Main countries index at \`docs/countries.md\` | |
### ✅ What's Next | |
Your PR has been merged and the documentation is now up to date. Thank you for contributing! 🎉 | |
--- | |
*This comment was automatically generated by the Country Pages Update workflow.*`; | |
github.rest.issues.createComment({ | |
issue_number: context.issue.number, | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
body: comment | |
}); |