From 6335bb496e774a748464086e30bef7136097e796 Mon Sep 17 00:00:00 2001 From: hwdsl2 Date: Tue, 4 Oct 2022 00:47:10 -0500 Subject: [PATCH] Add tests --- .github/workflows/main.yml | 27 ++++++++ .github/workflows/test_set_1.yml | 115 +++++++++++++++++++++++++++++++ .github/workflows/test_set_2.yml | 45 ++++++++++++ .github/workflows/test_set_3.yml | 40 +++++++++++ 4 files changed, 227 insertions(+) create mode 100644 .github/workflows/main.yml create mode 100644 .github/workflows/test_set_1.yml create mode 100644 .github/workflows/test_set_2.yml create mode 100644 .github/workflows/test_set_3.yml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..e6011cd --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,27 @@ +# +# Copyright (C) 2022 Lin Song + +name: build + +on: + push: + branches: [master] + paths: + - '**.sh' + - '.github/workflows/main.yml' + - '.github/workflows/test_set_1.yml' + - '.github/workflows/test_set_2.yml' + - '.github/workflows/test_set_3.yml' + +jobs: + test_set_1: + if: github.repository_owner == 'hwdsl2' + uses: ./.github/workflows/test_set_1.yml + + test_set_2: + if: github.repository_owner == 'hwdsl2' + uses: ./.github/workflows/test_set_2.yml + + test_set_3: + if: github.repository_owner == 'hwdsl2' + uses: ./.github/workflows/test_set_3.yml diff --git a/.github/workflows/test_set_1.yml b/.github/workflows/test_set_1.yml new file mode 100644 index 0000000..70602ef --- /dev/null +++ b/.github/workflows/test_set_1.yml @@ -0,0 +1,115 @@ +# +# Copyright (C) 2022 Lin Song + +name: test_set_1 + +on: workflow_call + +jobs: + test_set_1: + runs-on: ubuntu-20.04 + if: github.repository_owner == 'hwdsl2' + strategy: + matrix: + os_version: ["centos:9s", "centos:8s", "centos:7", "rockylinux:9", "rockylinux:8", "almalinux:9", "almalinux:8", "amazonlinux:2"] + fail-fast: false + env: + OS_VERSION: ${{ matrix.os_version }} + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # 2.4.0 + with: + persist-credentials: false + - name: Build + run: | + mkdir -p "$GITHUB_WORKSPACE/testing/${OS_VERSION//:}" + cd "$GITHUB_WORKSPACE/testing/${OS_VERSION//:}" + + mkdir -p scripts + ls -ld "$GITHUB_WORKSPACE/openvpn-install.sh" + cp -f "$GITHUB_WORKSPACE"/*.sh scripts/ + + cat > run.sh <<'EOF' + #!/bin/bash + set -eEx + + trap 'catch $? $LINENO' ERR + + catch() { + echo "Error $1 occurred on line $2." + cat -n -- "$0" | tail -n+"$(($2 - 3))" | head -n7 + exit 1 + } + + cd /opt/src + yum -y -q update + yum -y -q install wget rsyslog kmod procps-ng iproute net-tools + systemctl start rsyslog + + cp -f /opt/src/scripts/openvpn-install.sh ./openvpn.sh + + bash openvpn.sh --auto + + netstat -anpu | grep openvpn + systemctl status openvpn-server@server + ls -ld ~/client.ovpn + + exit 0 + EOF + + if [ "$OS_VERSION" = "centos:9s" ]; then + echo "FROM quay.io/centos/centos:stream9" > Dockerfile + elif [ "$OS_VERSION" = "centos:8s" ]; then + echo "FROM quay.io/centos/centos:stream8" > Dockerfile + else + echo "FROM $OS_VERSION" > Dockerfile + fi + + cat >> Dockerfile <<'EOF' + + ENV container docker + WORKDIR /opt/src + + RUN if command -v amazon-linux-extras; then amazon-linux-extras install -y kernel-ng; fi + EOF + + if [ "$OS_VERSION" = "centos:9s" ]; then + echo "RUN yum -y -q install systemd" >> Dockerfile + fi + + cat >> Dockerfile <<'EOF' + + RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ "$i" = \ + systemd-tmpfiles-setup.service ] || rm -f "$i"; done); \ + rm -f /lib/systemd/system/multi-user.target.wants/*; \ + rm -f /etc/systemd/system/*.wants/*; \ + rm -f /lib/systemd/system/local-fs.target.wants/*; \ + rm -f /lib/systemd/system/sockets.target.wants/*udev*; \ + rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \ + rm -f /lib/systemd/system/basic.target.wants/*; \ + rm -f /lib/systemd/system/anaconda.target.wants/*; + + COPY scripts/ /opt/src/scripts/ + COPY ./run.sh /opt/src/run.sh + RUN chmod 755 /opt/src/run.sh + + VOLUME [ "/sys/fs/cgroup" ] + + CMD ["/sbin/init"] + EOF + cat Dockerfile + cat run.sh + docker build -t "${OS_VERSION//:}-test" . + + - name: Test + run: | + docker run -d --name "${OS_VERSION//:}-test-1" -v /sys/fs/cgroup:/sys/fs/cgroup:ro \ + --privileged "${OS_VERSION//:}-test" + sleep 5 + docker exec "${OS_VERSION//:}-test-1" /opt/src/run.sh "${OS_VERSION::6}" + + - name: Clear + if: always() + run: | + rm -rf "$GITHUB_WORKSPACE/testing/${OS_VERSION//:}" + docker rm -f "${OS_VERSION//:}-test-1" || true + docker rmi "${OS_VERSION//:}-test" || true diff --git a/.github/workflows/test_set_2.yml b/.github/workflows/test_set_2.yml new file mode 100644 index 0000000..24c6264 --- /dev/null +++ b/.github/workflows/test_set_2.yml @@ -0,0 +1,45 @@ +# +# Copyright (C) 2022 Lin Song + +name: test_set_2 + +on: workflow_call + +jobs: + test_set_2: + runs-on: ubuntu-20.04 + if: github.repository_owner == 'hwdsl2' + strategy: + matrix: + os_version: ["debian:11", "debian:10"] + fail-fast: false + container: + image: ${{ matrix.os_version }} + options: --cap-add=NET_ADMIN --device=/dev/net/tun + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # 2.4.0 + with: + persist-credentials: false + - name: Test + run: | + set -ex + + mkdir -p /opt/src + cd /opt/src + ls -ld "$GITHUB_WORKSPACE/openvpn-install.sh" + + export DEBIAN_FRONTEND=noninteractive + apt-get -yqq update + apt-get -yqq dist-upgrade + apt-get -yqq install wget rsyslog kmod procps iproute2 net-tools + if grep -qs bookworm /etc/debian_version; then + rsyslogd + else + service rsyslog start + fi + + cp -f "$GITHUB_WORKSPACE"/openvpn-install.sh ./openvpn.sh + + bash openvpn.sh --auto + + ls -ld ~/client.ovpn diff --git a/.github/workflows/test_set_3.yml b/.github/workflows/test_set_3.yml new file mode 100644 index 0000000..b213804 --- /dev/null +++ b/.github/workflows/test_set_3.yml @@ -0,0 +1,40 @@ +# +# Copyright (C) 2022 Lin Song + +name: test_set_3 + +on: workflow_call + +jobs: + test_set_3: + if: github.repository_owner == 'hwdsl2' + strategy: + matrix: + os: [ubuntu-22.04, ubuntu-20.04] + fail-fast: false + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@ec3a7ce113134d7a93b817d10a8272cb61118579 # 2.4.0 + with: + persist-credentials: false + - name: Test + run: | + set -ex + + mkdir -p /opt/src + cd /opt/src + ls -ld "$GITHUB_WORKSPACE/openvpn-install.sh" + + export DEBIAN_FRONTEND=noninteractive + sudo apt-get -yqq update + sudo apt-get -yqq dist-upgrade + sudo apt-get -yqq install wget rsyslog + sudo service rsyslog start + + cp -f "$GITHUB_WORKSPACE"/openvpn-install.sh ./openvpn.sh + + sudo bash openvpn.sh --auto + + sudo netstat -anpu | grep openvpn + sudo systemctl status openvpn-server@server + ls -ld ~/client.ovpn