direitos-br 0.17.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. direitos_br-0.17.0/.dockerignore +18 -0
  2. direitos_br-0.17.0/.github/dependabot.yml +22 -0
  3. direitos_br-0.17.0/.github/workflows/annual-normative-check.yml +125 -0
  4. direitos_br-0.17.0/.github/workflows/ci.yml +46 -0
  5. direitos_br-0.17.0/.github/workflows/cloudrun.yml +104 -0
  6. direitos_br-0.17.0/.github/workflows/etl-saude-monthly.yml +87 -0
  7. direitos_br-0.17.0/.github/workflows/pages.yml +59 -0
  8. direitos_br-0.17.0/.github/workflows/publish.yml +147 -0
  9. direitos_br-0.17.0/.gitignore +23 -0
  10. direitos_br-0.17.0/CHANGELOG.md +250 -0
  11. direitos_br-0.17.0/Dockerfile +36 -0
  12. direitos_br-0.17.0/LICENSE +21 -0
  13. direitos_br-0.17.0/PKG-INFO +423 -0
  14. direitos_br-0.17.0/README.md +392 -0
  15. direitos_br-0.17.0/deploy/cloudrun-cleanup.sh +164 -0
  16. direitos_br-0.17.0/deploy/cloudrun-deploy.sh +31 -0
  17. direitos_br-0.17.0/deploy/cloudrun-setup-wif.sh +155 -0
  18. direitos_br-0.17.0/docs/CLOUD_RUN_AND_TELEGRAM.md +101 -0
  19. direitos_br-0.17.0/docs/MCP_REGISTRY.md +46 -0
  20. direitos_br-0.17.0/docs/WBS.md +129 -0
  21. direitos_br-0.17.0/etl/__init__.py +1 -0
  22. direitos_br-0.17.0/etl/saude/README.md +38 -0
  23. direitos_br-0.17.0/etl/saude/__init__.py +9 -0
  24. direitos_br-0.17.0/etl/saude/anvisa.py +126 -0
  25. direitos_br-0.17.0/etl/saude/build.py +280 -0
  26. direitos_br-0.17.0/etl/saude/cnes.py +190 -0
  27. direitos_br-0.17.0/etl/saude/schema.py +152 -0
  28. direitos_br-0.17.0/pyproject.toml +92 -0
  29. direitos_br-0.17.0/scripts/__init__.py +1 -0
  30. direitos_br-0.17.0/scripts/check_normative_schedule.py +219 -0
  31. direitos_br-0.17.0/scripts/check_versions.py +98 -0
  32. direitos_br-0.17.0/scripts/export_web_params.py +132 -0
  33. direitos_br-0.17.0/scripts/prune_data_releases.py +110 -0
  34. direitos_br-0.17.0/server.json +29 -0
  35. direitos_br-0.17.0/src/direitos_br/__init__.py +289 -0
  36. direitos_br-0.17.0/src/direitos_br/bot/__init__.py +40 -0
  37. direitos_br-0.17.0/src/direitos_br/bot/engine.py +1479 -0
  38. direitos_br-0.17.0/src/direitos_br/bot/telegram.py +324 -0
  39. direitos_br-0.17.0/src/direitos_br/bot/whatsapp.py +259 -0
  40. direitos_br-0.17.0/src/direitos_br/cli.py +2420 -0
  41. direitos_br-0.17.0/src/direitos_br/core/__init__.py +44 -0
  42. direitos_br-0.17.0/src/direitos_br/core/citations.py +92 -0
  43. direitos_br-0.17.0/src/direitos_br/core/money.py +27 -0
  44. direitos_br-0.17.0/src/direitos_br/core/params_loader.py +120 -0
  45. direitos_br-0.17.0/src/direitos_br/core/registry.py +111 -0
  46. direitos_br-0.17.0/src/direitos_br/core/zero_pii.py +97 -0
  47. direitos_br-0.17.0/src/direitos_br/data/2026-01.toml +547 -0
  48. direitos_br-0.17.0/src/direitos_br/data/2026-10.toml +547 -0
  49. direitos_br-0.17.0/src/direitos_br/data/2027-01.toml +555 -0
  50. direitos_br-0.17.0/src/direitos_br/data/__init__.py +1 -0
  51. direitos_br-0.17.0/src/direitos_br/domains/__init__.py +25 -0
  52. direitos_br-0.17.0/src/direitos_br/domains/consumidor/__init__.py +59 -0
  53. direitos_br-0.17.0/src/direitos_br/domains/consumidor/cli.py +607 -0
  54. direitos_br-0.17.0/src/direitos_br/domains/consumidor/data/2026-01.toml +107 -0
  55. direitos_br-0.17.0/src/direitos_br/domains/consumidor/data/2026-10.toml +107 -0
  56. direitos_br-0.17.0/src/direitos_br/domains/consumidor/data/2027-01.toml +107 -0
  57. direitos_br-0.17.0/src/direitos_br/domains/consumidor/data/__init__.py +1 -0
  58. direitos_br-0.17.0/src/direitos_br/domains/consumidor/engine.py +86 -0
  59. direitos_br-0.17.0/src/direitos_br/domains/consumidor/mcp_tools.py +184 -0
  60. direitos_br-0.17.0/src/direitos_br/domains/consumidor/models.py +603 -0
  61. direitos_br-0.17.0/src/direitos_br/domains/consumidor/params.py +189 -0
  62. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/__init__.py +17 -0
  63. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/anac.py +436 -0
  64. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/anatel.py +321 -0
  65. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/aneel.py +330 -0
  66. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/ans.py +356 -0
  67. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/cdc.py +371 -0
  68. direitos_br-0.17.0/src/direitos_br/domains/consumidor/rules/jec.py +70 -0
  69. direitos_br-0.17.0/src/direitos_br/domains/saude/__init__.py +81 -0
  70. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/__init__.py +54 -0
  71. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/anvisa.py +268 -0
  72. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/cli.py +120 -0
  73. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/cnes.py +195 -0
  74. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/models.py +284 -0
  75. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/store.py +162 -0
  76. direitos_br-0.17.0/src/direitos_br/domains/saude/catalog/sync.py +259 -0
  77. direitos_br-0.17.0/src/direitos_br/domains/saude/cli.py +607 -0
  78. direitos_br-0.17.0/src/direitos_br/domains/saude/data/2026-01.toml +78 -0
  79. direitos_br-0.17.0/src/direitos_br/domains/saude/data/2026-10.toml +77 -0
  80. direitos_br-0.17.0/src/direitos_br/domains/saude/data/2027-01.toml +77 -0
  81. direitos_br-0.17.0/src/direitos_br/domains/saude/data/__init__.py +1 -0
  82. direitos_br-0.17.0/src/direitos_br/domains/saude/engine.py +60 -0
  83. direitos_br-0.17.0/src/direitos_br/domains/saude/mcp_tools.py +205 -0
  84. direitos_br-0.17.0/src/direitos_br/domains/saude/models.py +430 -0
  85. direitos_br-0.17.0/src/direitos_br/domains/saude/params.py +126 -0
  86. direitos_br-0.17.0/src/direitos_br/domains/saude/rules/__init__.py +19 -0
  87. direitos_br-0.17.0/src/direitos_br/domains/saude/rules/falta_sus.py +441 -0
  88. direitos_br-0.17.0/src/direitos_br/domains/saude/rules/farmacia_popular.py +507 -0
  89. direitos_br-0.17.0/src/direitos_br/domains/saude/rules/rename.py +411 -0
  90. direitos_br-0.17.0/src/direitos_br/domains/social/__init__.py +48 -0
  91. direitos_br-0.17.0/src/direitos_br/domains/social/mcp_tools.py +684 -0
  92. direitos_br-0.17.0/src/direitos_br/engine.py +493 -0
  93. direitos_br-0.17.0/src/direitos_br/http_app.py +1465 -0
  94. direitos_br-0.17.0/src/direitos_br/mcp_server.py +141 -0
  95. direitos_br-0.17.0/src/direitos_br/models.py +2414 -0
  96. direitos_br-0.17.0/src/direitos_br/openapi_spec.py +1128 -0
  97. direitos_br-0.17.0/src/direitos_br/params.py +726 -0
  98. direitos_br-0.17.0/src/direitos_br/py.typed +0 -0
  99. direitos_br-0.17.0/src/direitos_br/rules/__init__.py +1 -0
  100. direitos_br-0.17.0/src/direitos_br/rules/abono_salarial.py +99 -0
  101. direitos_br-0.17.0/src/direitos_br/rules/acredita.py +266 -0
  102. direitos_br-0.17.0/src/direitos_br/rules/bolsa_familia.py +390 -0
  103. direitos_br-0.17.0/src/direitos_br/rules/bpc_loas.py +404 -0
  104. direitos_br-0.17.0/src/direitos_br/rules/common.py +70 -0
  105. direitos_br-0.17.0/src/direitos_br/rules/direitos_extras.py +271 -0
  106. direitos_br-0.17.0/src/direitos_br/rules/direitos_pcd.py +357 -0
  107. direitos_br-0.17.0/src/direitos_br/rules/educacao_superior.py +388 -0
  108. direitos_br-0.17.0/src/direitos_br/rules/ferias_decimo_terceiro.py +224 -0
  109. direitos_br-0.17.0/src/direitos_br/rules/fgts_saque_aniversario.py +269 -0
  110. direitos_br-0.17.0/src/direitos_br/rules/gas_do_povo.py +117 -0
  111. direitos_br-0.17.0/src/direitos_br/rules/inss_aposentadoria.py +329 -0
  112. direitos_br-0.17.0/src/direitos_br/rules/inss_beneficios.py +384 -0
  113. direitos_br-0.17.0/src/direitos_br/rules/irpf_clt.py +347 -0
  114. direitos_br-0.17.0/src/direitos_br/rules/mcmv.py +331 -0
  115. direitos_br-0.17.0/src/direitos_br/rules/mei_clt_pj.py +409 -0
  116. direitos_br-0.17.0/src/direitos_br/rules/move_brasil.py +362 -0
  117. direitos_br-0.17.0/src/direitos_br/rules/paa.py +295 -0
  118. direitos_br-0.17.0/src/direitos_br/rules/pe_de_meia.py +151 -0
  119. direitos_br-0.17.0/src/direitos_br/rules/programas_regionais.py +304 -0
  120. direitos_br-0.17.0/src/direitos_br/rules/pronaf.py +217 -0
  121. direitos_br-0.17.0/src/direitos_br/rules/reforma_casa_brasil.py +372 -0
  122. direitos_br-0.17.0/src/direitos_br/rules/rescisao_clt.py +262 -0
  123. direitos_br-0.17.0/src/direitos_br/rules/seguro_desemprego.py +126 -0
  124. direitos_br-0.17.0/src/direitos_br/rules/tarifas_sociais.py +205 -0
  125. direitos_br-0.17.0/tests/test_abono_salarial.py +93 -0
  126. direitos_br-0.17.0/tests/test_acredita.py +151 -0
  127. direitos_br-0.17.0/tests/test_bolsa_familia.py +144 -0
  128. direitos_br-0.17.0/tests/test_bots.py +601 -0
  129. direitos_br-0.17.0/tests/test_bpc_loas.py +114 -0
  130. direitos_br-0.17.0/tests/test_consumidor_parity.py +441 -0
  131. direitos_br-0.17.0/tests/test_consumidor_rules.py +526 -0
  132. direitos_br-0.17.0/tests/test_direitos_pcd.py +236 -0
  133. direitos_br-0.17.0/tests/test_educacao_superior.py +195 -0
  134. direitos_br-0.17.0/tests/test_engine_and_cli.py +738 -0
  135. direitos_br-0.17.0/tests/test_ferias_e_13.py +118 -0
  136. direitos_br-0.17.0/tests/test_fgts_saque_aniversario.py +138 -0
  137. direitos_br-0.17.0/tests/test_http_app.py +957 -0
  138. direitos_br-0.17.0/tests/test_inss_aposentadoria.py +94 -0
  139. direitos_br-0.17.0/tests/test_inss_beneficios.py +233 -0
  140. direitos_br-0.17.0/tests/test_irpf_clt.py +210 -0
  141. direitos_br-0.17.0/tests/test_maintenance_scripts.py +100 -0
  142. direitos_br-0.17.0/tests/test_mcmv.py +202 -0
  143. direitos_br-0.17.0/tests/test_mcp_domains.py +471 -0
  144. direitos_br-0.17.0/tests/test_mcp_stdio.py +916 -0
  145. direitos_br-0.17.0/tests/test_mei_clt_pj.py +167 -0
  146. direitos_br-0.17.0/tests/test_move_brasil.py +139 -0
  147. direitos_br-0.17.0/tests/test_paa.py +182 -0
  148. direitos_br-0.17.0/tests/test_params.py +120 -0
  149. direitos_br-0.17.0/tests/test_pe_de_meia_e_extras.py +85 -0
  150. direitos_br-0.17.0/tests/test_pii_rejection.py +80 -0
  151. direitos_br-0.17.0/tests/test_programas_regionais.py +165 -0
  152. direitos_br-0.17.0/tests/test_pronaf.py +74 -0
  153. direitos_br-0.17.0/tests/test_reforma_casa_brasil.py +169 -0
  154. direitos_br-0.17.0/tests/test_rescisao_clt.py +181 -0
  155. direitos_br-0.17.0/tests/test_saude_catalog.py +531 -0
  156. direitos_br-0.17.0/tests/test_saude_parity.py +364 -0
  157. direitos_br-0.17.0/tests/test_saude_rules.py +531 -0
  158. direitos_br-0.17.0/tests/test_seguro_desemprego.py +115 -0
  159. direitos_br-0.17.0/tests/test_tarifas_e_gas.py +110 -0
  160. direitos_br-0.17.0/tests/test_web_assets.py +226 -0
  161. direitos_br-0.17.0/tests/test_web_parity.py +1456 -0
  162. direitos_br-0.17.0/uv.lock +1231 -0
  163. direitos_br-0.17.0/web/app.js +4838 -0
  164. direitos_br-0.17.0/web/data/consumidor.json +335 -0
  165. direitos_br-0.17.0/web/data/params.json +1655 -0
  166. direitos_br-0.17.0/web/data/saude.json +246 -0
  167. direitos_br-0.17.0/web/engine.js +7571 -0
  168. direitos_br-0.17.0/web/engines/consumidor.js +1853 -0
  169. direitos_br-0.17.0/web/engines/saude.js +1277 -0
  170. direitos_br-0.17.0/web/google92b539d17b95fd22.html +1 -0
  171. direitos_br-0.17.0/web/icons/icon-192.png +0 -0
  172. direitos_br-0.17.0/web/icons/icon-512.png +0 -0
  173. direitos_br-0.17.0/web/icons/icon-maskable-512.png +0 -0
  174. direitos_br-0.17.0/web/icons/icon.svg +6 -0
  175. direitos_br-0.17.0/web/index.html +3347 -0
  176. direitos_br-0.17.0/web/llms.txt +138 -0
  177. direitos_br-0.17.0/web/manifest.webmanifest +31 -0
  178. direitos_br-0.17.0/web/og-image.png +0 -0
  179. direitos_br-0.17.0/web/robots.txt +4 -0
  180. direitos_br-0.17.0/web/sitemap.xml +9 -0
  181. direitos_br-0.17.0/web/styles.css +1187 -0
  182. direitos_br-0.17.0/web/sw.js +136 -0
@@ -0,0 +1,18 @@
1
+ .git/
2
+ .github/
3
+ .venv/
4
+ __pycache__/
5
+ *.py[cod]
6
+ *$py.class
7
+ .pytest_cache/
8
+ .mypy_cache/
9
+ .ruff_cache/
10
+ .coverage
11
+ htmlcov/
12
+ dist/
13
+ build/
14
+ *.egg-info/
15
+ tests/
16
+ scripts/
17
+ deploy/
18
+ .DS_Store
@@ -0,0 +1,22 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "uv"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "monthly"
7
+ open-pull-requests-limit: 5
8
+ groups:
9
+ python-minor-patch:
10
+ update-types:
11
+ - "minor"
12
+ - "patch"
13
+
14
+ - package-ecosystem: "github-actions"
15
+ directory: "/"
16
+ schedule:
17
+ interval: "monthly"
18
+ open-pull-requests-limit: 5
19
+ groups:
20
+ actions:
21
+ patterns:
22
+ - "*"
@@ -0,0 +1,125 @@
1
+ name: Annual Normative Audit (TOML & Statutory Schedule)
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 9 2 1 *"
6
+ - cron: "0 9 1 10 *"
7
+ workflow_dispatch:
8
+ inputs:
9
+ target_year:
10
+ description: "Ano-alvo da auditoria (vazio = ano atual em Jan / próximo ano em Out+)"
11
+ required: false
12
+ default: ""
13
+ type: string
14
+ dry_run:
15
+ description: "Executa auditoria sem abrir nem comentar Issues no GitHub"
16
+ required: false
17
+ default: false
18
+ type: boolean
19
+
20
+ permissions:
21
+ contents: read
22
+ issues: write
23
+
24
+ jobs:
25
+ audit-normative-tables:
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - name: Checkout repository
29
+ uses: actions/checkout@v7
30
+
31
+ - name: Install uv and Python 3.12
32
+ uses: astral-sh/setup-uv@v10.4.2
33
+ with:
34
+ python-version: "3.12"
35
+ enable-cache: true
36
+
37
+ - name: Install dependencies
38
+ run: uv sync --frozen
39
+
40
+ - name: Verify web params and version sync
41
+ run: |
42
+ uv run python scripts/export_web_params.py --check
43
+ uv run python scripts/check_versions.py
44
+
45
+ - name: Run normative schedule audit
46
+ id: audit
47
+ run: |
48
+ INPUT_YEAR="${{ inputs.target_year }}"
49
+ if [ -n "${INPUT_YEAR}" ]; then
50
+ YEAR="${INPUT_YEAR}"
51
+ else
52
+ YEAR="$(python3 -c 'from datetime import UTC, datetime; now = datetime.now(UTC); print(now.year + (1 if now.month >= 10 else 0))')"
53
+ fi
54
+ NEXT_YEAR=$((YEAR + 1))
55
+ echo "target_year=${YEAR}" >> "${GITHUB_OUTPUT}"
56
+ echo "next_year=${NEXT_YEAR}" >> "${GITHUB_OUTPUT}"
57
+
58
+ uv run python scripts/check_normative_schedule.py \
59
+ --year "${YEAR}" \
60
+ --require-next-year-scaffold \
61
+ --markdown-out audit.md \
62
+ --json > audit.json
63
+
64
+ NEEDS_ACTION="$(python3 -c 'import json; print("true" if json.load(open("audit.json"))["needs_action"] else "false")')"
65
+ echo "needs_action=${NEEDS_ACTION}" >> "${GITHUB_OUTPUT}"
66
+ cat audit.md
67
+
68
+ - name: Create or update tracking issue when normative action is needed
69
+ if: ${{ steps.audit.outputs.needs_action == 'true' && inputs.dry_run != true }}
70
+ env:
71
+ GH_TOKEN: ${{ github.token }}
72
+ TARGET_YEAR: ${{ steps.audit.outputs.target_year }}
73
+ NEXT_YEAR: ${{ steps.audit.outputs.next_year }}
74
+ run: |
75
+ python3 - <<'PY'
76
+ import json
77
+ import os
78
+ import subprocess
79
+ from datetime import UTC, datetime, timedelta
80
+
81
+ target_year = os.environ["TARGET_YEAR"]
82
+ next_year = os.environ["NEXT_YEAR"]
83
+ marker = f"{target_year}-01"
84
+
85
+ issues_raw = subprocess.check_output(
86
+ ["gh", "issue", "list", "--state", "open", "--limit", "50", "--json", "number,title"],
87
+ text=True,
88
+ )
89
+ issues = json.loads(issues_raw)
90
+ existing = next((it for it in issues if marker in str(it.get("title", ""))), None)
91
+
92
+ if existing is not None:
93
+ num = str(existing["number"])
94
+ last_raw = subprocess.check_output(
95
+ ["gh", "issue", "view", num, "--json", "comments", "--jq", ".comments[-1].createdAt // \"\""],
96
+ text=True,
97
+ ).strip()
98
+ if last_raw:
99
+ last_dt = datetime.fromisoformat(last_raw.replace("Z", "+00:00"))
100
+ if datetime.now(UTC) - last_dt < timedelta(days=7):
101
+ print(f"Skipping duplicate comment on issue #{num} (commented < 7d ago).")
102
+ raise SystemExit(0)
103
+ subprocess.run(
104
+ ["gh", "issue", "comment", num, "--body-file", "audit.md"],
105
+ check=True,
106
+ )
107
+ print(f"Updated tracking issue #{num}.")
108
+ else:
109
+ title = f"[Normativa {marker}] Consolidar tabelas anuais {marker}.toml e preparar {next_year}-01.toml"
110
+ subprocess.run(
111
+ [
112
+ "gh",
113
+ "issue",
114
+ "create",
115
+ "--title",
116
+ title,
117
+ "--body-file",
118
+ "audit.md",
119
+ "--label",
120
+ "documentation,area:rules",
121
+ ],
122
+ check=True,
123
+ )
124
+ print(f"Created tracking issue: {title}")
125
+ PY
@@ -0,0 +1,46 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ pull_request:
7
+ branches: ["main"]
8
+
9
+ jobs:
10
+ verify:
11
+ runs-on: ubuntu-latest
12
+ steps:
13
+ - name: Checkout repository
14
+ uses: actions/checkout@v7
15
+
16
+ - name: Install uv and Python 3.12
17
+ uses: astral-sh/setup-uv@v10.4.2
18
+ with:
19
+ python-version: "3.12"
20
+ enable-cache: true
21
+
22
+ - name: Install dependencies
23
+ run: uv sync --frozen
24
+
25
+ - name: Ruff lint
26
+ run: uv run ruff check .
27
+
28
+ - name: Ruff format check
29
+ run: uv run ruff format --check .
30
+
31
+ - name: Verify web params match TOML tables
32
+ run: uv run python scripts/export_web_params.py --check
33
+
34
+ - name: Verify version & MCP server.json sync
35
+ run: uv run python scripts/check_versions.py
36
+
37
+ - name: Mypy strict type check
38
+ run: uv run mypy --strict src tests scripts etl
39
+
40
+ - name: Pytest suite (unit, CLI, HTTP, JS parity, and MCP integration)
41
+ run: uv run pytest -v
42
+
43
+ - name: CLI smoke tests
44
+ run: |
45
+ uv run direitos-br params --date 2026-10-01 --json > /dev/null
46
+ uv run direitos-br demo --date 2026-10-01 > /dev/null
@@ -0,0 +1,104 @@
1
+ name: Deploy & Maintain Google Cloud Run
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+ schedule:
7
+ - cron: "0 7 6 * *"
8
+ workflow_dispatch:
9
+ inputs:
10
+ region:
11
+ description: "GCP Cloud Run region"
12
+ required: false
13
+ default: "southamerica-east1"
14
+ type: string
15
+ service_name:
16
+ description: "Cloud Run service name"
17
+ required: false
18
+ default: "direitos-br"
19
+ type: string
20
+ keep_revisions:
21
+ description: "Number of recent Cloud Run revisions to keep"
22
+ required: false
23
+ default: 3
24
+ type: number
25
+ keep_images:
26
+ description: "Number of recent Artifact Registry images to keep"
27
+ required: false
28
+ default: 2
29
+ type: number
30
+ skip_cleanup:
31
+ description: "Skip cleanup of old Cloud Run revisions and Artifact Registry images"
32
+ required: false
33
+ default: false
34
+ type: boolean
35
+
36
+ permissions:
37
+ contents: read
38
+ id-token: write
39
+
40
+ jobs:
41
+ deploy:
42
+ if: ${{ github.event_name == 'workflow_dispatch' || vars.ENABLE_CLOUDRUN_AUTO_DEPLOY == 'true' }}
43
+ runs-on: ubuntu-latest
44
+ steps:
45
+ - name: Checkout repository
46
+ uses: actions/checkout@v7
47
+
48
+ - name: Authenticate to Google Cloud (Workload Identity Federation)
49
+ uses: google-github-actions/auth@v3
50
+ with:
51
+ workload_identity_provider: ${{ secrets.GCP_WORKLOAD_IDENTITY_PROVIDER }}
52
+ service_account: ${{ secrets.GCP_SERVICE_ACCOUNT }}
53
+
54
+ - name: Set up Google Cloud SDK
55
+ uses: google-github-actions/setup-gcloud@v3
56
+
57
+ - name: Resolve deployment target
58
+ id: target
59
+ run: |
60
+ SERVICE="${{ inputs.service_name || vars.GCP_CLOUDRUN_SERVICE || 'direitos-br' }}"
61
+ REGION="${{ inputs.region || vars.GCP_CLOUDRUN_REGION || 'southamerica-east1' }}"
62
+ KEEP_REV="${{ inputs.keep_revisions || 3 }}"
63
+ KEEP_IMG="${{ inputs.keep_images || 2 }}"
64
+ echo "service=${SERVICE}" >> "${GITHUB_OUTPUT}"
65
+ echo "region=${REGION}" >> "${GITHUB_OUTPUT}"
66
+ echo "keep_revisions=${KEEP_REV}" >> "${GITHUB_OUTPUT}"
67
+ echo "keep_images=${KEEP_IMG}" >> "${GITHUB_OUTPUT}"
68
+
69
+ - name: Deploy to Cloud Run from source
70
+ id: deploy
71
+ uses: google-github-actions/deploy-cloudrun@v3
72
+ with:
73
+ service: ${{ steps.target.outputs.service }}
74
+ region: ${{ steps.target.outputs.region }}
75
+ source: .
76
+ env_vars_update_strategy: merge
77
+ flags: >-
78
+ --allow-unauthenticated
79
+ --port=8080
80
+ --memory=256Mi
81
+ --cpu=1
82
+ --min-instances=0
83
+ --max-instances=10
84
+ --concurrency=80
85
+ --update-env-vars=DIREITOS_BR_WEB_DIR=/app/web
86
+
87
+ - name: Smoke check Cloud Run /health
88
+ run: curl -fsS "${{ steps.deploy.outputs.url }}/health"
89
+
90
+ - name: Clean up old Cloud Run revisions and Artifact Registry images
91
+ if: ${{ inputs.skip_cleanup != true }}
92
+ run: |
93
+ chmod +x deploy/cloudrun-cleanup.sh
94
+ ./deploy/cloudrun-cleanup.sh \
95
+ "${{ steps.target.outputs.service }}" \
96
+ "${{ steps.target.outputs.region }}" \
97
+ "${{ steps.target.outputs.keep_revisions }}" \
98
+ "${{ steps.target.outputs.keep_images }}"
99
+
100
+ - name: Show Service URL
101
+ run: |
102
+ echo "Cloud Run URL: ${{ steps.deploy.outputs.url }}"
103
+ echo "MCP Endpoint: ${{ steps.deploy.outputs.url }}/mcp"
104
+ echo "Health Endpoint: ${{ steps.deploy.outputs.url }}/health"
@@ -0,0 +1,87 @@
1
+ name: Build & Publish Monthly Saúde Snapshot (ANVISA + CNES)
2
+
3
+ on:
4
+ schedule:
5
+ - cron: "0 6 5 * *"
6
+ workflow_dispatch:
7
+ inputs:
8
+ snapshot_tag:
9
+ description: "Tag do snapshot de dados (padrão: data-saude-YYYY-MM)"
10
+ required: false
11
+ default: ""
12
+ type: string
13
+ keep_snapshots:
14
+ description: "Número de snapshots mensais data-saude-* mantidos"
15
+ required: false
16
+ default: 3
17
+ type: number
18
+
19
+ permissions:
20
+ contents: write
21
+
22
+ jobs:
23
+ etl-saude:
24
+ runs-on: ubuntu-latest
25
+ steps:
26
+ - name: Checkout repository
27
+ uses: actions/checkout@v7
28
+
29
+ - name: Install uv and Python 3.12
30
+ uses: astral-sh/setup-uv@v10.4.2
31
+ with:
32
+ python-version: "3.12"
33
+ enable-cache: true
34
+
35
+ - name: Install dependencies
36
+ run: uv sync --frozen
37
+
38
+ - name: Build ANVISA + CNES SQLite snapshot
39
+ id: build
40
+ run: |
41
+ INPUT_TAG="${{ inputs.snapshot_tag }}"
42
+ if [ -n "${INPUT_TAG}" ]; then
43
+ TAG="${INPUT_TAG}"
44
+ else
45
+ TAG="data-saude-$(date -u +%Y-%m)"
46
+ fi
47
+ echo "tag=${TAG}" >> "${GITHUB_OUTPUT}"
48
+ uv run python -m etl.saude.build \
49
+ --output-dir etl_out \
50
+ --snapshot-tag "${TAG}" \
51
+ --min-anvisa-rows 1000 \
52
+ --min-cnes-rows 5000
53
+
54
+ - name: Smoke check offline catalog with compiled SQLite
55
+ run: |
56
+ DIREITOS_BR_SAUDE_DB=etl_out/saude.sqlite \
57
+ uv run direitos-br data status saude --json
58
+
59
+ - name: Publish data release assets (without replacing latest code release)
60
+ env:
61
+ GH_TOKEN: ${{ github.token }}
62
+ run: |
63
+ TAG="${{ steps.build.outputs.tag }}"
64
+ if gh release view "${TAG}" >/dev/null 2>&1; then
65
+ gh release upload "${TAG}" \
66
+ etl_out/saude.sqlite.gz \
67
+ etl_out/manifest.json \
68
+ --clobber
69
+ else
70
+ gh release create "${TAG}" \
71
+ etl_out/saude.sqlite.gz \
72
+ etl_out/manifest.json \
73
+ --title "${TAG} (ANVISA + CNES Offline Snapshot)" \
74
+ --notes "Snapshot mensal compilado de DADOS_ABERTOS_MEDICAMENTOS (ANVISA) e CNES/SUS (DATASUS). Verifique \`manifest.json\` para SHA-256." \
75
+ --latest=false
76
+ fi
77
+
78
+ - name: Prune old data-saude-* releases and tags
79
+ env:
80
+ GH_TOKEN: ${{ github.token }}
81
+ run: |
82
+ TAG="${{ steps.build.outputs.tag }}"
83
+ KEEP="${{ inputs.keep_snapshots || vars.SAUDE_KEEP_SNAPSHOTS || 3 }}"
84
+ uv run python scripts/prune_data_releases.py \
85
+ --prefix data-saude- \
86
+ --keep "${KEEP}" \
87
+ --protect-tag "${TAG}"
@@ -0,0 +1,59 @@
1
+ name: Deploy Zero-PII Web App to GitHub Pages
2
+
3
+ on:
4
+ push:
5
+ branches: ["main"]
6
+ paths:
7
+ - "web/**"
8
+ - "src/direitos_br/data/**"
9
+ - "src/direitos_br/domains/*/data/**"
10
+ - "scripts/export_web_params.py"
11
+ - ".github/workflows/pages.yml"
12
+ workflow_dispatch:
13
+
14
+ permissions:
15
+ contents: read
16
+ pages: write
17
+ id-token: write
18
+
19
+ concurrency:
20
+ group: "pages"
21
+ cancel-in-progress: false
22
+
23
+ jobs:
24
+ build:
25
+ runs-on: ubuntu-latest
26
+ steps:
27
+ - name: Checkout repository
28
+ uses: actions/checkout@v7
29
+
30
+ - name: Install uv and Python 3.12
31
+ uses: astral-sh/setup-uv@v10.4.2
32
+ with:
33
+ python-version: "3.12"
34
+ enable-cache: true
35
+
36
+ - name: Install dependencies
37
+ run: uv sync --frozen --no-dev
38
+
39
+ - name: Verify web/data/params.json matches TOML tables
40
+ run: uv run python scripts/export_web_params.py --check
41
+
42
+ - name: Configure Pages
43
+ uses: actions/configure-pages@v5
44
+
45
+ - name: Upload static web bundle
46
+ uses: actions/upload-pages-artifact@v3
47
+ with:
48
+ path: ./web
49
+
50
+ deploy:
51
+ environment:
52
+ name: github-pages
53
+ url: ${{ steps.deployment.outputs.page_url }}
54
+ runs-on: ubuntu-latest
55
+ needs: build
56
+ steps:
57
+ - name: Deploy to GitHub Pages
58
+ id: deployment
59
+ uses: actions/deploy-pages@v4
@@ -0,0 +1,147 @@
1
+ name: Publish Package & GitHub Release
2
+
3
+ on:
4
+ push:
5
+ tags: ["v*"]
6
+ workflow_dispatch:
7
+ inputs:
8
+ publish_pypi:
9
+ description: "Publish package to PyPI via OIDC Trusted Publishing"
10
+ required: false
11
+ default: false
12
+ type: boolean
13
+
14
+ jobs:
15
+ build-and-verify:
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - name: Checkout repository
19
+ uses: actions/checkout@v7
20
+
21
+ - name: Install uv and Python 3.12
22
+ uses: astral-sh/setup-uv@v10.4.2
23
+ with:
24
+ python-version: "3.12"
25
+ enable-cache: true
26
+
27
+ - name: Install dependencies
28
+ run: uv sync --frozen
29
+
30
+ - name: Ruff lint & format check
31
+ run: |
32
+ uv run ruff check .
33
+ uv run ruff format --check .
34
+
35
+ - name: Verify web params match TOML tables
36
+ run: uv run python scripts/export_web_params.py --check
37
+
38
+ - name: Verify version & MCP server.json sync
39
+ run: uv run python scripts/check_versions.py
40
+
41
+ - name: Mypy strict type check
42
+ run: uv run mypy --strict src tests scripts etl
43
+
44
+ - name: Run full test suite
45
+ run: uv run pytest -v
46
+
47
+ - name: Build sdist and wheel
48
+ run: uv build
49
+
50
+ - name: Verify wheel includes TOML tables and py.typed
51
+ run: |
52
+ python3 - <<'PY'
53
+ import glob
54
+ import zipfile
55
+
56
+ wheels = glob.glob("dist/*.whl")
57
+ assert len(wheels) == 1, f"Expected 1 wheel, found {wheels}"
58
+ with zipfile.ZipFile(wheels[0]) as zf:
59
+ names = set(zf.namelist())
60
+ required = {
61
+ "direitos_br/py.typed",
62
+ "direitos_br/data/2026-01.toml",
63
+ "direitos_br/data/2026-10.toml",
64
+ "direitos_br/data/2027-01.toml",
65
+ "direitos_br/domains/consumidor/data/2026-01.toml",
66
+ "direitos_br/domains/consumidor/data/2026-10.toml",
67
+ "direitos_br/domains/consumidor/data/2027-01.toml",
68
+ "direitos_br/domains/saude/data/2026-01.toml",
69
+ "direitos_br/domains/saude/data/2026-10.toml",
70
+ "direitos_br/domains/saude/data/2027-01.toml",
71
+ }
72
+ missing = required - names
73
+ assert not missing, f"Missing files in wheel: {missing}"
74
+ forbidden = [n for n in names if n.startswith("etl") or n.endswith((".sqlite", ".sqlite.gz", ".csv"))]
75
+ assert not forbidden, f"Unexpected ETL/data files in core wheel: {forbidden}"
76
+ print("Verified wheel contents:", sorted(required))
77
+ PY
78
+
79
+ - name: Upload build artifacts
80
+ uses: actions/upload-artifact@v7
81
+ with:
82
+ name: dist-artifacts
83
+ path: dist/*
84
+
85
+ github-release:
86
+ needs: build-and-verify
87
+ if: startsWith(github.ref, 'refs/tags/v')
88
+ runs-on: ubuntu-latest
89
+ permissions:
90
+ contents: write
91
+ steps:
92
+ - name: Checkout repository
93
+ uses: actions/checkout@v7
94
+
95
+ - name: Download build artifacts
96
+ uses: actions/download-artifact@v8
97
+ with:
98
+ name: dist-artifacts
99
+ path: dist
100
+
101
+ - name: Extract release notes from CHANGELOG.md
102
+ run: |
103
+ TAG="${GITHUB_REF_NAME}"
104
+ VER="${TAG#v}"
105
+ python3 - "$VER" <<'PY'
106
+ import pathlib
107
+ import re
108
+ import sys
109
+
110
+ ver = sys.argv[1]
111
+ changelog = pathlib.Path("CHANGELOG.md").read_text(encoding="utf-8")
112
+ pattern = rf"^## \[{re.escape(ver)}\].*?(?=^## \[|\Z)"
113
+ m = re.search(pattern, changelog, flags=re.MULTILINE | re.DOTALL)
114
+ if m:
115
+ notes = m.group(0).strip()
116
+ else:
117
+ notes = f"Release {ver}\n\nVeja detalhes completos em `CHANGELOG.md`."
118
+ pathlib.Path("release_notes.md").write_text(notes + "\n", encoding="utf-8")
119
+ PY
120
+
121
+ - name: Create or update GitHub Release with wheel/sdist
122
+ env:
123
+ GH_TOKEN: ${{ github.token }}
124
+ run: |
125
+ TAG="${GITHUB_REF_NAME}"
126
+ if gh release view "${TAG}" >/dev/null 2>&1; then
127
+ gh release upload "${TAG}" dist/* --clobber
128
+ else
129
+ gh release create "${TAG}" dist/* --title "${TAG}" --notes-file release_notes.md
130
+ fi
131
+
132
+ publish-pypi:
133
+ needs: build-and-verify
134
+ if: ${{ vars.ENABLE_PYPI_PUBLISH == 'true' || inputs.publish_pypi == true }}
135
+ runs-on: ubuntu-latest
136
+ environment: pypi
137
+ permissions:
138
+ id-token: write
139
+ steps:
140
+ - name: Download build artifacts
141
+ uses: actions/download-artifact@v8
142
+ with:
143
+ name: dist-artifacts
144
+ path: dist
145
+
146
+ - name: Publish package to PyPI (OIDC Trusted Publishing)
147
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,23 @@
1
+ # Python / uv
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.egg-info/
6
+ .eggs/
7
+ dist/
8
+ build/
9
+ .venv/
10
+ .python-version
11
+
12
+ # Tools & caches
13
+ .pytest_cache/
14
+ .mypy_cache/
15
+ .ruff_cache/
16
+ .coverage
17
+ htmlcov/
18
+
19
+ # Editors / OS
20
+ .vscode/
21
+ .idea/
22
+ .DS_Store
23
+ *.swp