Navigation
Getting startedCreating a workflowBuilding code in a workflowRunning multiple jobs in parallelRunning jobs in sequence- Deploying to GitHub Pages (this task)
- Using other events to run workflows
- Outputs from steps and jobs
- Keeping dependencies up to date with Dependabot
- Matrices
- Workflow dispatch inputs and security verification
- 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.
To deploy to GitHub Pages from GitHub Actions, we first need to configure the repository.
- Go to the repository settings on https://github.com/[your-username]/gh-actions-workshop/settings/pages
- Under "Build and deployment" → "Source", select "GitHub Actions"
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 |
-
Create a new job called
deploy
that runs onubuntu-latest
-
In the steps, check out the code, install dependencies and build the project as before
-
To be able to deploy, we use
actions/configure-pages
,actions/upload-pages-artifact
andactions/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!