🎓 A1Learner
🔍
0 of 50 lessons completed

GitHub Actions: Deploy a Node App

A deploy job publishes the built app after the tests pass. It runs only when the test job succeeds, because it needs the test job.

The deploy job waits for tests

Needs links the two jobs. The deploy job starts only when the test job passes.

deploy:
  needs: test

Build the app for deploy

The build step writes the site files into the dist folder.

- run: npm run build

Publish the built site as an artifact

The artifact holds the built site, so it is kept as the deployment output.

- uses: actions/upload-artifact@v7
  with:
    name: demo-site
    path: dist

Example

name: Deploy a Node app
on:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: npm test
  deploy:
    runs-on: ubuntu-latest
    needs: test
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: npm run build
      - uses: actions/upload-artifact@v7
        with:
          name: demo-site
          path: dist
      - run: echo "Deployed demo-site."

Key points

  • Use needs to make the deploy job wait for the test job.
  • A failed test job skips the deploy job, so a broken app never ships.
  • The deploy job builds the app again, from the same code the tests checked.
  • An artifact is a file the workflow saves, so the built site can be kept as the deploy output.
  • The demo app has no server, so the deploy step publishes the built site artifact.
  • The built site is the deploy output, not a running server.

In this example, the test job checks out the code and sets up Node 24, then runs the tests. The deploy job needs the test job, so it starts only when the tests pass. It checks out the code again, sets up Node 24, and builds the app. It uploads the dist folder as the demo-site artifact, which is the deployment output. The demo has no server, so nothing is started.

Note

A real app with a server needs a hosting account for the deploy step. The demo keeps the deploy inside GitHub.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

What happens to the deploy job if the test job fails?