跨平台 GitHub 动作
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
masterbranch, 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.
FeaturesSome of the features that this action supports include:
UsageHere's a sample workflow file which will run the given commands on FreeBSD 15.1.
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 | sortHere'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.
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 againWhen 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 afternone — skip syncing entirelyrunner-to-vm — only sync runner-to-vm before the file runsvm-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.
- 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:
- name: Sync files from the runner to the VM
run: cpa.sh --sync-files runner-to-vm
- name: Reboot the VM
run: cpa.sh --rebootThis 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'.
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. |
- uses: cross-platform-actions/action@v1
with:
operating_system: netbsd
version: '11.0'
variant: microvmThe 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:
ld0 (virtio-blk), not sd0 (vioscsi)pcictl and anything reading ACPI differMICROVM rather than GENERIC, which uname -v reportsIt 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.
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.
resources/custom.sh script. Don't
remove any existing provisioning scripts.暂无开放 Issues,或尚未同步最近议题。