|
| 1 | +name: Deploy Frontend to GitHub Pages |
| 2 | + |
| 3 | +on: |
| 4 | + # This workflow runs on every push to the 'main' branch, |
| 5 | + # but is scoped to only run if files in the 'client/' directory change. |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + paths: |
| 10 | + - 'client/**' |
| 11 | + |
| 12 | + # Allows manual triggering from the Actions tab |
| 13 | + workflow_dispatch: |
| 14 | + |
| 15 | +# Grant necessary permissions for the GitHub Pages actions |
| 16 | +permissions: |
| 17 | + # CRITICAL: Needs 'contents: write' to create and push to the gh-pages branch. |
| 18 | + contents: write |
| 19 | + pages: write # Added for compatibility with actions/deploy-pages if you ever switch back |
| 20 | + |
| 21 | +# Ensure only one deployment runs at a time |
| 22 | +concurrency: |
| 23 | + group: "pages-deployment" # Changed group name for clarity |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +jobs: |
| 27 | + build_and_deploy: # Renamed job for clarity |
| 28 | + runs-on: ubuntu-latest |
| 29 | + steps: |
| 30 | + - name: Checkout repository |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Set up Node.js |
| 34 | + uses: actions/setup-node@v4 |
| 35 | + with: |
| 36 | + node-version: '20' |
| 37 | + cache: 'npm' # Use npm caching for faster install times |
| 38 | + cache-dependency-path: 'client/package-lock.json' # Cache based on client lock file |
| 39 | + |
| 40 | + # --- React Build Steps --- |
| 41 | + |
| 42 | + - name: Install dependencies in client/ |
| 43 | + run: npm install |
| 44 | + working-directory: ./client |
| 45 | + |
| 46 | + - name: Build React application (fix base path for GitHub Pages) |
| 47 | + # CRITICAL FIX: The --base flag ensures asset paths (like main.jsx) are correct |
| 48 | + # for the subdirectory URL: https://techquanta.github.io/github-avatar-frame-api/ |
| 49 | + run: npm run build -- --base=/github-avatar-frame-api/ |
| 50 | + working-directory: ./client |
| 51 | + env: |
| 52 | + # CI: true prevents warnings from being treated as errors |
| 53 | + CI: true |
| 54 | + |
| 55 | + # --- GitHub Pages Deployment Steps (using gh-pages branch) --- |
| 56 | + |
| 57 | + - name: Deploy to gh-pages branch |
| 58 | + uses: peaceiris/actions-gh-pages@v4 |
| 59 | + with: |
| 60 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 61 | + publish_dir: ./client/dist |
| 62 | + publish_branch: gh-pages |
0 commit comments