Skip to content

Commit

Permalink
Generated from base-vm
Browse files Browse the repository at this point in the history
  • Loading branch information
Generate.yml committed Sep 7, 2024
1 parent 93754f6 commit 1bfb23f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
15 changes: 15 additions & 0 deletions .github/tpl/README.tpl.md
Original file line number Diff line number Diff line change
Expand Up @@ -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}}:

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down Expand Up @@ -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: |
Expand Down
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 12 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 5 additions & 8 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ ovafile="$osname-$VM_RELEASE.qcow2.xz"

_idfile='~/.ssh/host.id_rsa'



importVM() {
_mem=$1
_cpu=$2

bash $vmsh setup

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -156,13 +160,6 @@ addNAT() {

}

setMemory() {
bash $vmsh setMemory "$osname" "$@"
}

setCPU() {
bash $vmsh setCPU "$osname" "$@"
}

startVM() {
bash $vmsh startVM "$osname"
Expand Down

0 comments on commit 1bfb23f

Please sign in to comment.