Add files via upload #50
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: Deploy Portfolio and Update Projects | |
| on: | |
| push: | |
| branches: | |
| - main | |
| schedule: | |
| # Run weekly on Sundays at 00:00 UTC | |
| - cron: '0 0 * * 0' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| update-projects: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Fetch pinned repositories | |
| id: fetch-repos | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| # Make scripts executable | |
| chmod +x .github/scripts/fetch-pinned-repos.sh | |
| chmod +x .github/scripts/download-thumbnails.sh | |
| # Fetch pinned repositories using GraphQL API | |
| # Use repository owner to make this workflow reusable | |
| .github/scripts/fetch-pinned-repos.sh "${{ github.repository_owner }}" projects.json | |
| echo "Projects updated successfully" | |
| cat projects.json | |
| - name: Download thumbnails | |
| run: | | |
| # Download thumbnails from Open Graph images | |
| .github/scripts/download-thumbnails.sh projects.json assets/img | |
| # Show downloaded thumbnails | |
| echo "Thumbnails in assets/img:" | |
| ls -lh assets/img/ || echo "No thumbnails directory yet" | |
| - name: Commit updated projects.json and thumbnails | |
| run: | | |
| git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
| git config --local user.name "github-actions[bot]" | |
| # Add all changes (projects.json and any new thumbnails) | |
| git add projects.json assets/img/ 2>/dev/null || git add projects.json | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit" | |
| else | |
| git commit -m "Update projects.json and thumbnails with pinned repositories" | |
| git push | |
| fi | |
| build-and-deploy-projects: | |
| needs: update-projects | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: main # Explicitly check out main branch to get the latest updates | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Create dist directory | |
| run: mkdir -p dist | |
| - name: Copy main site files | |
| run: | | |
| cp index.html dist/ | |
| cp projects.json dist/ | |
| cp -r assets dist/ | |
| - name: Read projects and build each | |
| run: | | |
| # Read projects from projects.json | |
| PROJECTS=$(cat projects.json | jq -r '.[].name') | |
| for PROJECT in $PROJECTS; do | |
| echo "Processing project: $PROJECT" | |
| # Check if repo exists | |
| if curl -s -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ | |
| "https://api.github.com/repos/brianwalkerdev/$PROJECT" | jq -e '.name' > /dev/null; then | |
| echo "Cloning $PROJECT..." | |
| git clone "https://${{ secrets.GITHUB_TOKEN }}@github.com/brianwalkerdev/$PROJECT.git" "/tmp/$PROJECT" || continue | |
| cd "/tmp/$PROJECT" | |
| # Check if it's a Node.js project | |
| if [ -f "package.json" ]; then | |
| echo "Building Node.js project: $PROJECT" | |
| npm install | |
| if [ $? -ne 0 ]; then | |
| echo "npm install failed for $PROJECT, skipping deployment for this project." | |
| cd "$GITHUB_WORKSPACE" | |
| continue | |
| fi | |
| npm run build || npm run build:prod | |
| if [ $? -ne 0 ]; then | |
| echo "Build failed for $PROJECT, skipping deployment for this project." | |
| cd "$GITHUB_WORKSPACE" | |
| continue | |
| fi | |
| # Look for common build output directories | |
| DEPLOYED=false | |
| for BUILD_DIR in dist build public; do | |
| if [ -d "$BUILD_DIR" ]; then | |
| mkdir -p "$GITHUB_WORKSPACE/dist/$PROJECT" | |
| cp -r "$BUILD_DIR"/* "$GITHUB_WORKSPACE/dist/$PROJECT/" || true | |
| DEPLOYED=true | |
| break | |
| fi | |
| done | |
| # If no standard build directory found, copy static site files as fallback | |
| if [ "$DEPLOYED" = false ]; then | |
| echo "No standard build directory found for $PROJECT, copying static files..." | |
| mkdir -p "$GITHUB_WORKSPACE/dist/$PROJECT" | |
| shopt -s nullglob | |
| # Copy root-level HTML files | |
| for file in *.html; do | |
| cp "$file" "$GITHUB_WORKSPACE/dist/$PROJECT/" || true | |
| done | |
| # Copy common directories (this will include CSS, JS, and asset files) | |
| for dir in css js images assets photos svgs; do | |
| if [ -d "$dir" ]; then | |
| cp -r "$dir" "$GITHUB_WORKSPACE/dist/$PROJECT/" || true | |
| fi | |
| done | |
| shopt -u nullglob | |
| fi | |
| else | |
| # For non-Node projects, copy only static site files (html, css, js, assets) | |
| mkdir -p "$GITHUB_WORKSPACE/dist/$PROJECT" | |
| shopt -s nullglob dotglob | |
| for ext in html css js; do | |
| for file in *.$ext; do | |
| cp "$file" "$GITHUB_WORKSPACE/dist/$PROJECT/" || true | |
| done | |
| done | |
| if [ -d "assets" ]; then | |
| cp -r assets "$GITHUB_WORKSPACE/dist/$PROJECT/" || true | |
| fi | |
| shopt -u nullglob dotglob | |
| fi | |
| cd "$GITHUB_WORKSPACE" | |
| else | |
| echo "Project $PROJECT not found or not accessible" | |
| fi | |
| done | |
| - name: Create .nojekyll file | |
| run: touch dist/.nojekyll | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: 'dist' | |
| deploy: | |
| needs: build-and-deploy-projects | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |