Using Built-in Actions
1. Checking Out Code
| Property | Description | Default |
|---|---|---|
| uses | The action to use for checking out code | actions/checkout@v4 |
| with.token | Personal access token for private repositories | ${{ secrets.GITHUB_TOKEN }} |
| with.repository | Repository to check out (optional) | Current repository |
| with.ref | Git ref to check out (branch, tag, or commit) | Current branch |
| with.path | Directory to check out code into | . |
Example: Checkout specific branch
steps:
- name: Checkout feature branch
uses: actions/checkout@v4
with:
ref: feature-branch
Example: Checkout with custom path
steps:
- name: Checkout to custom directory
uses: actions/checkout@v4
with:
path: ./my-project
2. Setting Up Node.js
| Option | Values | Notes |
|---|---|---|
| uses | actions/setup-node@v4 |
Latest stable version of the Node.js setup action |
| with.node-version | 20 |
Version of Node.js to set up (LTS version) |
| with.cache | npm |
Cache dependency files (e.g., package-lock.json) to speed up builds |
Example: Setting up Node.js with caching
name: Setup Node.js
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
- run: npm ci
Note: The
actions/setup-node action automatically configures the Node.js environment and installs the specified version.
3. Setting Up Python
| Option | Values | Notes |
|---|---|---|
| uses | actions/setup-python@v5 |
Latest stable version as of 2026 |
| with.python-version | 3.12 |
Target Python version |
| with.cache | pip |
Enable dependency caching |
Example: Setting up Python with pip caching
name: Python CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: pip
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
Note: The
actions/setup-python action supports Python versions 3.6 through 3.12.
4. Setting Up Java
| Option | Values | Notes |
|---|---|---|
| uses | actions/setup-java@v4 |
Version of the action to use |
| with.java-version | '17', '21' |
Java version to set up |
| with.distribution | 'temurin', 'zulu' |
Java distribution to use |
| with.cache | 'maven', 'gradle' |
Build tool to cache dependencies for |
Example: Setting up Java 17 with Maven caching
name: Java CI
on: [push]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn clean package
Note: The
actions/setup-java action automatically configures the Java environment and sets up the necessary environment variables for running Java applications.5. Setting Up Go
| Property | Value | Description |
|---|---|---|
| uses | actions/setup-go@v5 |
GitHub Action to set up the Go environment |
| with.go-version | '1.23' |
Version of Go to install (latest stable as of 2026) |
| with.go-version-file | go.mod |
File to read Go version from (e.g. go.mod) |
| with.check-latest | true |
Check if the latest version is available |
| with.cache | true |
Enable caching of Go modules and binaries |
Example: Setting up Go in a workflow
name: Go CI
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: true
- name: Build
run: go build -v ./...
Note: The
actions/setup-go@v5 action supports Go versions 1.20 and above. For older versions, use v4.
6. Setting Up .NET
| Property | Value | Description |
|---|---|---|
| uses | actions/setup-dotnet@v4 |
GitHub Action to set up .NET environment |
| with.version | 8.0.x |
Version of .NET to install (latest LTS) |
| with.include-prerelease | false |
Whether to include pre-release versions |
Example: Setting up .NET Core 8.0
name: .NET Build
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore
Note: The
actions/setup-dotnet@v4 action supports .NET 8, 7, and 6. LTS versions are recommended for production use.
7. Setting Up Ruby
| Option | Values | Notes |
|---|---|---|
| uses | ruby/setup-ruby@v1 |
GitHub Action for setting up Ruby environment |
| ruby-version | 3.1 |
Version of Ruby to install (default: latest stable) |
| bundler-cache | true |
Enable caching of gems using Bundler |
Example: Setting up Ruby with Bundler caching
name: Ruby CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.1
bundler-cache: true
- name: Run tests
run: bundle exec rspec
Note: The
ruby/setup-ruby action supports multiple Ruby versions including 3.1, 3.0, and 2.7.
8. Caching Dependencies
Example: Caching npm dependencies
steps:
- uses: actions/checkout@v4
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-npm-
| Option | Values | Description |
|---|---|---|
| path | ~/.npm |
Directory to cache or restore |
| key | ${{ runner.os }}-npm-${{ hashFiles('**/package-lock.json') }} |
Unique identifier for cache |
| restore-keys | ${{ runner.os }}-npm- |
Alternative keys to try if primary key doesn't match |
Note: The
hashFiles function ensures cache is invalidated when dependencies change.
Warning: Cache size is limited to 10GB per workflow. Avoid caching large directories.
Example: Caching Gradle dependencies
steps:
- uses: actions/checkout@v4
- name: Cache Gradle
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
9. Uploading Artifacts
| Property | Description | Default |
|---|---|---|
| name | Name of the artifact to upload | None |
| path | Path to the file or directory to upload | None |
| if-no-files-found | Behavior when no files are found | error |
| retention-days | Number of days to retain the artifact | 90 |
Example: Upload a build artifact
name: Build and Upload Artifact
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build project
run: |
npm install
npm run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: build-output
path: dist/
Note: Artifacts are stored for up to 90 days by default. You can configure retention using the
retention-days parameter.
Warning: Large artifacts can increase storage costs and slow down workflows. Consider compressing or archiving large files before uploading.
10. Downloading Artifacts
| Property | Description | Default |
|---|---|---|
| name | Name of the artifact to download | None |
| path | Local path to save the artifact | None |
| if-no-files-found | Behavior when no files are found | error |
Example: Downloading a Single Artifact
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: my-artifact
path: ./downloads
Example: Download All Artifacts
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
Note: Artifacts must be uploaded using
actions/upload-artifact before they can be downloaded.
11. Using GitHub Script
| Property | Description | Example |
|---|---|---|
| uses | The action to use, in the format github/script@v6 |
uses: github/script@v6 |
| with.script | The script to run, as a string or multiline string | |
| with.args | Arguments to pass to the script (optional) | with: args: --name "John" |
Example: Basic Script Usage
name: Run Script
on: [push]
jobs:
run-script:
runs-on: ubuntu-latest
steps:
- uses: github/script@v6
with:
script: |
echo "Hello from GitHub Script!"
Example: Using Context Variables
name: Use Context
on: [push]
jobs:
use-context:
runs-on: ubuntu-latest
steps:
- uses: github/script@v6
with:
script: |
echo "Repository: ${{ github.repository }}"
echo "Event: ${{ github.event_name }}"
Note: The
github/script action runs in a Node.js environment with access to the GitHub Actions context and can execute any valid JavaScript or shell commands.
12. Setting Up Docker Buildx
GitHub Actions provides built-in support for setting up Docker Buildx, which enables multi-platform builds and improved performance. The docker/setup-buildx-action is used to configure Buildx.
| Input | Description | Default |
|---|---|---|
| version | Docker Buildx version to install | v0.12.1 |
| install | Whether to install Buildx | true |
| driver | Buildx driver to use | docker-container |
| driver-opts | Driver-specific options | |
Example: Setting up Docker Buildx
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.12.1
driver: docker-container
Note: Ensure that the
docker/setup-buildx-action is used in a step before any build steps that require Buildx.
Warning: The
docker/setup-buildx-action requires Docker to be installed on the runner. If using a self-hosted runner, ensure Docker is pre-installed.