Skip to content

Instantly share code, notes, and snippets.

@vnegi10
Created May 10, 2024 10:26
Show Gist options
  • Save vnegi10/a26291fee1005b794dd75a4ba8cb24da to your computer and use it in GitHub Desktop.
Save vnegi10/a26291fee1005b794dd75a4ba8cb24da to your computer and use it in GitHub Desktop.
name: Deploy to GitHub pages
on:
  push:
    branches: [ main ]
  pull_request:
    branches: ["main"]
  schedule:
    - cron: "30 */2 * * *"
jobs:
  build:
    runs-on: ubuntu-latest
    env:
      CG_PRO_KEY: ${{ secrets.CG_PRO_KEY }}
    permissions:
      contents: write
      deployments: write
      id-token: write
      packages: read
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-node@v4
        with:
          node-version: 20
          cache: 'yarn'
          cache-dependency-path: yarn.lock
      - run: yarn --frozen-lockfile
      # This step will generate the build data in dist folder
      - name: Build website
        run: yarn build
      - name: Upload Pages artifact
        uses: actions/upload-pages-artifact@v3
        with:
          path: "dist/"
  deploy:
  # Add a dependency to the build job
    needs: build
    # Grant GITHUB_TOKEN the permissions required to make a Pages deployment
    permissions:
      pages: write      # to deploy to Pages
      id-token: write   # to verify the deployment originates from an appropriate source
    # Deploy to the github-pages environment
    environment:
      name: github-pages
      url: ${{ steps.deployment.outputs.page_url }}
    # Specify runner + deployment step
    runs-on: ubuntu-latest
    steps:
      - name: Deploy to GitHub Pages
        id: deployment
        uses: actions/deploy-pages@v4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment