diff --git a/.github/workflows/simple_test.yaml b/.github/workflows/simple_test.yaml new file mode 100644 index 00000000..04acca27 --- /dev/null +++ b/.github/workflows/simple_test.yaml @@ -0,0 +1,56 @@ +name: simple_test + +on: + push: + branches: + - conor/com-6015-run-a-single-workflow-against-staging + workflow_dispatch: + inputs: + environment: + description: "Environment to test" + required: true + type: string + + +permissions: + id-token: write + contents: write + +env: + AWS_ECR_STS_ROLE: arn:aws:iam::688567264391:role/DojoApiCIRole + + +jobs: + # Print environment parameter with emojis + print-env: + runs-on: ubuntu-latest + steps: + - name: Print environment parameter + run: | + echo "🚀 Starting workflow..." + echo "📋 Environment parameter: ${{ github.event.inputs.environment }}" + echo "⚙️ Workflow triggered with environment: ${{ github.event.inputs.environment || 'default' }}" + echo "✅ Environment validation complete!" + + test: + runs-on: ubuntu-latest + needs: print-env + steps: + - uses: actions/checkout@v4 + - name: Setup Python + uses: actions/setup-python@v4 + with: + python-version: '3.11' + - name: Install uv + run: pip install uv + - name: Install dependencies + run: | + cd test + uv sync + - name: Run test + env: + COMPASS_API_KEY: ${{ secrets.COMPASS_API_KEY }} + run: | + cd test + uv run python main.py + \ No newline at end of file diff --git a/.github/workflows/simple_test__staging.yaml b/.github/workflows/simple_test__staging.yaml new file mode 100644 index 00000000..c2414e2d --- /dev/null +++ b/.github/workflows/simple_test__staging.yaml @@ -0,0 +1,146 @@ +name: simple_test_on_staging + +on: + push: + branches: + - conor/com-6015-run-a-single-workflow-against-staging + + workflow_dispatch: + inputs: + environment: + description: "Environment to test" + required: true + type: string + + workflow_call: + inputs: + environment: + description: "Environment to test" + required: true + type: string + + +permissions: + id-token: write + contents: write + +env: + AWS_ECR_STS_ROLE: arn:aws:iam::688567264391:role/DojoApiCIRole + + +jobs: + # Print environment parameter with emojis + print-env: + runs-on: ubuntu-latest + steps: + - name: Print environment parameter + run: | + echo "🚀 Starting workflow..." + echo "📋 Environment parameter: ${{ github.event.inputs.environment }}" + echo "⚙️ Workflow triggered with environment: ${{ github.event.inputs.environment || 'default' }}" + echo "✅ Environment validation complete!" + + validate-environment: + runs-on: ubuntu-latest + outputs: + environment: ${{ steps.validate.outputs.environment }} + steps: + - name: Validate environment input + id: validate + run: | + if [[ "${{ github.event_name }}" == "workflow_dispatch" || "${{ github.event_name }}" == "workflow_call" ]]; then + ENVIRONMENT="${{ inputs.environment }}" + else + ENVIRONMENT="local" + fi + if [[ "$ENVIRONMENT" != "staging" && "$ENVIRONMENT" != "prod" && "$ENVIRONMENT" != "local" ]]; then + echo "❌ Error: Invalid environment '$ENVIRONMENT'. Must be 'staging' or 'prod' or 'local'." + exit 1 + fi + echo "✅ Environment '$ENVIRONMENT' is valid" + echo "environment=$ENVIRONMENT" >> $GITHUB_OUTPUT + + set-versions: + needs: [validate-environment] + runs-on: ubuntu-latest + outputs: + npm_package_version: ${{ steps.set-versions.outputs.npm_package_version }} + uv_package_version: ${{ steps.set-versions.outputs.uv_package_version }} + steps: + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: "20" + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Set versions + id: set-versions + run: | + if [[ "${{ needs.validate-environment.outputs.environment }}" == "staging" ]]; then + NPM_PACKAGE_VERSION=$(npm view @compass-labs/api-sdk versions --json | jq -r '.[]' | grep -E 'rc|alpha|beta' | sort -V | tail -1) + UV_PACKAGE_VERSION="$(curl -s https://pypi.org/pypi/compass-api-sdk/json | jq -r '.releases | keys | .[]' | grep -E 'rc|a|b|dev' | sort -V | tail -1)" + else + NPM_PACKAGE_VERSION="latest" + UV_PACKAGE_VERSION="latest" + fi + + echo "npm_package_version=$NPM_PACKAGE_VERSION" >> $GITHUB_OUTPUT + echo "uv_package_version=$UV_PACKAGE_VERSION" >> $GITHUB_OUTPUT + + + + test: + needs: [validate-environment, set-versions, print-env] + runs-on: ubuntu-latest + + env: + COMPASS_API_KEY: ${{ secrets.COMPASS_API_KEY }} + PRIVATE_KEY: ${{ secrets.PRIVATE_KEY }} + ARBITRUM_RPC_URL: http://localhost:8547 + SERVER_URL: http://localhost:80 + NPM_PACKAGE_VERSION: ${{ needs.set-versions.outputs.npm_package_version }} + UV_PACKAGE_VERSION: ${{ needs.set-versions.outputs.uv_package_version }} + + steps: + - name: Checkout repository + uses: actions/checkout@v3 + + - name: Install uv + run: curl -LsSf https://astral.sh/uv/install.sh | sh + + - name: Start up full local API and anvil + uses: ./.github/actions/local_anvil_and_api + id: local_anvil_and_api + with: + ethereum_rpc_url: ${{ secrets.ETHEREUM_MAINNET_RPC_URL }} + arbitrum_rpc_url: ${{ secrets.ARBITRUM_MAINNET_RPC_URL }} + base_rpc_url: ${{ secrets.BASE_MAINNET_RPC_URL }} + private_key: ${{ secrets.PRIVATE_KEY }} + mono_app_id: ${{ secrets.MONOREPOAPP_ID }} + mono_app_private_key: ${{ secrets.MONOREPOAPP_PRIVATE_KEY }} + fund_amount_eth: "10" + environment: ${{ needs.validate-environment.outputs.environment }} + aws_ecr_sts_role: ${{ env.AWS_ECR_STS_ROLE }} + ecr_image_uri: 688567264391.dkr.ecr.eu-west-2.amazonaws.com/dojo_api + + - name: Install dependencies + working-directory: test + run: | + if [[ "$UV_PACKAGE_VERSION" != "latest" ]]; then + echo "Installing compass-api-sdk==$UV_PACKAGE_VERSION" + uv add compass-api-sdk==$UV_PACKAGE_VERSION + fi + uv sync + uv pip freeze + + - name: Run example + working-directory: test + run: uv run python main.py + + +# run: | +# cd test +# uv run python main.py + \ No newline at end of file diff --git a/.github/workflows/test_usecases_v0.yml b/.github/workflows/test_usecases_v0.yml index 57e35d68..91c3aac3 100644 --- a/.github/workflows/test_usecases_v0.yml +++ b/.github/workflows/test_usecases_v0.yml @@ -1,23 +1,23 @@ -name: test_usecases_v_zero +# name: test_usecases_v_zero -on: - schedule: - # Runs at 00:00 UTC every day - - cron: "0 0 * * *" - pull_request: - branches: - - main - workflow_dispatch: +# on: +# schedule: +# # Runs at 00:00 UTC every day +# - cron: "0 0 * * *" +# pull_request: +# branches: +# - main +# workflow_dispatch: -permissions: - id-token: write - contents: write +# permissions: +# id-token: write +# contents: write -jobs: - do-nothing: - runs-on: ubuntu-latest +# jobs: +# do-nothing: +# runs-on: ubuntu-latest - steps: - - name: Do nothing - run: | - echo "I am doing nothing" +# steps: +# - name: Do nothing +# run: | +# echo "I am doing nothing" diff --git a/.github/workflows/test_usecases_v1.yml b/.github/workflows/test_usecases_v1.yml index b0d08099..baf77522 100644 --- a/.github/workflows/test_usecases_v1.yml +++ b/.github/workflows/test_usecases_v1.yml @@ -4,9 +4,9 @@ on: schedule: # Runs at 00:00 UTC every day - cron: "0 0 * * *" - pull_request: - branches: - - main +# pull_request: +# branches: +# - main workflow_dispatch: inputs: environment: @@ -708,4 +708,4 @@ jobs: run: | curl -X POST "https://allquiet.app/api/webhook/829f846c-4dfa-4a58-ab33-eafae34a57c9" \ -H "Content-Type: application/json" \ - -d '{"status": "Open", "severity": "Critical", "message": "GitHub workflow failed", "run_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' + -d '{"status": "Open", "severity": "Critical", "message": "GitHub workflow failed", "run_url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"}' \ No newline at end of file diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..e69de29b diff --git a/test/main.py b/test/main.py new file mode 100644 index 00000000..a8910aea --- /dev/null +++ b/test/main.py @@ -0,0 +1,27 @@ +import os +from compass_api_sdk import CompassAPI, models + +print("Hello from test!") + +# Load and print the API key +COMPASS_API_KEY = os.getenv("COMPASS_API_KEY") +if COMPASS_API_KEY: + print(f"API Key loaded: {COMPASS_API_KEY[:10]}...") + +SERVER_URL = os.getenv("SERVER_URL") +if SERVER_URL: + print(f"API Key loaded: {SERVER_URL[:10]}...") + + # Test Compass API - Aave Supported Tokens] + +compass = CompassAPI(api_key_auth=COMPASS_API_KEY, server_url=SERVER_URL) + +res = compass.aave_v3.aave_aave_supported_tokens( + chain=models.V1AaveAaveSupportedTokensChain.ARBITRUM, + server_url=SERVER_URL +) +print("API call successful!") +print(f"Found {len(res.tokens)} supported tokens") +print(res.json()) + + diff --git a/test/pyproject.toml b/test/pyproject.toml new file mode 100644 index 00000000..758995db --- /dev/null +++ b/test/pyproject.toml @@ -0,0 +1,9 @@ +[project] +name = "test" +version = "0.1.0" +description = "Add your description here" +readme = "README.md" +requires-python = ">=3.9" +dependencies = [ + "compass-api-sdk" +] diff --git a/v1/test_sdk_snippets/01.py b/v1/test_sdk_snippets/01.py new file mode 100644 index 00000000..e88bb05b --- /dev/null +++ b/v1/test_sdk_snippets/01.py @@ -0,0 +1,64 @@ +# v1/test_sdk_snippets/run_endpoint.py + +from compass_api_sdk import CompassAPI, models + + +with CompassAPI( + api_key_auth="Zp69nDSOYw9P02FiVnhZBaJkvkRcz0Pg1U7cjnhr", +) as compass_api: + + res = compass_api.aave_v3.aave_aave_supported_tokens(chain=models.V1AaveAaveSupportedTokensChain.ARBITRUM) + + # Handle response + print(res) + + +import os +import sys +import requests +from dotenv import load_dotenv +import subprocess +import shlex + +load_dotenv() + +COMPASS_API_KEY = os.getenv("COMPASS_API_KEY") +ENDPOINT = os.getenv("ENDPOINT") +print([ENDPOINT]) +API_URL = "https://spec.speakeasy.com/compasslabs/api/compass-api-with-code-samples" +SPEC = requests.get(API_URL).json() + +# get python code sample for given path +methods = SPEC["paths"].get(ENDPOINT) +if not methods: + raise ValueError(f"Endpoint not found in spec: {ENDPOINT!r}") + +SNIPPET = None +for method in ("get", "post"): + samples = (methods.get(method, {}) or {}).get("x-codeSamples") or [] + for s in samples: + if (s.get("lang") or "").lower().startswith("python"): + SNIPPET = s["source"] + break + if SNIPPET: + break + +if not SNIPPET: + raise ValueError(f"No Python code sample found for endpoint: {ENDPOINT!r}") + + +print(f"--- Running python SDK snippet for {ENDPOINT} ---") + +SNIPPET = SNIPPET.replace("", COMPASS_API_KEY) +# Write snippet to a simple file and run it +script_path = os.path.join(os.getcwd(), "snippet.py") +with open(script_path, "w", encoding="utf-8") as f: + f.write(SNIPPET) + +try: + cmd = f"{shlex.quote(sys.executable)} {shlex.quote(script_path)}" + subprocess.run(cmd, shell=True, check=True) + print(f"✅ PASS: {ENDPOINT}") +except subprocess.CalledProcessError as e: + print(f"❌ FAIL: {ENDPOINT} – exit code {e.returncode}", file=sys.stderr) + sys.exit(e.returncode) diff --git a/v1/test_sdk_snippets/snippet.py b/v1/test_sdk_snippets/snippet.py new file mode 100644 index 00000000..ac791313 --- /dev/null +++ b/v1/test_sdk_snippets/snippet.py @@ -0,0 +1,11 @@ +from compass_api_sdk import CompassAPI, models + + +with CompassAPI( + api_key_auth="Zp69nDSOYw9P02FiVnhZBaJkvkRcz0Pg1U7cjnhr", +) as compass_api: + + res = compass_api.aave_v3.aave_aave_supported_tokens(chain=models.V1AaveAaveSupportedTokensChain.ARBITRUM) + + # Handle response + print(res) \ No newline at end of file diff --git a/v1/test_sdk_snippets/snippet.ts b/v1/test_sdk_snippets/snippet.ts new file mode 100644 index 00000000..ac791313 --- /dev/null +++ b/v1/test_sdk_snippets/snippet.ts @@ -0,0 +1,11 @@ +from compass_api_sdk import CompassAPI, models + + +with CompassAPI( + api_key_auth="Zp69nDSOYw9P02FiVnhZBaJkvkRcz0Pg1U7cjnhr", +) as compass_api: + + res = compass_api.aave_v3.aave_aave_supported_tokens(chain=models.V1AaveAaveSupportedTokensChain.ARBITRUM) + + # Handle response + print(res) \ No newline at end of file