tunasync.yml 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. name: tunasync
  2. on: [push, pull_request, workflow_dispatch]
  3. jobs:
  4. build:
  5. name: Build
  6. runs-on: ubuntu-latest
  7. steps:
  8. - name: Check out code into the Go module directory
  9. uses: actions/checkout@v4
  10. - name: Set up Go
  11. uses: actions/setup-go@v5
  12. with:
  13. go-version: '^1.22'
  14. id: go
  15. - name: Get dependencies
  16. run: |
  17. go get -v -t -d ./cmd/tunasync
  18. go get -v -t -d ./cmd/tunasynctl
  19. - name: Build
  20. run: |
  21. make tunasync
  22. make tunasynctl
  23. - name: Keep artifacts
  24. uses: actions/upload-artifact@v4
  25. with:
  26. name: tunasync-bin
  27. path: build-linux-amd64/
  28. test:
  29. name: Test
  30. runs-on: ubuntu-latest
  31. services:
  32. registry:
  33. image: registry:2
  34. ports:
  35. - 5000:5000
  36. steps:
  37. - name: Setup test dependencies
  38. run: |
  39. sudo apt-get update
  40. sudo apt-get install -y cgroup-tools
  41. docker pull alpine:3.8
  42. - name: Check out code into the Go module directory
  43. uses: actions/checkout@v4
  44. - name: Set up Go
  45. uses: actions/setup-go@v5
  46. with:
  47. go-version: '^1.22'
  48. id: go
  49. - name: Run Unit tests.
  50. run: |
  51. go install github.com/wadey/gocovmerge@latest
  52. sudo systemd-run --service-type=oneshot --uid="$(id --user)" --pipe --wait \
  53. --property=Delegate=yes --setenv=USECURCGROUP=1 \
  54. --setenv=TERM=xterm-256color --same-dir \
  55. make test
  56. - name: Run Additional Unit tests.
  57. run: |
  58. make build-test-worker
  59. sudo mkdir /sys/fs/cgroup/tunasync
  60. sudo ./worker.test -test.v=true -test.coverprofile profile2.cov -test.run TestCgroup
  61. sudo rmdir /sys/fs/cgroup/tunasync
  62. touch /tmp/dummy_exec
  63. chmod +x /tmp/dummy_exec
  64. run_test_reexec (){
  65. case="$1"
  66. shift
  67. argv0="$1"
  68. shift
  69. (TESTREEXEC="$case" TERM=xterm-256color exec -a "$argv0" ./worker.test -test.v=true -test.coverprofile "profile5_$case.cov" -test.run TestReexec -- "$@")
  70. }
  71. run_test_reexec 1 tunasync-exec __dummy__
  72. run_test_reexec 2 tunasync-exec /tmp/dummy_exec
  73. run_test_reexec 3 tunasync-exec /tmp/dummy_exec 3< <(echo -n "abrt")
  74. run_test_reexec 4 tunasync-exec /tmp/dummy_exec 3< <(echo -n "cont")
  75. run_test_reexec 5 tunasync-exec2
  76. - name: Set up Docker Buildx
  77. uses: docker/setup-buildx-action@v3
  78. with:
  79. driver-opts: network=host
  80. - name: Cache Docker layers
  81. uses: actions/cache@v4
  82. if: github.event_name == 'push'
  83. with:
  84. path: /tmp/.buildx-cache
  85. key: ${{ runner.os }}-buildx-${{ github.sha }}
  86. restore-keys: |
  87. ${{ runner.os }}-buildx-
  88. - name: Cache Docker layers
  89. uses: actions/cache@v4
  90. if: github.event_name == 'pull_request'
  91. with:
  92. path: /tmp/.buildx-cache
  93. key: ${{ runner.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-${{ github.sha }}
  94. restore-keys: |
  95. ${{ runner.os }}-pr-${{ github.event.pull_request.head.user.login }}-buildx-
  96. ${{ runner.os }}-buildx-
  97. - name: Cache Docker layers
  98. if: github.event_name != 'push' && github.event_name != 'pull_request'
  99. run: |
  100. echo "I do not know how to setup cache"
  101. exit -1
  102. - name: Prepare cache directory
  103. run: |
  104. mkdir -p /tmp/.buildx-cache
  105. - name: Build Docker image for uml rootfs
  106. uses: docker/build-push-action@v6
  107. with:
  108. context: .umlrootfs
  109. file: .umlrootfs/Dockerfile
  110. push: true
  111. tags: localhost:5000/umlrootfs
  112. cache-from: type=local,src=/tmp/.buildx-cache
  113. cache-to: type=local,dest=/tmp/.buildx-cache
  114. - name: Fetch and install uml package
  115. run: |
  116. sudo apt-get update
  117. sudo apt-get install -y debian-archive-keyring
  118. sudo ln -sf /usr/share/keyrings/debian-archive-keyring.gpg /etc/apt/trusted.gpg.d/
  119. echo "deb http://deb.debian.org/debian bullseye main" | sudo tee /etc/apt/sources.list.d/bullseye.list
  120. sudo apt-get update
  121. apt-get download user-mode-linux/bullseye
  122. sudo rm /etc/apt/sources.list.d/bullseye.list
  123. sudo apt-get update
  124. sudo mv user-mode-linux_*.deb /tmp/uml.deb
  125. sudo apt-get install --no-install-recommends -y /tmp/uml.deb
  126. sudo rm /tmp/uml.deb
  127. sudo apt-get install --no-install-recommends -y rsh-redone-client
  128. - name: Prepare uml environment
  129. run: |
  130. docker container create --name umlrootfs localhost:5000/umlrootfs
  131. sudo mkdir -p umlrootfs
  132. docker container export umlrootfs | sudo tar -xv -C umlrootfs
  133. docker container rm umlrootfs
  134. sudo cp -a --target-directory=umlrootfs/lib/ /usr/lib/uml/modules
  135. /bin/echo -e "127.0.0.1 localhost\n254.255.255.1 host" | sudo tee umlrootfs/etc/hosts
  136. sudo ip tuntap add dev umltap mode tap
  137. sudo ip addr add 254.255.255.1/24 dev umltap
  138. sudo ip link set umltap up
  139. - name: Start Uml
  140. run: |
  141. start_uml () {
  142. sudo bash -c 'linux root=/dev/root rootflags=/ rw rootfstype=hostfs mem=2G eth0=tuntap,umltap hostfs="$PWD/umlrootfs" con1=pts systemd.unified_cgroup_hierarchy=0 & pid=$!; echo "UMLINUX_PID=$pid" >> '"$GITHUB_ENV"
  143. }
  144. ( start_uml )
  145. started=0
  146. for i in $(seq 1 60); do
  147. if ping -c 1 -w 1 254.255.255.2; then
  148. started=1
  149. break
  150. fi
  151. done
  152. if [ "$started" != "1" ]; then
  153. echo "Failed to wait Umlinux online"
  154. exit 1
  155. fi
  156. - name: Prepare Uml Environment
  157. run: |
  158. CUSER="$(id --user --name)"
  159. CUID="$(id --user)"
  160. CGID="$(id --group)"
  161. sudo chroot umlrootfs bash --noprofile --norc -eo pipefail << EOF
  162. groupadd --gid "${CGID?}" "${CUSER?}"
  163. useradd --create-home --home-dir "/home/${CUSER}" --gid "${CGID?}" \
  164. --uid "${CUID?}" --shell "\$(which bash)" "${CUSER?}"
  165. EOF
  166. ln ./worker.test "umlrootfs/home/${CUSER}/worker.test"
  167. - name: Run Tests in Cgroupv1
  168. run: |
  169. CUSER="$(id --user --name)"
  170. sudo rsh 254.255.255.2 bash --noprofile --norc -eo pipefail << EOF
  171. cd "/home/${CUSER}"
  172. lssubsys -am
  173. cgcreate -a "$CUSER" -t "$CUSER" -g cpu:tunasync
  174. cgcreate -a "$CUSER" -t "$CUSER" -g memory:tunasync
  175. TERM=xterm-256color ./worker.test -test.v=true -test.coverprofile \
  176. profile3.cov -test.run TestCgroup
  177. cgexec -g "*:/" bash -c "echo 0 > /sys/fs/cgroup/systemd/tasks; exec sudo -u $CUSER env USECURCGROUP=1 TERM=xterm-256color cgexec -g cpu,memory:tunasync ./worker.test -test.v=true -test.coverprofile profile4.cov -test.run TestCgroup"
  178. EOF
  179. - name: Stop Uml
  180. run: |
  181. sudo rsh 254.255.255.2 systemctl poweroff
  182. sleep 10
  183. if [ -e "/proc/$UMLINUX_PID" ]; then
  184. sleep 10
  185. if [ -e "/proc/$UMLINUX_PID" ]; then
  186. sudo kill -TERM "$UMLINUX_PID" || true
  187. sleep 1
  188. fi
  189. fi
  190. if [ -e "/proc/$UMLINUX_PID" ]; then
  191. sleep 10
  192. if [ -e "/proc/$UMLINUX_PID" ]; then
  193. sudo kill -KILL "$UMLINUX_PID" || true
  194. sleep 1
  195. fi
  196. fi
  197. - name: Combine coverage files
  198. run : |
  199. CUSER="$(id --user --name)"
  200. "${HOME}/go/bin/gocovmerge" profile.cov profile2.cov \
  201. "umlrootfs/home/${CUSER}/profile3.cov" \
  202. "umlrootfs/home/${CUSER}/profile4.cov" \
  203. profile5_*.cov > profile-all.cov
  204. - name: Convert coverage to lcov
  205. uses: jandelgado/gcov2lcov-action@v1
  206. with:
  207. infile: profile-all.cov
  208. outfile: coverage.lcov
  209. - name: Coveralls
  210. uses: coverallsapp/github-action@v2
  211. with:
  212. github-token: ${{ secrets.github_token }}
  213. path-to-lcov: coverage.lcov