百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
A

action

> 编程语言
开源

跨平台 GitHub 动作

194 stars0 点赞2 次浏览
访问官网GitHub

工具介绍

跨平台 GitHub 动作

Cross-Platform GitHub Action

This project provides a GitHub action for running GitHub Actions workflows on multiple platforms, including platforms that GitHub Actions doesn't currently natively support.

[!IMPORTANT] This readme documents the master branch, which may describe features and operating system versions that have not been released yet. For the documentation matching the latest release, see the readme for the latest release.

Features

Some of the features that this action supports include:

  • Multiple operating systems with one single action
  • Multiple versions of each operating system
  • Non-x86_64 architectures
  • Allows to use default shell or Bash shell
  • Low boot overhead
  • Fast execution
  • Using the action in multiple steps in the same job

Usage

Minimal Example

Here's a sample workflow file which will run the given commands on FreeBSD 15.1.

yaml
name: CI

on: [push]

jobs:
  test:
    runs-on: ubuntu-latest
    defaults:
      run:
        shell: cpa.sh {0}

    steps:
      - uses: actions/checkout@v6

      - name: Start VM
        uses: cross-platform-actions/[email protected]
        with:
          operating_system: freebsd
          version: '15.1'

      - name: Test
        run: |
          uname -a
          echo $SHELL
          pwd
          ls -lah
          whoami
          env | sort

Full Example

Here's a sample workflow file which will set up a matrix resulting in nine jobs. One which will run on FreeBSD 15.1, one which runs OpenBSD 7.9, one which runs NetBSD 11.0, one which runs OpenBSD 7.9 on ARM64, one which runs NetBSD 11.0 on ARM64, one which runs DragonFly BSD 6.4.2, one which runs MidnightBSD 4.0.4, one which runs Haiku R1/beta6 and one which runs OmniOS r151056.

…

Different platforms need to run on different runners, so see the Runners section below.

Helper Script

When the action starts the VM, the cpa.sh helper is added to the runner's PATH and can be used in subsequent steps. It runs commands inside the VM and can also synchronize files or reboot the VM:

cpa.sh FILE [POST_FLAGS...]       # Run FILE inside the VM
cpa.sh --sync-files [DIRECTION]   # Synchronize files between the runner and the VM
cpa.sh --reboot                   # Reboot the VM and wait until it's reachable again

When FILE is given (typically via shell: cpa.sh {0}), files are synchronized automatically: runner-to-vm before the file is executed and vm-to-runner after. Pass --sync-files DIRECTION as a POST_FLAG to change this. DIRECTION accepts:

  • both (default) — sync runner-to-vm before and vm-to-runner after
  • none — skip syncing entirely
  • runner-to-vm — only sync runner-to-vm before the file runs
  • vm-to-runner — only sync vm-to-runner after the file runs

--reboot may also be given as a POST_FLAG to reboot the VM after the file has run (and after the post-sync, if any).

--environment-variables NAME1 NAME2 ... may be given as a POST_FLAG to forward additional environment variables to the VM for that step, on top of the ones declared via the action's environment_variables input. List the names separated by spaces and do not quote them (GitHub Actions splits the shell line on spaces without honoring quotes). The named variables are read from the step's environment (set them with env:), so they don't need to be listed on the Start VM step.

yaml
- name: Run a command inside the VM
  shell: cpa.sh {0}
  run: uname -a

- name: Run a command without syncing files
  shell: cpa.sh {0} --sync-files none
  run: uname -a

- name: Run a command and reboot afterwards
  shell: cpa.sh {0} --reboot
  run: sysctl -w some.setting=1

- name: Run a command with extra environment variables
  shell: cpa.sh {0} --environment-variables MY_ENV1 MY_ENV2
  env:
    MY_ENV1: value1
    MY_ENV2: value2
  run: echo "$MY_ENV1 $MY_ENV2"

Use the standalone forms when you don't need to run a command. In standalone mode --sync-files defaults to both and runs the sync as a one-shot:

yaml
- name: Sync files from the runner to the VM
  run: cpa.sh --sync-files runner-to-vm

- name: Reboot the VM
  run: cpa.sh --reboot

Inputs

This section lists the available inputs for the action.

Input Required Default Value Type Description
run ❌ "" string Deprecated. Runs command-line programs using the operating system's shell. This will be executed inside the virtual machine. Prefer the cpa.sh custom shell (shell: cpa.sh {0}) in subsequent steps instead.
operating_system ✅ ❌ string The type of operating system to run the job on. See Supported Platforms.
architecture ❌ x86-64 string The architecture of the operating system. See Supported Platforms.
version ✅ ❌ string The version of the operating system to use. See Supported Platforms.
shell ❌ default string The shell to use to execute the commands. Defaults to the default shell for the given operating system. Allowed values are: default, sh and bash
environment_variables ❌ "" string A list of environment variables to forward to the virtual machine. The list should be separated with spaces. The CI and any environment variables starting with GITHUB_ are forwarded automatically.
memory ❌ 6G string The amount of memory for the virtual machine.
cpu_count ❌ 2 integer The number of CPU cores for the virtual machine.
variant ❌ default string Which variant of the operating system to run. See Variants. Valid values are default and, where the platform has it, microvm.
image_url ❌ ❌ string URL a custom VM image that should be used in place of the default ones.
sync_files ❌ true string Specifies if the local files should be synchronized to the virtual machine and in which direction. Valid values are true, false, runner-to-vm and vm-to-runner. true synchronizes files in both directions. false disables file synchronization.
shutdown_vm ❌ conditional boolean Deprecated. Specifies if the VM should be shutdown after the action has been run. If unset, defaults to true when run is provided and false otherwise. There is no replacement.

All inputs are expected to be of the specified type. It's especially important that you specify version as a string, using single or double quotes. Otherwise YAML might interpet the value as a numeric value instead of a string, which leads to some unexpected behavior. If the version is specified as version: 13.0, YAML will interpet 13.0 as a floating point number, drop the fraction part (because 13 and 13.0 are the same) and the GitHub action will only see 13 instead of 13.0. The solution is to explicitly state that a string is required by using quotes: version: '13.0'.

Variants (variant)

A variant is a named configuration of a platform, not a set of independent options. Asking for a variant a platform doesn't have is an error listing the ones it does, rather than a silent fallback.

Variant Available on Description
default everything The platform as it has always booted: firmware, boot loader, then the kernel.
microvm NetBSD 11 on x86-64 Boots the kernel directly on QEMU's microvm machine type, which has no boot loader, no PCI bus and no ACPI.
yaml
- uses: cross-platform-actions/action@v1
  with:
    operating_system: netbsd
    version: '11.0'
    variant: microvm

The microvm variant reaches a usable guest in roughly half the time, but it is opt-in because it changes the hardware the guest sees, and a job that inspects hardware will notice:

  • the root disk is ld0 (virtio-blk), not sd0 (vioscsi)
  • there is no PCI bus and no ACPI, so pcictl and anything reading ACPI differ
  • the kernel is MICROVM rather than GENERIC, which uname -v reports
  • bulk transfers into the guest are slower, virtio over MMIO having one interrupt line per device where PCI has a vector per queue

It also needs an image new enough to ship a kernel beside its disk. Asking for it with an older image is an error rather than a slow boot.

Custom VM Image (image_url)

With the image_url input it's possible to specify a custom virtual machine image. The main reason for this feature is to do additional custom provisioning, like installing additional packages. This allows to pre-install everything that is needed for a CI job beforhand, which can save time later when the job is run.

Only existing operating systems, architectures and versions are supported.

Building a Custom VM Image
  1. Fork one of the existing *builder repositories
  2. Add the additional provisioning to the resources/custom.sh script. Don't remove any existing provisioning scripts.
  3. Adjust the CI workflow to remove any unwanted architectures or versions
  4. Create and push a new tag
  5. This will launch the CI workflow, build the image(s) and create a draft GitHub release. The VM image(s) are automatically attached to the release
  6. Edit the release to publish it
  7. Copy the URL for the VM

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

TypeScript

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月18日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言