|
| 1 | +# Workflow for deploying static content to GitHub Pages |
| 2 | +name: Deploy static content to GitHub Pages |
| 3 | + |
| 4 | +on: |
| 5 | + # Trigger workflow on push to the main branch |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | + # Allow manual trigger of the workflow through the Actions tab |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +permissions: |
| 14 | + # Set required permissions for deployment |
| 15 | + contents: read |
| 16 | + pages: write |
| 17 | + id-token: write |
| 18 | + |
| 19 | +concurrency: |
| 20 | + # Allow only one deployment at a time, cancel in-progress deployments |
| 21 | + group: 'github-pages-deployment' |
| 22 | + cancel-in-progress: true |
| 23 | + |
| 24 | +jobs: |
| 25 | + deploy: |
| 26 | + # Define the target deployment environment |
| 27 | + environment: |
| 28 | + name: github-pages |
| 29 | + url: ${{ steps.deployment.outputs.page_url }} |
| 30 | + runs-on: ubuntu-latest |
| 31 | + |
| 32 | + steps: |
| 33 | + # Step 1: Check out the repository |
| 34 | + - name: Check out the code |
| 35 | + uses: actions/checkout@v4 |
| 36 | + with: |
| 37 | + fetch-depth: 1 |
| 38 | + |
| 39 | + # Step 2: Set up Node.js environment |
| 40 | + - name: Set up Node.js |
| 41 | + uses: actions/setup-node@v4 |
| 42 | + with: |
| 43 | + node-version: 20 |
| 44 | + cache: npm |
| 45 | + |
| 46 | + # Step 3: Install dependencies |
| 47 | + - name: Install project dependencies |
| 48 | + run: npm ci |
| 49 | + |
| 50 | + # Step 4: Build the project |
| 51 | + - name: Build the project |
| 52 | + run: npm run build |
| 53 | + |
| 54 | + # Step 5: Configure GitHub Pages |
| 55 | + - name: Configure GitHub Pages |
| 56 | + uses: actions/configure-pages@v4 |
| 57 | + |
| 58 | + # Step 6: Upload build artifacts |
| 59 | + - name: Upload build artifacts |
| 60 | + uses: actions/upload-pages-artifact@v3 |
| 61 | + with: |
| 62 | + path: ./dist |
| 63 | + |
| 64 | + # Step 7: Deploy to GitHub Pages |
| 65 | + - name: Deploy to GitHub Pages |
| 66 | + id: deployment |
| 67 | + uses: actions/deploy-pages@v4 |
0 commit comments