From 0b34065deb1f3723d73ec803ac01928ccf8e7685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=81=B5=E3=81=81?= Date: Sun, 30 Jul 2023 05:55:44 +0900 Subject: [PATCH] update github acction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: ふぁ --- .github/workflows/test-build.yaml | 87 +++++++++++++++++++ .github/workflows/test-python.yaml | 30 +++---- test/dart-dio/openapi-generator-config.yaml | 2 + test/python/login.py | 4 +- test/python/openapi-generator-config.yaml | 4 - test/python/test_serialize.py | 9 +- .../openapi-generator-config.yaml | 4 + 7 files changed, 114 insertions(+), 26 deletions(-) create mode 100644 .github/workflows/test-build.yaml create mode 100644 test/dart-dio/openapi-generator-config.yaml create mode 100644 test/typescript-fetch/openapi-generator-config.yaml diff --git a/.github/workflows/test-build.yaml b/.github/workflows/test-build.yaml new file mode 100644 index 0000000..d74973e --- /dev/null +++ b/.github/workflows/test-build.yaml @@ -0,0 +1,87 @@ +name: build-test + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + + # Openapi Generator Setup + - name: Get OpenJDK 11 + uses: actions/setup-java@v2 + with: + distribution: "temurin" + java-version: 11 + + - name: Get Java version + run: java -version + + - name: Get Openapi Generator cache file + id: openapi-generator-cache + run: echo "file=openapi-generator-cli.jar" >> $GITHUB_OUTPUT + + - name: Openapi Generator cache + uses: actions/cache@v3 + with: + path: ${{ steps.openapi-generator-cache.outputs.file }} + key: ${{ runner.os }}-openapi-generator-${{ hashFiles('openapi-generator-cli.jar') }} + restore-keys: | + ${{ runner.os }}-openapi-generator- + + - name: Get Openapi Generator + run: | + wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose + if: steps.openapi-generator-cache.outputs.cache-hit != 'true' + + # Python Setup + - name: Set up Python 3.10 + uses: actions/setup-python@v4 + with: + python-version: "3.10" + architecture: "x64" + + - name: Get Python version + run: python -V + + - name: Get pip cache dir + id: pip-cache + run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT + + - name: pip cache + uses: actions/cache@v3 + with: + path: ${{ steps.pip-cache.outputs.dir }} + key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + # generate + - name: Build twitter-openapi + run: | + python tools/build.py + + # clean up dependencies + - name: Clean up dependencies + run: | + pip uninstall -y -r requirements.txt + + # generate + - name: Generate + run: | + java -jar openapi-generator-cli.jar generate -c test/python/openapi-generator-config.yaml -g python + java -jar openapi-generator-cli.jar generate -c test/dart-dio/openapi-generator-config.yaml -g dart-dio + java -jar openapi-generator-cli.jar generate -c test/typescript-fetch/openapi-generator-config.yaml -g typescript-fetch diff --git a/.github/workflows/test-python.yaml b/.github/workflows/test-python.yaml index 2998899..2665978 100644 --- a/.github/workflows/test-python.yaml +++ b/.github/workflows/test-python.yaml @@ -1,21 +1,12 @@ name: test-python -on: - # auto review - pull_request: - paths-ignore: - - "test/**" - - ".github/**" - branches: - - master - -env: - TWITTER_SESSION: ${{secrets.TWITTER_SESSION}} - +on: ["pull_request_target"] jobs: - test: - name: Test + build_and_preview: runs-on: ubuntu-latest + name: Test + environment: twitter_session + steps: - uses: actions/checkout@v3 @@ -43,13 +34,14 @@ jobs: - name: Get Openapi Generator run: | - wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose --show-progress --no-clobber + wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose + if: steps.openapi-generator-cache.outputs.cache-hit != 'true' # Python Setup - - name: Set up Python 3.8 - uses: actions/setup-python@v2 + - name: Set up Python 3.10 + uses: actions/setup-python@v4 with: - python-version: 3.8 + python-version: "3.10" architecture: "x64" - name: Get Python version @@ -96,4 +88,4 @@ jobs: run: | python test/python/test_serialize.py env: - TWITTER_SESSION: ${{secrets.TWITTER_SESSION}} + TWITTER_SESSION: ${{ secrets.TWITTER_SESSION }} diff --git a/test/dart-dio/openapi-generator-config.yaml b/test/dart-dio/openapi-generator-config.yaml new file mode 100644 index 0000000..68a63b1 --- /dev/null +++ b/test/dart-dio/openapi-generator-config.yaml @@ -0,0 +1,2 @@ +inputSpec: dist/compatible/openapi-3.0.yaml +outputDir: dart_dio_generated diff --git a/test/python/login.py b/test/python/login.py index 8b83387..29e2762 100644 --- a/test/python/login.py +++ b/test/python/login.py @@ -1,4 +1,5 @@ import json +import base64 from tweepy_authlib import CookieSessionUserHandler auth_handler = CookieSessionUserHandler( @@ -9,4 +10,5 @@ auth_handler = CookieSessionUserHandler( cookies = auth_handler.get_cookies() -print(json.dumps(cookies.get_dict())) +data = json.dumps(cookies.get_dict()) +print(base64.b64encode(data.encode("utf-8")).decode("utf-8")) diff --git a/test/python/openapi-generator-config.yaml b/test/python/openapi-generator-config.yaml index 11a4569..29dd088 100644 --- a/test/python/openapi-generator-config.yaml +++ b/test/python/openapi-generator-config.yaml @@ -1,8 +1,4 @@ inputSpec: dist/compatible/openapi-3.0.yaml outputDir: python_generated -packageName: python_generated -packageVersion: 0.0.1 -projectName: python_generated - useOneOfDiscriminatorLookup: true diff --git a/test/python/test_serialize.py b/test/python/test_serialize.py index 29457d5..78567a9 100644 --- a/test/python/test_serialize.py +++ b/test/python/test_serialize.py @@ -1,7 +1,8 @@ import json import os import logging -import python_generated as pt +import base64 +import openapi_client as pt from pathlib import Path @@ -12,7 +13,8 @@ if Path("cookie.json").exists(): with open("cookie.json", "r") as f: cookies = json.load(f) else: - cookies = json.loads(os.environ["TWITTER_SESSION"]) + data = base64.b64decode(os.environ["TWITTER_SESSION"]).decode("utf-8") + cookies = json.loads(data) cookies_str = "; ".join([f"{k}={v}" for k, v in cookies.items()]) @@ -65,6 +67,9 @@ for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UserListApi]: except Exception as e: logger.error(f"{key}") logger.error(e) + import traceback + + logger.error(traceback.print_exc()) error_count += 1 if error_count > 0: diff --git a/test/typescript-fetch/openapi-generator-config.yaml b/test/typescript-fetch/openapi-generator-config.yaml new file mode 100644 index 0000000..aca83c8 --- /dev/null +++ b/test/typescript-fetch/openapi-generator-config.yaml @@ -0,0 +1,4 @@ +inputSpec: dist/compatible/openapi-3.0.yaml +outputDir: typescript_fetch_generated + +legacyDiscriminatorBehavior: false