| name: Deploy to GitHub Pages | |
| on: | |
| push: | |
| branches: | |
| - main # This workflow will run on pushes to the 'main' branch. | |
| # Change this to your default branch if it's different (e.g., 'master'). | |
| permissions: | |
| contents: read # Allows the action to read your repository contents | |
| pages: write # Allows the action to deploy to GitHub Pages | |
| id-token: write # Required to authenticate with GitHub's OIDC provider | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 # Checks out your repository code | |
| with: | |
| fetch-depth: 1 # <--- Added this line for shallow clone | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' # Specify the Node.js version your project needs | |
| cache: 'npm' # Enable caching for npm dependencies | |
| - name: Install dependencies | |
| run: npm install # Installs your project's npm dependencies. | |
| - name: Build project | |
| run: npm run build -- --outfile=./dist/index.js && cp index.html ./dist/index.html # Runs your project's build script (e.g., Vite, esbuild) | |
| - name: Upload artifact for GitHub Pages | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| name: github-pages | |
| path: ./dist | |
| deploy: | |
| environment: | |
| name: github-pages # Specifies the deployment environment | |
| url: ${{ steps.deployment.outputs.page_url }} # Retrieves the deployed URL | |
| runs-on: ubuntu-latest | |
| needs: build # This job depends on the 'build' job completing successfully | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4.0.5 # Deploys the artifact to GitHub Pages | |