在 GitHub 操作上使用 Vagrant(最好包括 VirtualBox)

Using Vagrant on GitHub Actions (ideally incl. VirtualBox)

我知道 可以使用 libvirt 而不是 VirtualBox 在 TravisCI 上启动和 运行 Vagrant Boxes。

GitHub 动作也可以吗?由于 the new pricing model,我们将一切都从 TravisCI 移走,我们还需要切换基于 Vagrant 的测试用例。

是的,this is possible using the macos-10.15 (which is currently the macos-latest) environment. You could also try to go with macos-11.0, but there currently seems to be no stable VirtualBox release for Big Sur. I created a small example project at https://github.com/jonashackt/vagrant-github-actions

假设您的存储库中有一个 Vagrantfile,如下所示:

Vagrant.configure("2") do |config|
    config.vm.box = "generic/ubuntu1804"

    config.vm.define 'ubuntu'

    # Prevent SharedFoldersEnableSymlinksCreate errors
    config.vm.synced_folder ".", "/vagrant", disabled: true
end

然后在 .github/workflows 文件夹中添加一个 GitHub 动作工作流程,例如 vagrant-up.yml,如下所示:

name: vagrant-up

on: [push]

jobs:
  vagrant-up:
    runs-on: macos-10.15

    steps:
    - uses: actions/checkout@v2

    - name: Cache Vagrant boxes
      uses: actions/cache@v2
      with:
        path: ~/.vagrant.d/boxes
        key: ${{ runner.os }}-vagrant-${{ hashFiles('Vagrantfile') }}
        restore-keys: |
          ${{ runner.os }}-vagrant-

    - name: Run vagrant up
      run: vagrant up

    - name: ssh into box after boot
      run: vagrant ssh -c "echo 'hello world!'"

您甚至可以省略 the caching action - 我只是将其添加到此处以显示可能的情况。它会为您节省几秒钟,具体取决于您使用的 VagrantBox。

运行 Vagrant 的 GitHub 操作实施 , because you don't need to install Vagrant or VirtualBox - and you also don't need to switch to libvirt. Just use the box you want from https://app.vagrantup.com/boxes/search 更容易,这非常酷。