🎓 A1Learner
🔍
0 of 50 lessons completed

GitHub Actions: setup-node and setup-python

actions/setup-node and actions/setup-python install a language version on the runner. They pin the exact version the code needs.

Pin Node 24

This step installs Node 24 on the runner.

- uses: actions/setup-node@v7
  with:
    node-version: '24'

Pin Python 3.13

This step installs Python 3.13 on the runner.

- uses: actions/setup-python@v7
  with:
    python-version: '3.13'

Install pytest

pytest is the Python test runner. Install it before running it.

- run: pip install pytest
- run: pytest test_app.py

Example

name: Setup versions

on: push

jobs:
  node-job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: '24'
      - run: node --version
      - run: npm test
  python-job:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-python@v7
        with:
          python-version: '3.13'
      - run: python --version
      - run: pip install pytest
      - run: pytest test_app.py

Key points

  • setup-node: the action that installs Node.js on the runner.
  • setup-python: the action that installs Python on the runner.
  • Pin the version with node-version or python-version.
  • The demo app uses Node 24 and Python 3.13.
  • Pinning stops a new language release from breaking the build.
  • A step that runs npm test must come after setup-node.
  • pip is the Python package installer.
  • The runner has no pytest preinstalled, so the workflow installs it first.
  • Setup actions give the runner the right language version before any command runs.

In this example, the workflow holds two jobs. The Node job checks out the repo, installs Node 24, prints the version, and runs the Node tests. The Python job checks out the repo, installs Python 3.13, prints the version, installs pytest, and runs the Python test. Both jobs pass.

Note

Node 24 is the long-term support release. Python 3.13 is the version pinned in this course.

Try it Yourself

Edit the code, then press Run.

Running is simulated · Rust Playground

Exercise

How does a workflow pin Node 24?