From 8aba3d5591015679a1619ef00960656f3cdebe0e Mon Sep 17 00:00:00 2001 From: Aolin Date: Mon, 4 Dec 2023 12:41:16 +0800 Subject: [PATCH] feat: support running unit tests in CI (#27) --- .github/workflows/run_tests.yml | 30 ++++++++++++++++++++++++++++++ test/test.py | 5 ++++- 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/run_tests.yml diff --git a/.github/workflows/run_tests.yml b/.github/workflows/run_tests.yml new file mode 100644 index 00000000..3d3efa46 --- /dev/null +++ b/.github/workflows/run_tests.yml @@ -0,0 +1,30 @@ +name: Run tests +on: + pull_request: + branches: + - main + +jobs: + + build_and_test: + runs-on: ubuntu-latest + + steps: + - name: Checkout current repo + uses: actions/checkout@v3 + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Create .env file + run: | + echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> .env + echo "TEST=1" >> .env + echo "DOCS_PR=13910" >> .env + echo "DOCS_CN_PR=14523" >> .env + echo "CLOUD_DOCS_PR=10098" >> .env + echo "OPERATOR_DOCS_PR=2397" >> .env + echo "RELEASE_DIR=release-6.7" >> .env + - name: Run test script + run: | + python3 test/test.py diff --git a/test/test.py b/test/test.py index dd4a63b7..920ab22d 100644 --- a/test/test.py +++ b/test/test.py @@ -102,7 +102,10 @@ def analyze(self) -> str: """ Analyze test results and generate a report. """ - terminal_width = os.get_terminal_size().columns + try: + terminal_width = os.get_terminal_size().columns + except OSError: + terminal_width = 80 hyphens = "-" * ((terminal_width - len("Test Results")) // 2) duration = self.report.end_time - self.report.start_time