build: use explicit publish #3
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 content and deploy | |
| on: | |
| workflow_dispatch: | |
| repository_dispatch: | |
| types: [notebook-updated] | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: true | |
| jobs: | |
| update_and_deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Clone this repo | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Clone notes repo | |
| uses: actions/[email protected] | |
| with: | |
| repository: "mpicard/notes" | |
| ref: main | |
| token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
| path: notes | |
| - name: Delete everything in content/ except index.md | |
| run: | | |
| mv content/index.md . || touch index.md | |
| rm -rf content | |
| mkdir content | |
| mv index.md content/ | |
| - name: Copy over media and files | |
| run: | | |
| cd notes | |
| echo "----- Copying over Images folder" | |
| cp -vr Images ../content/ || echo "Images folder not found, skipping" | |
| echo -e "\n----- Copying over Analysis folder" | |
| cp -vr Analysis ../content/ || echo "Analysis folder not found, skipping" | |
| echo -e "\n----- Copying over Reflection folder" | |
| cp -vr Reflection ../content/ || echo "Reflection folder not found, skipping" | |
| echo -e "\n----- Copying over Technique folder" | |
| cp -vr Technique ../content/ || echo "Technique folder not found, skipping" | |
| echo -e "\n----- Copying over Tracks folder" | |
| cp -vr Tracks ../content/ || echo "Tracks folder not found, skipping" | |
| echo -e "\n----- Copying over Markdown files from root" | |
| cp -v *.md ../content/ 2>/dev/null || echo "No root markdown files found" | |
| # Exclude specific files that are in ignorePatterns | |
| cd ../content | |
| rm -f "Session Tracker.md" "_Track_Kanban_.md" "Accountability Log.md" 2>/dev/null || true | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 22 | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build Quartz | |
| run: npx quartz build | |
| - name: Setup Git config (user and email), necessary for commits | |
| if: github.event_name != 'push' | |
| run: | | |
| git config --global user.name "GitHub Actions" | |
| git config --global user.email "[email protected]" | |
| - name: Commit and push content changes (only if triggered by notebook/manual) | |
| if: github.event_name != 'push' | |
| run: | | |
| git add content/ | |
| if ! git diff --staged --quiet; then | |
| git commit -m "Update content from notebook" || true | |
| git push || true | |
| else | |
| echo "No content changes to commit" | |
| fi | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v4 | |
| with: | |
| path: public | |
| name: github-pages | |
| - name: Cancel stuck deployments | |
| run: | | |
| echo "Checking for in-progress deployments..." | |
| DEPLOYMENTS=$(curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/${{ github.repository }}/pages/deployments" | \ | |
| jq -r '.[] | select(.status == "in_progress") | .id' || echo "") | |
| if [ -n "$DEPLOYMENTS" ]; then | |
| echo "Found in-progress deployments: $DEPLOYMENTS" | |
| for DEPLOY_ID in $DEPLOYMENTS; do | |
| echo "Cancelling deployment $DEPLOY_ID..." | |
| curl -s -X POST \ | |
| -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "Accept: application/vnd.github.v3+json" \ | |
| "https://api.github.com/repos/${{ github.repository }}/pages/deployments/$DEPLOY_ID/cancel" || true | |
| done | |
| echo "Waiting 10 seconds for cancellations to process..." | |
| sleep 10 | |
| else | |
| echo "No in-progress deployments found" | |
| fi | |
| - name: Wait before deploying | |
| run: sleep 30 | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 | |
| continue-on-error: true | |
| - name: Retry deployment if needed | |
| if: failure() | |
| run: | | |
| echo "First attempt failed, waiting 60 seconds and retrying..." | |
| sleep 60 | |
| - name: Deploy to GitHub Pages (retry) | |
| if: failure() | |
| id: deployment_retry | |
| uses: actions/deploy-pages@v4 | |