Skip to content

Commit 1bfb23f

Browse files
author
Generate.yml
committed
Generated from base-vm
1 parent 93754f6 commit 1bfb23f

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

.github/tpl/README.tpl.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,21 @@ The default memory of the VM is 6144MB, you can use `mem` option to set the memo
159159
```
160160

161161

162+
The VM is using all the cpu cores of the host by default, you can use `cpu` option to change the cpu cores:
163+
164+
```
165+
...
166+
steps:
167+
- uses: actions/checkout@v4
168+
- name: Test
169+
id: test
170+
uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}}
171+
with:
172+
envs: 'MYTOKEN MYTOKEN2'
173+
usesh: true
174+
cpu: 3
175+
...
176+
```
162177

163178
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}}:
164179

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
port: 8000
4848
- name: Test in DragonflyBSD
4949
id: test
50-
uses: vmactions/dragonflybsd-vm@a0998de1569e15a795022f2031e8a3af9fb4c2c4
50+
uses: vmactions/dragonflybsd-vm@6b1c9d839cd7f10d02064685deb51237513af408
5151
with:
5252
envs: 'DEBUG MYTOKEN MYTOKEN2'
5353
prepare: |
@@ -90,7 +90,7 @@ jobs:
9090
- uses: actions/checkout@v4
9191
- name: Test in DragonflyBSD
9292
id: test
93-
uses: vmactions/dragonflybsd-vm@a0998de1569e15a795022f2031e8a3af9fb4c2c4
93+
uses: vmactions/dragonflybsd-vm@6b1c9d839cd7f10d02064685deb51237513af408
9494
with:
9595
envs: 'MYTOKEN MYTOKEN2'
9696
prepare: |

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ inputs:
1616
mem:
1717
description: 'Set the memory size of the vm'
1818
required: false
19+
cpu:
20+
description: 'Set the cpu cores of the vm'
21+
required: false
1922
nat:
2023
description: 'The NAT ports to DragonflyBSD vm'
2124
required: false

index.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const core = require('@actions/core');
22
const exec = require('@actions/exec');
33
const fs = require("fs");
44
const path = require("path");
5+
const os = require('os');
56

67

78
var workingDir = __dirname;
@@ -30,22 +31,19 @@ async function shell(cmd, cdToScriptHome = true) {
3031
}
3132

3233

33-
async function setup(nat, mem) {
34+
async function setup(nat, mem, cpu) {
3435
try {
3536
core.startGroup("Importing VM");
36-
await shell("bash run.sh importVM");
37-
core.endGroup();
38-
39-
core.startGroup("Set VM");
40-
41-
42-
if (mem) {
43-
await shell("bash run.sh setMemory " + mem);
37+
if(!cpu) {
38+
cpu = os.cpus().length;//use the system all cores
4439
}
40+
core.info("Use cpu: " + cpu);
4541

46-
await shell("bash run.sh setCPU 3");
42+
43+
await shell("bash run.sh importVM '" + mem + "' '" + cpu + "'");
4744
core.endGroup();
4845

46+
4947
core.startGroup("Run onBeforeStartVM");
5048
await shell("bash run.sh onBeforeStartVM " );
5149
core.endGroup();
@@ -133,7 +131,10 @@ async function main() {
133131
let mem = core.getInput("mem");
134132
core.info("mem: " + mem);
135133

136-
await setup(nat, mem);
134+
let cpu = core.getInput("cpu");
135+
core.info("cpu: " + cpu);
136+
137+
await setup(nat, mem, cpu);
137138

138139
var envs = core.getInput("envs");
139140
console.log("envs:" + envs);

run.sh

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ ovafile="$osname-$VM_RELEASE.qcow2.xz"
7979

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

82+
83+
8284
importVM() {
85+
_mem=$1
86+
_cpu=$2
8387

8488
bash $vmsh setup
8589

@@ -107,7 +111,7 @@ importVM() {
107111
cat host.id_rsa >$HOME/.ssh/host.id_rsa
108112
chmod 600 $HOME/.ssh/host.id_rsa
109113

110-
bash $vmsh importVM $osname $ostype "$osname-$VM_RELEASE.qcow2"
114+
bash $vmsh importVM $osname $ostype "$osname-$VM_RELEASE.qcow2" "" "$_mem" "$_cpu"
111115

112116
if [ "$DEBUG" ]; then
113117
bash $vmsh startWeb $osname
@@ -156,13 +160,6 @@ addNAT() {
156160

157161
}
158162

159-
setMemory() {
160-
bash $vmsh setMemory "$osname" "$@"
161-
}
162-
163-
setCPU() {
164-
bash $vmsh setCPU "$osname" "$@"
165-
}
166163

167164
startVM() {
168165
bash $vmsh startVM "$osname"

0 commit comments

Comments
 (0)