Repository navigation
Description
Summary
Rewrite the Bash helper scripts in the composite actions as a single, unit-tested Python package. Python is already guaranteed on the runner (we install uv and already use Python for TOML parsing), so we can consolidate the shell logic into testable functions and import rsconnect-python where it helps.
This is motivated by the fact that the script logic (config resolution, app_mode → subcommand mapping, metadata-arg building, deployment-file auto-detection) is pure logic that is painful to test in Bash and currently has no tests at all.
Scope
The four .sh files plus the two already-Python TOML parsers:
| File | Lines | What it does |
|---|---|---|
deploy/scripts/deploy.sh |
100 | app_mode lookup (curl+jq), metadata-arg building, rsconnect deploy, URL scraping |
deploy/scripts/resolve-config.sh |
51 | 3-tier config resolution, TOML auto-detect |
cleanup-previews/scripts/resolve-config.sh |
50 | near-duplicate of the above |
deploy/scripts/generate-requirements.sh |
26 | uv pip compile |
deploy/scripts/parse-deployment-toml.py |
20 | already Python (near-duplicate) |
cleanup-previews/scripts/parse-deployment-toml.py |
16 | already Python (near-duplicate) |
Out of scope (for now):
get-api-key/get-api-key.sh— OIDC exchange has moved into rsconnect-python (feat: exchange OIDC identity tokens for an API key inrsconnect loginrsconnect-python#802). There is likely a larger change to make here (rsconnect loginshared across action steps); tracked separately.- The inline
actions/github-scriptJavaScript in bothaction.ymlfiles (PR comment / bundle-ID logic) — that's JS tied to the github-script action; leave as-is.
Target layout
A real package at the repo root (not PEP 723 single-files), so shared code and pytest are clean:
connect-actions/
pyproject.toml # package "connect_actions", python>=3.11, dev dep: pytest
src/connect_actions/
__init__.py
config.py # resolve_config() — pure logic
cli.py # argparse dispatch + GITHUB_OUTPUT writing (thin I/O shell)
requirements.py # generate-requirements
deploy.py # app_mode lookup, metadata args, deploy
tests/
test_config.py
deploy/action.yml # step: uv run --project ${{ github.action_path }}/.. python -m connect_actions.cli resolve-config
cleanup-previews/action.yml # same module, ignores entrypoint
Both actions already reach sibling code via ${{ github.action_path }}/../… (that's how get-api-key is invoked), so --project ${{ github.action_path }}/.. points uv at the repo-root pyproject.toml while working-directory: ${{ inputs.path }} keeps the user's app dir as cwd.
Design principles
- Pure functions + thin
main(). All logic in importable functions with typed inputs/outputs; a thin CLI layer reads env, writesGITHUB_OUTPUT, and shells out. Only the thin layer touches I/O. - Collapse the duplication. The two
resolve-config.sh+ twoparse-deployment-toml.pybecome oneconfig.py; deploy needs the extraentrypointfield, cleanup just ignores it. - Drop the
tomldependency in favor of stdlibtomllib(pin python>=3.11 viauv). - Keep the
action.ymlenv-var contract identical so the rewrite is mechanical from the actions' perspective. - Add CI — there is no test/lint CI today. Add a workflow that runs
uv run pytest.
One real design decision: rsconnect deploy
The deploy itself stays a side-effecting invocation. Two options:
- Subprocess the CLI and parse stdout for the content URL (what
deploy.shdoes today via grep+sed). Smallest change. - Use
rsconnect-pythonas a library and get the URL back as structured data — no log-scraping, more testable, but couples to rsconnect internals.
Start with (1) to keep the rewrite mechanical; revisit (2) later, likely alongside the rsconnect login / shared-session work.
Suggested order (incremental PRs)
- Config resolution (
resolve-config.sh+parse-deployment-toml.py, both actions →config.py+ tests). Self-contained, already half-Python, most duplicated, pure logic. Establishes thepyproject.toml/srclayout, thepytestharness, the CI workflow, and theuv runinvocation pattern that everything else reuses. generate-requirements.sh→requirements.py.deploy.sh→deploy.py(the big one; carries the CLI-vs-library decision above).
First bite: config resolution
Behavior must match the current 3-tier resolution: (1) explicit connect-server+content-guid inputs, (2) specified deployment-file, (3) auto-detect exactly one .toml under .posit/publish/deployments/ (current Bash uses recursive find, so use rglob). Error messages preserved for: missing dir, zero files, multiple files, missing specified file.
Tests cover: explicit inputs win; single-toml auto-detect (incl. entrypoint); multiple-toml error; missing-dir error.
Activity
refactor: rewrite config resolution as a unit-tested Python package (#36
nealrichardson commentedon Jul 7, 2026
We've done a bunch of this by various means, closing this as done, may still refactor other things later 🤷