Skip to content

Commit

Permalink
v1.4 (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
hummeltech authored Dec 6, 2023
1 parent 952fe7a commit 939203a
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 13 deletions.
66 changes: 63 additions & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,76 @@ on:
push:

jobs:
FreeBSD:
FreeBSD-On-Linux:
name: ${{ matrix.box }}
runs-on: ubuntu-latest
strategy:
matrix:
box:
- generic/freebsd12
- generic/freebsd13
- generic/freebsd14
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Provision VM
uses: ./
with:
box: ${{ matrix.box }}
cpus: 4
save_box_to_cache: true
use_cached_box: true

- name: Run Test (uname) (VM)
run: |
if [ "$(uname -s)" = "FreeBSD" ]; then
echo "FreeBSD detected."
else
echo "FreeBSD not detected."
exit 1
fi
shell: bash --noprofile --norc -euo pipefail {0}

- name: Run Test (uname) (Host)
run: |
if [ "$(uname -s)" = "Linux" ]; then
echo "Linux detected."
else
echo "Linux not detected."
exit 1
fi
shell: /bin/bash --noprofile --norc -euo pipefail {0}

- name: Prepare Test (working-directory) (VM)
run: |
mkdir new_working_directory
shell: bash --noprofile --norc -euo pipefail {0}

- name: Run Test (working-directory) (VM)
run: |
if [ "$(basename ${PWD})" = "new_working_directory" ]; then
echo "Expected working directory detected."
else
echo "Expected working directory not detected."
exit 1
fi
shell: bash --noprofile --norc -euo pipefail {0}
working-directory: new_working_directory

FreeBSD-On-macOS:
name: ${{ matrix.box }}
runs-on: macos-latest
strategy:
matrix:
box:
- freebsd/FreeBSD-12.4-RELEASE
- freebsd/FreeBSD-13.2-RELEASE
- freebsd/FreeBSD-12.4-STABLE
- freebsd/FreeBSD-13.2-STABLE
- freebsd/FreeBSD-14.0-STABLE
- generic/freebsd12
- generic/freebsd13
- generic/freebsd14
fail-fast: false
steps:
- name: Checkout code
Expand Down
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
# FreeBSD Vagrant Action

**The value for [runs-on](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on) must always be set to `macos-latest` in order to use this action.**
**The value for [runs-on](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on) must either be set to `macos-latest` or `ubuntu-latest` in order to use this action.**

This action allows the running of command-line programs via the `bash` shell of FreeBSD VMs provisioned with Vagrant using the [run](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun) keyword. This also works with composite actions which exclusively use the `run` keyword (and/or call other composite actions which also do so.)

#### *This action is currently only tested with these boxes (but will probably also work with others):*
* `freebsd/FreeBSD-12.4-RELEASE`
* `freebsd/FreeBSD-13.2-RELEASE`
* `freebsd/FreeBSD-12.4-STABLE` (`macos-latest` only)
* `freebsd/FreeBSD-13.2-STABLE` (`macos-latest` only)
* `freebsd/FreeBSD-14.0-STABLE` (`macos-latest` only)
* `generic/freebsd12`
* `generic/freebsd13`
* `generic/freebsd14`

# Usage
<!-- start usage -->
1. Provision a `FreeBSD VM` using the specified `box` (with 2 CPUs & 2GB of RAM)
```yaml
- name: Provision VM
uses: hummeltech/freebsd-vagrant-action@v1.3
uses: hummeltech/freebsd-vagrant-action@v1.4
with:
box: freebsd/FreeBSD-12.4-RELEASE
cpus: 2
Expand Down
72 changes: 66 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,24 @@ inputs:
runs:
using: composite
steps:
- name: Upgrade Vagrant
run: brew upgrade --force --quiet vagrant
- name: Install/Upgrade Vagrant (Linux)
env:
DEBIAN_FRONTEND: noninteractive
run: |
sudo apt-get update
sudo apt-get --yes install \
libvirt-daemon-system \
qemu \
vagrant \
virtualbox
shell: bash
if: runner.os == 'Linux'

- name: Install/Upgrade Vagrant (macOS)
run: |
brew upgrade --force --quiet vagrant
shell: bash
if: runner.os == 'macOS'

- name: Cache Vagrant Box
if: inputs.save_box_to_cache
Expand All @@ -87,7 +102,38 @@ runs:
fi
shell: bash

- name: Generate Vagrantfile
- name: Install Vagrant libvirt Plugin (Linux)
run: |
vagrant plugin install vagrant-libvirt
sudo setfacl -m user:$USER:rw /var/run/libvirt/libvirt-sock
shell: bash
if: runner.os == 'Linux'

- name: Generate Vagrantfile (Linux)
run: |
cat > Vagrantfile <<EOF
Vagrant.configure("2") do |config|
config.ssh.compression = false
config.ssh.connect_timeout = 30
config.ssh.forward_env = ["*"]
config.ssh.shell = "bash"
config.ssh.username = "${{ inputs.vagrant_ssh_username }}"
config.vm.boot_timeout = 1800
config.vm.box = "${{ inputs.box }}"
config.vm.box_check_update = false
config.vm.provider :libvirt do |v|
v.cpus = ${{ inputs.cpus }}
v.driver = "kvm"
v.memory = ${{ inputs.memory }}
end
config.vm.provision "shell", inline: "${{ inputs.provision-commands }}"
config.vm.synced_folder ".", "/vagrant", disabled: true
end
EOF
shell: bash
if: runner.os == 'Linux'

- name: Generate Vagrantfile (macOS)
run: |
cat > Vagrantfile <<EOF
Vagrant.configure("2") do |config|
Expand All @@ -100,22 +146,36 @@ runs:
config.vm.box = "${{ inputs.box }}"
config.vm.box_check_update = false
config.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--cpus", ${{ inputs.cpus }}]
v.customize ["modifyvm", :id, "--memory", ${{ inputs.memory }}]
v.cpus = ${{ inputs.cpus }}
v.memory = ${{ inputs.memory }}
end
config.vm.provision "shell", inline: "${{ inputs.provision-commands }}"
config.vm.synced_folder ".", "/vagrant", disabled: true
end
EOF
shell: bash
if: runner.os == 'macOS'

- name: Show Vagrant Status
run: |
vagrant status
shell: bash

- name: Start Vagrant Environment (Linux)
run: |
vagrant up --provider libvirt
shell: bash
if: runner.os == 'Linux'

- name: Start Vagrant Environment
- name: Start Vagrant Environment (macOS)
run: |
vagrant up
shell: bash
if: runner.os == 'macOS'

- name: Save OpenSSH configuration to ~/.ssh/config
run: |
mkdir -p ~/.ssh
vagrant ssh-config --host vagrantbox >> ~/.ssh/config
shell: bash

Expand Down

0 comments on commit 939203a

Please sign in to comment.