Skip to content

Regenerate Python Bindings #42

Regenerate Python Bindings

Regenerate Python Bindings #42

Workflow file for this run

name: Regenerate Python Bindings
on:
schedule:
- cron: '0 6 * * *' # Daily at 6am UTC
workflow_dispatch: # Manual trigger from GitHub UI
permissions:
contents: write
jobs:
regenerate:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: pip install websockets
- name: Fetch STDB schema
env:
STDB_TOKEN: ${{ secrets.STDB_TOKEN }}
run: |
curl -sf \
"https://bitcraft-early-access.spacetimedb.com/v1/database/bitcraft-live-14/schema?version=9" \
-H "Authorization: $STDB_TOKEN" \
-o schema_region.json
curl -sf \
"https://bitcraft-early-access.spacetimedb.com/v1/database/bitcraft-live-global/schema?version=9" \
-H "Authorization: $STDB_TOKEN" \
-o schema_global.json
- name: Generate graphs from schema
run: |
python schema_to_graph.py \
--region schema_region.json \
--global schema_global.json \
--out-region region_graph.json \
--out-global global_graph.json
- name: Generate Python bindings
run: |
python generate_bindings.py \
--region-graph region_graph.json \
--global-graph global_graph.json \
--out bitcraft_types
- name: Run test suite
id: tests
continue-on-error: true
env:
PYTHONUNBUFFERED: "1"
run: |
python test_bindings.py \
--region-graph region_graph.json \
--global-graph global_graph.json \
--token "${{ secrets.STDB_TOKEN }}" \
--out results.json \
--delay 0.1 \
--timeout 60 \
--skip-tables \
ActionLogData \
ActionLogState \
ActiveEnvironmentBuffState \
AIDebugState \
AiDebugState \
AuctionListingState \
AutoClaimState \
BuildingSpawnDesc \
ChestRarityDesc \
CrumbTrailState \
DiscoveryTriggerDesc \
EmpireLogState \
EnemyScalingState \
GrantedHubItemState \
KnowledgeScrollTypeDesc \
KnowledgeState \
LootRarityDesc \
ModConsequenceState \
ModEnforcementConfigState \
ModFlagLevelThresholdState \
ModFlaggedWordState \
ModReplacementTextState \
ModReportConfigState \
ModThresholdState \
ModViolationState \
ModWordReplacementState \
MoveValidationParamsDesc \
MoveValidationStrikeCounterState \
OnboardingRewardDesc \
ParametersPlayerMoveDesc \
PrivateParametersDesc \
ResourceGrowthRecipeDesc \
SingleResourceToClumpDesc \
StageRewardsDesc \
PartialExperienceState \
PlayerReportState \
PlayerTimestampState \
PreviousEmpireNameState \
PreviousPlayerSkillsState \
PreviousPlayerUsernameState \
RegionModerationConfigState \
RezSickLongTermState \
StarvingPlayerState \
UnclaimedCollectiblesState \
UnclaimedShardsState \
UserAuthenticationState \
UserCreationTimestampState \
UserModerationState \
UserPreviousRegionState
- name: Summarise test results
id: summary
run: |
python - <<'EOF'
import json, sys, os
with open('results.json') as f:
results = json.load(f)
passed = sum(1 for r in results if r['result'] == 'PASS')
skipped = sum(1 for r in results if r['result'] == 'SKIP')
failed = sum(1 for r in results if r['result'] == 'FAIL')
print(f'Test results: {passed} passed, {skipped} skipped, {failed} failed')
with open(os.environ['GITHUB_OUTPUT'], 'a') as f:
f.write(f'passed={passed}\n')
f.write(f'skipped={skipped}\n')
f.write(f'failed={failed}\n')
EOF
env:
GITHUB_OUTPUT: ${{ env.GITHUB_OUTPUT }}
- name: Commit updated bindings
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add bitcraft_types/
if git diff --staged --quiet; then
echo "No changes to bindings — skipping commit."
else
TEST_SUMMARY="${{ steps.tests.outcome }} (${{ steps.summary.outputs.passed }} passed, ${{ steps.summary.outputs.skipped }} skipped, ${{ steps.summary.outputs.failed }} failed)"
git commit -m "Auto-regenerate bindings $(date -u +%Y-%m-%d) [tests: ${TEST_SUMMARY}]"
git push origin main
fi