Check for Template Updates #1
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: Check for Template Updates | |
| # This workflow checks for updates from the template repository | |
| # and creates a PR when updates are available | |
| # | |
| # To enable: Uncomment the schedule trigger below | |
| # To disable: Keep the schedule commented out or delete this file | |
| on: | |
| # Uncomment to enable weekly checks: | |
| # schedule: | |
| # - cron: '0 0 * * 0' # Weekly on Sunday at midnight UTC | |
| # Manual trigger is always available | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: 'Force update even if no changes' | |
| required: false | |
| default: 'false' | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| jobs: | |
| check-update: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| update_available: ${{ steps.check.outputs.update_available }} | |
| current_version: ${{ steps.check.outputs.current_version }} | |
| latest_version: ${{ steps.check.outputs.latest_version }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Check for updates | |
| id: check | |
| run: | | |
| chmod +x update-design.sh | |
| if [ "${{ github.event.inputs.force }}" = "true" ]; then | |
| ./update-design.sh --check-only --non-interactive --force || true | |
| else | |
| ./update-design.sh --check-only --non-interactive || true | |
| fi | |
| apply-update: | |
| needs: check-update | |
| if: needs.check-update.outputs.update_available == 'true' || github.event.inputs.force == 'true' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Configure Git | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| - name: Create update branch | |
| run: | | |
| BRANCH_NAME="template-update-$(date +%Y%m%d-%H%M%S)" | |
| git checkout -b "$BRANCH_NAME" | |
| echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_ENV | |
| - name: Run update script | |
| id: update | |
| run: | | |
| chmod +x update-design.sh | |
| if [ "${{ github.event.inputs.force }}" = "true" ]; then | |
| ./update-design.sh --non-interactive --force | |
| else | |
| ./update-design.sh --non-interactive | |
| fi | |
| - name: Commit changes | |
| id: commit | |
| run: | | |
| git add -A | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| echo "has_changes=false" >> $GITHUB_OUTPUT | |
| else | |
| CURRENT="${{ needs.check-update.outputs.current_version }}" | |
| LATEST="${{ needs.check-update.outputs.latest_version }}" | |
| git commit -m "Update design from template v$CURRENT → v$LATEST" \ | |
| -m "Automated update from mechanicpanic/academic-website" \ | |
| -m "" \ | |
| -m "🤖 Generated by GitHub Actions" | |
| git push origin "$BRANCH_NAME" | |
| echo "has_changes=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check for conflicts | |
| id: conflicts | |
| if: steps.commit.outputs.has_changes == 'true' | |
| run: | | |
| # Check if user has modified design files | |
| MODIFIED="" | |
| for file in _layouts _sass assets/css/main.scss _plugins; do | |
| if [ -e "$file" ]; then | |
| if git log --all --oneline -- "$file" 2>/dev/null | \ | |
| grep -v "Update design" | \ | |
| grep -v "template update" | \ | |
| grep -v "github-actions" > /dev/null; then | |
| MODIFIED="$MODIFIED $file" | |
| fi | |
| fi | |
| done | |
| if [ -n "$MODIFIED" ]; then | |
| echo "has_conflicts=true" >> $GITHUB_OUTPUT | |
| echo "modified_files=$MODIFIED" >> $GITHUB_OUTPUT | |
| else | |
| echo "has_conflicts=false" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Get changelog | |
| id: changelog | |
| if: steps.commit.outputs.has_changes == 'true' | |
| run: | | |
| LATEST="${{ needs.check-update.outputs.latest_version }}" | |
| CHANGELOG=$(curl -s "https://raw.githubusercontent.com/mechanicpanic/academic-website/master/CHANGELOG.md" | \ | |
| sed -n "/## \[$LATEST\]/,/## \[/p" | head -n -1) | |
| # Save to file for PR body | |
| echo "$CHANGELOG" > /tmp/changelog.md | |
| - name: Create Pull Request | |
| if: steps.commit.outputs.has_changes == 'true' | |
| uses: peter-evans/create-pull-request@v5 | |
| id: pr | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| branch: ${{ env.BRANCH_NAME }} | |
| title: "🎨 Template Update: v${{ needs.check-update.outputs.current_version }} → v${{ needs.check-update.outputs.latest_version }}" | |
| body: | | |
| ## 🎨 Template Design Update Available | |
| A new version of the academic website template is available! | |
| **Current Version:** `${{ needs.check-update.outputs.current_version }}` | |
| **New Version:** `${{ needs.check-update.outputs.latest_version }}` | |
| ### 📋 What's New | |
| ${{ steps.changelog.outputs.content }} | |
| ### 🔍 Conflict Check | |
| **Safe to auto-merge:** ${{ steps.conflicts.outputs.has_conflicts == 'false' && '✅ Yes' || '⚠️ No - Review needed' }} | |
| ${{ steps.conflicts.outputs.has_conflicts == 'true' && format('**Modified files:** {0}', steps.conflicts.outputs.modified_files) || '' }} | |
| ### 🚀 What to Do | |
| ${{ steps.conflicts.outputs.has_conflicts == 'false' && ' | |
| This PR can be safely merged! No conflicts detected with your customizations. | |
| **To merge:** | |
| 1. Review the changes below | |
| 2. Click "Merge pull request" | |
| 3. Your site will be updated automatically | |
| ' || ' | |
| **⚠️ Manual review recommended** | |
| You have customized design files that may conflict with this update: | |
| ' }} | |
| ${{ steps.conflicts.outputs.modified_files }} | |
| ${{ steps.conflicts.outputs.has_conflicts == 'true' && ' | |
| **Recommended steps:** | |
| 1. Review the changes carefully | |
| 2. Test locally: `git fetch && git checkout ' || '' }}${{ env.BRANCH_NAME }}${{ steps.conflicts.outputs.has_conflicts == 'true' && ' && bundle exec jekyll serve` | |
| 3. Merge conflicts if needed | |
| 4. Merge when ready | |
| ' || '' }} | |
| ### 📚 Resources | |
| - [Template Repository](https://github.com/mechanicpanic/academic-website) | |
| - [Full Changelog](https://github.com/mechanicpanic/academic-website/blob/master/CHANGELOG.md) | |
| - [Update Script Documentation](https://github.com/mechanicpanic/academic-website#updating-the-template) | |
| --- | |
| *This PR was created automatically by the template-update workflow.* | |
| *Your content in `vault/` and `_config.yml` has been preserved.* | |
| 🤖 Generated by [GitHub Actions](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) | |
| labels: | | |
| template-update | |
| automated | |
| draft: false | |
| - name: Enable auto-merge if safe | |
| if: steps.commit.outputs.has_changes == 'true' && steps.conflicts.outputs.has_conflicts == 'false' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Enable auto-merge with squash | |
| gh pr merge --auto --squash --delete-branch \ | |
| --subject "Update design to v${{ needs.check-update.outputs.latest_version }}" \ | |
| ${{ steps.pr.outputs.pull-request-number }} | |
| echo "✅ Auto-merge enabled for PR #${{ steps.pr.outputs.pull-request-number }}" | |
| echo "The PR will merge automatically once checks pass" | |
| - name: Comment on PR | |
| if: steps.commit.outputs.has_changes == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| if [ "${{ steps.conflicts.outputs.has_conflicts }}" = "false" ]; then | |
| COMMENT="✅ **Auto-merge enabled!** | |
| This PR will merge automatically because: | |
| - No conflicts detected with your customizations | |
| - All checks passing | |
| - Only template design files are updated | |
| Your content and configuration remain untouched." | |
| else | |
| COMMENT="⚠️ **Manual review needed** | |
| This PR requires your attention because you've customized: | |
| ${{ steps.conflicts.outputs.modified_files }} | |
| Please review the changes and merge when ready." | |
| fi | |
| gh pr comment ${{ steps.pr.outputs.pull-request-number }} --body "$COMMENT" | |
| - name: Summary | |
| if: steps.commit.outputs.has_changes == 'true' | |
| run: | | |
| echo "## 🎨 Template Update Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "**PR Created:** #${{ steps.pr.outputs.pull-request-number }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Version:** ${{ needs.check-update.outputs.current_version }} → ${{ needs.check-update.outputs.latest_version }}" >> $GITHUB_STEP_SUMMARY | |
| echo "**Auto-merge:** ${{ steps.conflicts.outputs.has_conflicts == 'false' && 'Enabled ✅' || 'Disabled ⚠️' }}" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "[View Pull Request](${{ steps.pr.outputs.pull-request-url }})" >> $GITHUB_STEP_SUMMARY |