diff --git a/.github/tpl/README.tpl.md b/.github/tpl/README.tpl.md index 3b084d7..4ffd552 100644 --- a/.github/tpl/README.tpl.md +++ b/.github/tpl/README.tpl.md @@ -23,7 +23,7 @@ jobs: MYTOKEN : ${{ secrets.MYTOKEN }} MYTOKEN2: "value2" steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test in {{VM_NAME}} id: test uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} @@ -72,7 +72,7 @@ The code is shared from the host to the VM via `rsync`, you can choose to use to ... steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test id: test uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} @@ -99,7 +99,7 @@ When using `rsync`, you can define `copyback: false` to not copy files back fro ... steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test id: test uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} @@ -125,7 +125,7 @@ You can add NAT port between the host and the VM. ``` ... steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test id: test uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} @@ -145,7 +145,7 @@ The default memory of the VM is 6144MB, you can use `mem` option to set the memo ``` ... steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test id: test uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} @@ -163,7 +163,7 @@ It uses [the latest {{VM_NAME}} {{DEFAULT_RELEASE}}](conf/default.release.conf) ``` ... steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test id: test uses: {{GITHUB_REPOSITORY}}@{{LATEST_MAJOR}} diff --git a/.github/workflows/manual.yml b/.github/workflows/manual.yml index 73e947d..ab1be00 100644 --- a/.github/workflows/manual.yml +++ b/.github/workflows/manual.yml @@ -12,7 +12,7 @@ jobs: VM_RELEASE: ${{ secrets.VM_RELEASE }} SEC_VBOX : ${{ secrets.SEC_VBOX }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - uses: vmactions/cf-tunnel@v0 id: tunnel with: diff --git a/.github/workflows/readme.yml b/.github/workflows/readme.yml index 9321fbd..46c4538 100644 --- a/.github/workflows/readme.yml +++ b/.github/workflows/readme.yml @@ -17,7 +17,7 @@ jobs: readme: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Get latest release id: get-latest-release diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 8e1e9e3..0ae4c74 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,10 +37,10 @@ jobs: MYTOKEN2: "value2" SEC_VBOX : ${{ secrets.SEC_VBOX }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test in OpenBSD id: test - uses: vmactions/openbsd-vm@main + uses: vmactions/openbsd-vm@d50db1de19e70496fba3280d4c7c8891409fcd1d with: envs: 'MYTOKEN MYTOKEN2' prepare: | @@ -49,6 +49,7 @@ jobs: copyback: false release: ${{ matrix.release }} nat: | + "10022": "22" "8080": "80" "8443": "443" udp:"8081": "80" @@ -57,6 +58,9 @@ jobs: run: | tree . tree $HOME/work/ + - name: Test NAT + run: + ssh -p 10022 -i $HOME/.ssh/host.id_rsa root@localhost "uname -a;whoami;pwd" test: strategy: @@ -70,10 +74,10 @@ jobs: MYTOKEN2: "value2" SEC_VBOX : ${{ secrets.SEC_VBOX }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Test in OpenBSD id: test - uses: vmactions/openbsd-vm@main + uses: vmactions/openbsd-vm@d50db1de19e70496fba3280d4c7c8891409fcd1d with: envs: 'MYTOKEN MYTOKEN2' prepare: | @@ -82,6 +86,7 @@ jobs: copyback: false release: ${{ matrix.release }} nat: | + "10022": "22" "8080": "80" "8443": "443" udp:"8081": "80" @@ -94,6 +99,9 @@ jobs: env + - name: Test NAT + run: + ssh -p 10022 -i $HOME/.ssh/host.id_rsa root@localhost "uname -a;whoami;pwd" diff --git a/index.js b/index.js index ca94460..d03ea04 100644 --- a/index.js +++ b/index.js @@ -37,27 +37,7 @@ async function setup(nat, mem) { core.endGroup(); core.startGroup("Set VM"); - if (nat) { - let nats = nat.split("\n").filter(x => x !== ""); - for (let element of nats) { - core.info("Add nat: " + element); - let segs = element.split(":"); - if (segs.length === 3) { - //udp:"8081": "80" - let proto = segs[0].trim().trim('"'); - let hostPort = segs[1].trim().trim('"'); - let vmPort = segs[2].trim().trim('"'); - await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort); - - } else if (segs.length === 2) { - let proto = "tcp" - let hostPort = segs[0].trim().trim('"'); - let vmPort = segs[1].trim().trim('"'); - await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort); - } - }; - } if (mem) { await shell("bash run.sh setMemory " + mem); @@ -82,6 +62,30 @@ async function setup(nat, mem) { core.endGroup(); core.startGroup("Run onStarted in VM"); + + if (nat) { + let nats = nat.split("\n").filter(x => x !== ""); + for (let element of nats) { + core.info("Add nat: " + element); + let segs = element.split(":"); + if (segs.length === 3) { + //udp:"8081": "80" + let proto = segs[0].trim().trim('"'); + let hostPort = segs[1].trim().trim('"'); + let vmPort = segs[2].trim().trim('"'); + + await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort); + + } else if (segs.length === 2) { + let proto = "tcp" + let hostPort = segs[0].trim().trim('"'); + let vmPort = segs[1].trim().trim('"'); + await shell("bash run.sh addNAT " + proto + " " + hostPort + " " + vmPort); + } + }; + } + + await shell("bash run.sh onStarted" ); core.endGroup(); diff --git a/run.sh b/run.sh index cdccb6e..ac78d2f 100644 --- a/run.sh +++ b/run.sh @@ -138,7 +138,25 @@ execSSHSH() { addNAT() { - bash $vmsh addNAT "$osname" "$@" + _prot="$1" + _hostport="$2" + _vmport="$3" + _vmip=$(bash $vmsh getVMIP "$osname") + + if ! command -v socat; then + if bash $vmsh isLinux; then + sudo apt-get install -y socat + else + brew install socat + fi + fi + + if [ "$_prot" == "udp" ]; then + sudo socat UDP4-RECVFROM:$_hostport,fork UDP4-SENDTO:$_vmip:$_vmport & + else + sudo socat TCP-LISTEN:$_hostport,fork TCP:$_vmip:$_vmport & + fi + } setMemory() {