跳到主要内容

Using Action Plugins

Applicable Scenarios: When you need to call reusable Action plugins in a step to perform operations such as pulling code, setting up the language environment, caching dependencies, and uploading artifacts.

Prerequisites

  • Familiar with the usage of uses and with.

Quick Example

jobs:
build:
runs-on: [ubuntu-latest, x64, small]
steps:
- name: Checkout source code
uses: checkout

- name: Setup Node.js
uses: setup-node
with:
node-version: "20"

- run: npm ci
- run: npm test

Configuration Description

Three Ways to Reference

AtomGit Action supports three ways to reference Action plugins:

MethodSyntaxDescription
Official Pluginuses: action-name@refDirectly write the plugin name
Open Source Pluginuses: owner/repo/path@refPlugin in AtomGit public repository
Local Referenceuses: ./path/to/actionPlugin in the current repository

1. Official Plugin Reference

Directly write the plugin name:

steps:
- uses: checkout
- uses: setup-node
with:
node-version: "20"

2. Open Source Plugin Reference

Reference an Action in an open-source repository using the {owner}/{repo}/{path}@{ref} format:

steps:
- uses: checkout
- uses: docker/build-push-action@v6
with:
push: true
tags: example.com/demo/app:latest

3. Custom Plugin Reference (Relative Path in the Same Repository)

Reference a local Action in the current repository:

steps:
- uses: ./.gitcode/actions/my-custom-action

The local Action must have an action.yml metadata file in the corresponding path of the repository:

# Using Action Plugins
name: "My Custom Action"
description: "Do something custom"
inputs:
param1:
description: "Parameter 1"
required: false
default: "default-value"
outputs:
result:
description: "Action result"
runs:
using: 'node16'
main: 'dist/main.js'

Action Version Reference Methods

Reference MethodDescriptionRecommendation
@v4 (Tag)Use the major version tag, which can automatically get patch updatesRecommended
@v4.1.0 (Full Version)Use the exact version, stable behavior but no automatic updateHighest Security
@main (Branch)Use the latest commit in the branch, behavior may changeNot Recommended
@a1b2c3d (SHA)Use the exact commit SHA, behavior is completely determinedRecommended for Production

Passing Parameters with with

with is used to pass input parameters to the Action, and the parameter names must match the inputs defined in the Action's action.yml:

steps:
- uses: setup-node
with:
node-version: "20"
registry-url: "https://registry.npmjs.org"