Skip to content

Commit d0dcef3

Browse files
authored
Let there be light (#1)
1 parent beaeeb3 commit d0dcef3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+10445
-0
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: "setup-uv-env"
2+
description: "Composite action to setup the Python and uv environment."
3+
4+
inputs:
5+
python-version:
6+
required: false
7+
description: "The python version to use"
8+
default: "3.11"
9+
is-server:
10+
required: false
11+
description: "Whether this is a server package"
12+
default: "false"
13+
working-directory:
14+
required: false
15+
description: "Working directory for the installation (used for servers)"
16+
default: "."
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Install uv
22+
uses: astral-sh/setup-uv@v5
23+
with:
24+
python-version: ${{ inputs.python-version }}
25+
26+
- name: Install server dependencies
27+
if: inputs.is-server == 'true'
28+
working-directory: ${{ inputs.working-directory }}
29+
run: |
30+
echo "Installing server dependencies for ${{ inputs.working-directory }}"
31+
uv venv --python ${{ inputs.python-version}}
32+
source .venv/bin/activate
33+
make install
34+
shell: bash
35+
36+
- name: Install libs dependencies
37+
if: inputs.is-server != 'true'
38+
working-directory: ${{ inputs.working-directory }}
39+
run: uv sync --dev --extra all
40+
shell: bash
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# This workflow is used to release packages to PyPI when its
2+
# pyproject.toml version is changed or a new package is added.
3+
4+
name: Release on Version Change
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
detect-version-changes:
13+
runs-on: ubuntu-latest
14+
outputs:
15+
matrix: ${{ steps.set-matrix.outputs.matrix }}
16+
has-changes: ${{ steps.set-matrix.outputs.has-changes }}
17+
steps:
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
fetch-depth: 0
22+
23+
- name: Get changed files
24+
id: changed-files
25+
uses: tj-actions/changed-files@ed68ef82c095e0d48ec87eccea555d944a631a4c # v46
26+
with:
27+
files: |
28+
**/pyproject.toml
29+
30+
- name: Check for version changes or new packages
31+
id: check-versions
32+
if: steps.changed-files.outputs.any_changed == 'true'
33+
run: |
34+
./.github/scripts/check-version-changes.sh "${{ steps.changed-files.outputs.all_changed_files }}"
35+
36+
- name: Set matrix
37+
id: set-matrix
38+
run: |
39+
packages='${{ steps.check-versions.outputs.packages }}'
40+
if [ -z "$packages" ] || [ "$packages" = "[]" ]; then
41+
echo "has-changes=false" >> $GITHUB_OUTPUT
42+
echo "matrix={\"include\":[]}" >> $GITHUB_OUTPUT
43+
else
44+
echo "has-changes=true" >> $GITHUB_OUTPUT
45+
# Create matrix with package directories
46+
matrix=$(echo "$packages" | jq -c '{include: [.[] | {package: .}]}')
47+
echo "matrix=$matrix" >> $GITHUB_OUTPUT
48+
echo "Matrix: $matrix"
49+
fi
50+
51+
build-and-test:
52+
needs: detect-version-changes
53+
if: needs.detect-version-changes.outputs.has-changes == 'true'
54+
runs-on: ubuntu-latest
55+
strategy:
56+
matrix: ${{ fromJson(needs.detect-version-changes.outputs.matrix) }}
57+
permissions:
58+
contents: write
59+
packages: write
60+
steps:
61+
- name: Checkout code
62+
uses: actions/checkout@v4
63+
with:
64+
fetch-depth: 0
65+
66+
- name: Extract package name and version
67+
working-directory: ${{ matrix.package }}
68+
run: |
69+
# Extract package name
70+
PACKAGE_NAME=$(grep -m1 '^name = ' pyproject.toml | cut -d'"' -f2)
71+
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
72+
73+
# Extract version
74+
VERSION=$(grep -m1 '^version = ' pyproject.toml | cut -d'"' -f2)
75+
echo "VERSION=$VERSION" >> $GITHUB_ENV
76+
77+
echo "Building $PACKAGE_NAME version $VERSION"
78+
79+
- name: Set up the environment
80+
uses: ./.github/actions/setup-uv-env
81+
with:
82+
python-version: "3.10"
83+
is-server: ${{ startsWith(matrix.package, 'servers/') }}
84+
working-directory: ${{ matrix.package }}
85+
86+
- name: Build release distributions
87+
working-directory: ${{ matrix.package }}
88+
run: |
89+
uv build --wheel --out-dir dist | tee build.log
90+
91+
# Verify build artifacts
92+
ls -la dist/
93+
echo "Built artifacts for ${{ env.PACKAGE_NAME }} v${{ env.VERSION }}"
94+
95+
- name: Upload release distributions
96+
uses: actions/upload-artifact@v4
97+
with:
98+
name: release-dists-${{ env.PACKAGE_NAME }}-${{ env.VERSION }}
99+
path: ${{ matrix.package }}/dist/
100+
101+
pypi-publish:
102+
needs: [detect-version-changes, build-and-test]
103+
if: needs.detect-version-changes.outputs.has-changes == 'true'
104+
runs-on: ubuntu-latest
105+
strategy:
106+
matrix: ${{ fromJson(needs.detect-version-changes.outputs.matrix) }}
107+
permissions:
108+
id-token: write
109+
contents: read
110+
steps:
111+
- name: Checkout code
112+
uses: actions/checkout@v4
113+
with:
114+
fetch-depth: 0
115+
116+
- name: Extract package name and version
117+
working-directory: ${{ matrix.package }}
118+
run: |
119+
PACKAGE_NAME=$(grep -m1 '^name = ' pyproject.toml | cut -d'"' -f2)
120+
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
121+
122+
VERSION=$(grep -m1 '^version = ' pyproject.toml | cut -d'"' -f2)
123+
echo "VERSION=$VERSION" >> $GITHUB_ENV
124+
125+
- name: Retrieve release distributions
126+
uses: actions/download-artifact@v4
127+
with:
128+
name: release-dists-${{ env.PACKAGE_NAME }}-${{ env.VERSION }}
129+
path: dist/
130+
131+
- name: Publish release distributions to PyPI
132+
uses: pypa/gh-action-pypi-publish@release/v1
133+
134+
- name: Send status to Slack
135+
if: always()
136+
uses: slackapi/[email protected]
137+
with:
138+
webhook: ${{ secrets.PACKAGE_RELEASE_SLACK_WEBHOOK_URL }}
139+
webhook-type: webhook-trigger
140+
payload: |
141+
{
142+
"status": "${{ (job.status == 'failure' || job.status == 'cancelled') && 'Failed' || 'Success' }}",
143+
"package": "${{ env.PACKAGE_NAME }}",
144+
"version": "${{ env.VERSION }}",
145+
"url": "${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
146+
}

.github/workflows/test-servers.yml

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
name: Test Servers
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
types: [opened, synchronize, reopened, ready_for_review]
9+
10+
jobs:
11+
setup:
12+
runs-on: ubuntu-latest
13+
outputs:
14+
servers_with_gha_secrets: ${{ steps.load_servers.outputs.servers_with_gha_secrets }}
15+
servers_without_gha_secrets: ${{ steps.load_servers.outputs.servers_without_gha_secrets }}
16+
steps:
17+
- name: Check out
18+
uses: actions/checkout@v4
19+
20+
- name: determine servers with and without GHA secrets
21+
id: load_servers
22+
run: |
23+
# Find all directories in servers/ that have a pyproject.toml
24+
SERVERS=$(find servers -maxdepth 1 -type d -not -name "servers" -exec test -f {}/pyproject.toml \; -exec basename {} \; | jq -R -s -c 'split("\n")[:-1]')
25+
SERVERS_WITH_GHA_SECRETS='[]'
26+
SERVERS_WITHOUT_GHA_SECRETS=$(echo "$SERVERS" | jq -c --argjson with "$SERVERS_WITH_GHA_SECRETS" '[.[] | select(. as $t | $with | index($t) | not)]')
27+
echo "Found servers: $SERVERS"
28+
echo "Found servers without GHA secrets: $SERVERS_WITHOUT_GHA_SECRETS"
29+
echo "Found servers with GHA secrets: $SERVERS_WITH_GHA_SECRETS"
30+
echo "servers_without_gha_secrets=$SERVERS_WITHOUT_GHA_SECRETS" >> $GITHUB_OUTPUT
31+
echo "servers_with_gha_secrets=$SERVERS_WITH_GHA_SECRETS" >> $GITHUB_OUTPUT
32+
33+
test-servers:
34+
needs: setup
35+
runs-on: ubuntu-latest
36+
strategy:
37+
matrix:
38+
server: ${{ fromJson(needs.setup.outputs.servers_without_gha_secrets) }}
39+
fail-fast: true
40+
steps:
41+
- name: Check out
42+
uses: actions/checkout@v4
43+
44+
- name: Checkout arcade-mcp
45+
run: |
46+
cd ..
47+
git clone https://github.com/ArcadeAI/arcade-mcp.git
48+
49+
- name: Set up the environment
50+
uses: ./.github/actions/setup-uv-env
51+
with:
52+
working-directory: ../arcade-mcp
53+
54+
- name: Install server dependencies
55+
working-directory: servers/${{ matrix.server }}
56+
run: uv pip install --pre -e ".[dev]"
57+
58+
- name: Check server
59+
working-directory: servers/${{ matrix.server }}
60+
run: |
61+
uv run --active pre-commit run -a
62+
uv run --active mypy --config-file=pyproject.toml
63+
64+
- name: Test stand-alone servers (no secrets)
65+
working-directory: servers/${{ matrix.server }}
66+
run: |
67+
# Run pytest and capture exit code
68+
uv run --active pytest -W ignore -v --cov=arcade_${{ matrix.server }} --cov-report=xml || EXIT_CODE=$?
69+
70+
if [ "${EXIT_CODE:-0}" -eq 5 ]; then
71+
echo "No tests found for server ${{ matrix.server }}, skipping..."
72+
exit 0
73+
elif [ "${EXIT_CODE:-0}" -ne 0 ]; then
74+
exit ${EXIT_CODE}
75+
fi
76+
77+
test-servers-with-gha-secrets:
78+
needs: setup
79+
runs-on: ubuntu-latest
80+
if: ${{ needs.setup.outputs.servers_with_gha_secrets != '[]' }}
81+
strategy:
82+
matrix:
83+
server: ${{ fromJson(needs.setup.outputs.servers_with_gha_secrets) }}
84+
fail-fast: true
85+
steps:
86+
- name: Check out
87+
uses: actions/checkout@v4
88+
89+
- name: Checkout arcade-mcp
90+
run: |
91+
cd ..
92+
git clone https://github.com/ArcadeAI/arcade-mcp.git
93+
94+
- name: Set up the environment
95+
uses: ./.github/actions/setup-uv-env
96+
with:
97+
working-directory: ../arcade-mcp
98+
99+
- name: Install server dependencies
100+
working-directory: servers/${{ matrix.server }}
101+
run: uv pip install -e ".[dev]"
102+
103+
- name: Check server
104+
working-directory: servers/${{ matrix.server }}
105+
run: |
106+
uv run --active pre-commit run -a
107+
uv run --active mypy --config-file=pyproject.toml
108+
109+
- name: Test stand-alone servers (with secrets)
110+
if: |
111+
!github.event.pull_request.head.repo.fork
112+
working-directory: servers/${{ matrix.server }}
113+
env:
114+
TEST_POSTGRES_DATABASE_CONNECTION_STRING: ${{ secrets.TEST_POSTGRES_DATABASE_CONNECTION_STRING }} # TODO: dynamically only load the `TEST_${{ matrix.server }}_DATABASE_CONNECTION_STRING secret`
115+
run: |
116+
# Run pytest and capture exit code
117+
uv run --active pytest -W ignore -v --cov=arcade_${{ matrix.server }} --cov-report=xml || EXIT_CODE=$?
118+
119+
if [ "${EXIT_CODE:-0}" -eq 5 ]; then
120+
echo "No tests found for server ${{ matrix.server }}, skipping..."
121+
exit 0
122+
elif [ "${EXIT_CODE:-0}" -ne 0 ]; then
123+
exit ${EXIT_CODE}
124+
fi

servers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
arcade-arcade-engine-api
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
files: ^.*/arcade_arcade_engine_api/.*
2+
repos:
3+
- repo: https://github.com/pre-commit/pre-commit-hooks
4+
rev: "v4.4.0"
5+
hooks:
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: check-toml
9+
- id: check-yaml
10+
- id: end-of-file-fixer
11+
- id: trailing-whitespace
12+
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.6.7
15+
hooks:
16+
- id: ruff
17+
args: [--fix]
18+
- id: ruff-format
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
target-version = "py310"
2+
line-length = 100
3+
fix = true
4+
5+
[lint]
6+
select = [
7+
# flake8-2020
8+
"YTT",
9+
# flake8-bandit
10+
"S",
11+
# flake8-bugbear
12+
"B",
13+
# flake8-builtins
14+
"A",
15+
# flake8-comprehensions
16+
"C4",
17+
# flake8-debugger
18+
"T10",
19+
# flake8-simplify
20+
"SIM",
21+
# isort
22+
"I",
23+
# mccabe
24+
"C90",
25+
# pycodestyle
26+
"E", "W",
27+
# pyflakes
28+
"F",
29+
# pygrep-hooks
30+
"PGH",
31+
# pyupgrade
32+
"UP",
33+
# ruff
34+
"RUF",
35+
# tryceratops
36+
"TRY",
37+
]
38+
39+
[lint.per-file-ignores]
40+
"**/tests/*" = ["S101"]
41+
42+
[format]
43+
preview = true
44+
skip-magic-trailing-comma = false

0 commit comments

Comments
 (0)