name: BharatDefence Auto-Publish on: schedule: - cron: '30 0 * * *' - cron: '30 6 * * *' - cron: '30 12 * * *' - cron: '30 17 * * *' workflow_dispatch: permissions: contents: write jobs: autopost: name: Generate and Publish Articles runs-on: ubuntu-latest concurrency: group: bharatdefence-autopost cancel-in-progress: false 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: '20' - name: Install dependencies working-directory: automation run: npm install - name: Create required folders run: mkdir -p site/articles - name: Run AI article engine working-directory: automation env: GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} UNSPLASH_KEY: ${{ secrets.UNSPLASH_KEY }} NEWS_API_KEY: ${{ secrets.NEWS_API_KEY }} SITE_DOMAIN: ${{ secrets.SITE_DOMAIN }} run: node autopost.js - name: Show generated files run: | echo "=== Articles folder ===" ls -la site/articles/ || echo "No articles folder" echo "=== index.json ===" cat site/articles/index.json 2>/dev/null | head -c 500 || echo "NO index.json found!" - name: Commit new articles run: | git config --local user.email "autobot@bharatdefence.site" git config --local user.name "BharatDefence AutoBot" git add -A site/articles/ git add -A site/sitemap.xml git diff --staged --quiet && echo "Nothing to commit" || git commit -m "Auto-publish $(date +'%d %b %Y %H:%M IST')" - name: Pull latest changes before push run: | git pull --rebase origin main || { echo "Rebase failed, trying merge strategy..." git rebase --abort 2>/dev/null || true git pull --no-rebase --strategy=recursive -X ours origin main } - name: Push to GitHub run: | git push origin main echo "Push complete" env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - name: Ping Google run: | curl -s "https://www.google.com/ping?sitemap=https://bharatdefence.site/sitemap.xml" || true echo "Done"