Skip to content

Latest commit

 

History

History
64 lines (50 loc) · 3.11 KB

README.md

File metadata and controls

64 lines (50 loc) · 3.11 KB

5 Deploying to GitHub Pages

Navigation
  1. Getting started
  2. Creating a workflow
  3. Building code in a workflow
  4. Running multiple jobs in parallel
  5. Running jobs in sequence
  6. Deploying to GitHub Pages (this task)
  7. Using other events to run workflows
  8. Outputs from steps and jobs
  9. Keeping dependencies up to date with Dependabot
  10. Matrices
  11. Workflow dispatch inputs and security verification
  12. Learn more about GitHub Actions

GitHub Pages is GitHub's built-in static site hosting. It's not very often used in production, but it's great for hosting things like documentation, blogs, or even your own website. Even though it's not used that often, it's still a great way to learn how to deploy to a cloud service.

5.1 Configuring GitHub Pages

To deploy to GitHub Pages from GitHub Actions, we first need to configure the repository.

  1. Go to the repository settings on https://github.com/[your-username]/gh-actions-workshop/settings/pages
  2. Under "Build and deployment" → "Source", select "GitHub Actions"

5.2 Creating a workflow that deploys to GitHub Pages

Now that we've configured GitHub Pages, we can create a workflow that deploys to it. Let's create a new workflow file called deploy.yml in the .github/workflows directory. The new workflow should be triggered on push to the main branch, as this is the only branch we know works.

We need to set a few permissions to be able to read the repository and deploy to GitHub Pages:

Permission Description
contents: read To read the repository contents
pages: write To deploy to GitHub Pages
id-token: write To verify the deployment originates from an appropriate source
  1. Create a new job called deploy that runs on ubuntu-latest

  2. In the steps, check out the code, install dependencies and build the project as before

  3. To be able to deploy, we use actions/configure-pages, actions/upload-pages-artifact and actions/deploy-pages:

    - name: Setup Pages
      uses: actions/configure-pages@v5
    - name: Upload artifact
      uses: actions/upload-pages-artifact@v3
      with:
        # Upload the `dist` folder, which was generated by `npm run build`
        path: "./dist"
    - name: Deploy to GitHub Pages
      id: deployment
      uses: actions/deploy-pages@v4

After running this workflow (on the main branch), you should be able to see the webpage on https://[your-username].github.io/gh-pages-workshop 😍 Now let's learn about other events in task 6!