Add the Deploy Workflow

Your repository on GitHub now holds check.yml, and the issue “Put the store’s site live” is still open. Closing it takes a second workflow, one that builds the site and publishes it whenever main changes, so that nobody has to upload files by hand ever again, not even at six in the morning on Christmas Eve.

In this lesson, you’ll read the check workflow step by step, then add Vite’s deploy workflow on a branch and compare the two. You’ll open a pull request for it, read why the check fails, and then fix the problem. Start with the workflow you already have, because it shows how every workflow file is built.

Read the Check Step by Step

Before you add a workflow that publishes the store’s site, it helps to know exactly what the one already in your repository does. Workflow files are written in YAML, a format for settings where each line is a name: value pair, the indentation shows what belongs to what, and a - starts an item in a list. Open .github/workflows/check.yml in VS Code. Here’s the whole file:

Language: YAML
# The check every pull request into main runs: the same lint, formatting and build as
# npm run lint, npx prettier --check . and npm run build on your computer. Protecting main
# can require it to pass before a pull request merges. It never runs on a push to main.
name: Check

on:
  pull_request:
    branches: [main]

permissions:
  contents: read

jobs:
  check:
    runs-on: ubuntu-latest
    steps:
      # Each action is pinned to one exact commit, like a lockfile pins a package.
      - name: Checkout
        uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
      - name: Set up Node
        uses: actions/setup-node@949feb2413d6458794dcd2491c4babbbce0c15c1 # v7
        with:
          node-version: lts/*
          cache: npm
      - name: Install dependencies
        run: npm ci
      - name: Lint
        run: npm run lint
      - name: Check formatting
        run: npx prettier --check .
      - name: Build
        run: npm run build

Read it from the top down, the same way GitHub does. The lines that start with # are comments for people, and GitHub skips them:

  • name: Check is the workflow’s name. GitHub shows it on the Actions tab and in the list of checks on a pull request, so it’s how you’ll recognize this workflow there.

  • on: says which event starts the workflow. pull_request: starts it when a pull request is opened or reopened, and again each time you push new commits to its branch.

The line under it, branches: [main], is a filter on the branch the pull request would merge into, so only pull requests into main run the check. It doesn’t list push:, so a push straight to main, including the one a merge makes, never starts the check.

  • permissions: sets what the run’s automatic GitHub token, GITHUB_TOKEN, may do with your repository. contents: read lets that token read the repository’s files, but not push changes back to it.

  • jobs: holds the work. This file has one job, called check, and runs-on: ubuntu-latest gives it a fresh Linux virtual machine on GitHub’s servers. Each job gets a new one, with many common tools already installed but without your project’s files or packages. GitHub throws the machine away when the job ends.

  • steps: run in order, and each - name: is a step that you’ll see by that name on GitHub. A step either runs a command with run: or uses an action with uses:. An action is a ready-made step that someone published on GitHub.

The first two steps are actions. actions/checkout copies your repository onto that fresh machine, and actions/setup-node installs Node.js, here the current long-term support version (lts/*).

The last four steps are commands you already know from your laptop. npm ci installs exactly what the lockfile lists. Then the check lints, checks the formatting, and builds. The run stops at the first step that fails.

Look at the long string after each @. An action is code from someone else’s repository. @v7 would mean “whatever its owner calls version 7 today,” and the owner can move that name to different code. A commit hash can’t change, so pinning to it works like your lockfile does for packages, a habit that also protects you from supply chain attacks. The # v7 comment keeps the version readable for you.

Add the Deploy Workflow

The check proves that the code in a pull request builds, but it never publishes anything, and it doesn’t even run when main changes. Vite’s guide to deploying on GitHub Pages gives a workflow that runs when main changes and publishes the site. Start a branch for it from your up-to-date main:

Language: Shell
$ git switch -c deploy-to-pages
Switched to a new branch 'deploy-to-pages'

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.