diff --git a/.github/tpl/README.tpl.md b/.github/tpl/README.tpl.md index c277426..6f258aa 100644 --- a/.github/tpl/README.tpl.md +++ b/.github/tpl/README.tpl.md @@ -159,6 +159,21 @@ The default memory of the VM is 6144MB, you can use `mem` option to set the memo ``` +The VM is using all the cpu cores of the host by default, you can use `cpu` option to change the cpu cores: + +``` +... + steps: + - uses: actions/checkout@v4 + - name: Test + id: test + uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} + with: + envs: 'MYTOKEN MYTOKEN2' + usesh: true + cpu: 3 +... +``` It uses [the {{VM_NAME}} {{DEFAULT_RELEASE}}](conf/default.release.conf) by default, you can use `release` option to use another version of {{VM_NAME}}: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8384617..1d42253 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -47,7 +47,7 @@ jobs: port: 8000 - name: Test in DragonflyBSD id: test - uses: vmactions/dragonflybsd-vm@a0998de1569e15a795022f2031e8a3af9fb4c2c4 + uses: vmactions/dragonflybsd-vm@6b1c9d839cd7f10d02064685deb51237513af408 with: envs: 'DEBUG MYTOKEN MYTOKEN2' prepare: | @@ -90,7 +90,7 @@ jobs: - uses: actions/checkout@v4 - name: Test in DragonflyBSD id: test - uses: vmactions/dragonflybsd-vm@a0998de1569e15a795022f2031e8a3af9fb4c2c4 + uses: vmactions/dragonflybsd-vm@6b1c9d839cd7f10d02064685deb51237513af408 with: envs: 'MYTOKEN MYTOKEN2' prepare: | diff --git a/action.yml b/action.yml index c72cd70..1ddf493 100644 --- a/action.yml +++ b/action.yml @@ -16,6 +16,9 @@ inputs: mem: description: 'Set the memory size of the vm' required: false + cpu: + description: 'Set the cpu cores of the vm' + required: false nat: description: 'The NAT ports to DragonflyBSD vm' required: false diff --git a/index.js b/index.js index d506f47..a3405ef 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ const core = require('@actions/core'); const exec = require('@actions/exec'); const fs = require("fs"); const path = require("path"); +const os = require('os'); var workingDir = __dirname; @@ -30,22 +31,19 @@ async function shell(cmd, cdToScriptHome = true) { } -async function setup(nat, mem) { +async function setup(nat, mem, cpu) { try { core.startGroup("Importing VM"); - await shell("bash run.sh importVM"); - core.endGroup(); - - core.startGroup("Set VM"); - - - if (mem) { - await shell("bash run.sh setMemory " + mem); + if(!cpu) { + cpu = os.cpus().length;//use the system all cores } + core.info("Use cpu: " + cpu); - await shell("bash run.sh setCPU 3"); + + await shell("bash run.sh importVM '" + mem + "' '" + cpu + "'"); core.endGroup(); + core.startGroup("Run onBeforeStartVM"); await shell("bash run.sh onBeforeStartVM " ); core.endGroup(); @@ -133,7 +131,10 @@ async function main() { let mem = core.getInput("mem"); core.info("mem: " + mem); - await setup(nat, mem); + let cpu = core.getInput("cpu"); + core.info("cpu: " + cpu); + + await setup(nat, mem, cpu); var envs = core.getInput("envs"); console.log("envs:" + envs); diff --git a/run.sh b/run.sh index 589806d..2a5e927 100644 --- a/run.sh +++ b/run.sh @@ -79,7 +79,11 @@ ovafile="$osname-$VM_RELEASE.qcow2.xz" _idfile='~/.ssh/host.id_rsa' + + importVM() { + _mem=$1 + _cpu=$2 bash $vmsh setup @@ -107,7 +111,7 @@ importVM() { cat host.id_rsa >$HOME/.ssh/host.id_rsa chmod 600 $HOME/.ssh/host.id_rsa - bash $vmsh importVM $osname $ostype "$osname-$VM_RELEASE.qcow2" + bash $vmsh importVM $osname $ostype "$osname-$VM_RELEASE.qcow2" "" "$_mem" "$_cpu" if [ "$DEBUG" ]; then bash $vmsh startWeb $osname @@ -156,13 +160,6 @@ addNAT() { } -setMemory() { - bash $vmsh setMemory "$osname" "$@" -} - -setCPU() { - bash $vmsh setCPU "$osname" "$@" -} startVM() { bash $vmsh startVM "$osname"