-
Notifications
You must be signed in to change notification settings - Fork 0
Implement stdlib network and command helpers #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leynos
wants to merge
13
commits into
main
Choose a base branch
from
codex/implement-network-and-command-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e3a8f80
Implement stdlib network and command helpers
leynos 4888597
Fix stdlib command portability and tests
leynos ceb2722
Use Windows quoting when formatting commands
leynos d3aec13
Mark fetch network access as impure
leynos 2f69f0f
Harden stdlib command helpers
leynos 560b7b6
Address review feedback on stdlib helpers
leynos b58c85b
Add coverage for undefined command inputs
leynos ff68165
Document stdlib cucumber step scopes
leynos 58d72ba
Harden stdlib fixtures and dedupe undefined-input tests
leynos 23742a6
Refine stdlib fixtures and command tests
leynos 7c82368
Serialise stdlib fixtures and dedupe command tests
leynos 2addbee
Extract stdlib host parsing helpers
leynos 7178137
Refactor staging utilities and simplify release uploader CLI (#194)
leynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| name: Stage Release Artefacts | ||
| description: Stage release artefacts using a TOML configuration file. | ||
|
|
||
| inputs: | ||
| config-file: | ||
| description: Path to the project-specific TOML staging configuration file. | ||
| required: true | ||
| target: | ||
| description: The target key from the configuration file to be staged. | ||
| required: true | ||
|
|
||
| outputs: | ||
| artifact_dir: | ||
| description: Absolute path to the directory containing the staged artefacts. | ||
| value: ${{ steps.run-stage.outputs.artifact_dir }} | ||
| dist_dir: | ||
| description: Absolute path to the workspace distribution directory. | ||
| value: ${{ steps.run-stage.outputs.dist_dir }} | ||
| staged_files: | ||
| description: Newline-separated list of staged file names. | ||
| value: ${{ steps.run-stage.outputs.staged_files }} | ||
| artefact_map: | ||
| description: JSON map of named artefact outputs to their absolute paths. | ||
| value: ${{ steps.run-stage.outputs.artefact_map }} | ||
| checksum_map: | ||
| description: JSON map of staged file names to their checksum digests. | ||
| value: ${{ steps.run-stage.outputs.checksum_map }} | ||
| binary_path: | ||
| description: Absolute path to the staged binary artefact, when available. | ||
| value: ${{ steps.run-stage.outputs.binary_path }} | ||
| man_path: | ||
| description: Absolute path to the staged manual page artefact, when available. | ||
| value: ${{ steps.run-stage.outputs.man_path }} | ||
| license_path: | ||
| description: Absolute path to the staged licence artefact, when available. | ||
| value: ${{ steps.run-stage.outputs.license_path }} | ||
|
|
||
| runs: | ||
| using: composite | ||
| steps: | ||
| - name: Install uv | ||
| uses: astral-sh/setup-uv@8d55fbecc275b1c35dbe060458839f8d30439ccf | ||
| with: | ||
| python-version: '3.11' | ||
| - id: check-uv | ||
| name: Verify uv is available | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| if ! command -v uv >/dev/null 2>&1; then | ||
| echo "::error title=Missing dependency::uv not found on PATH. Install it (e.g. with astral-sh/setup-uv) before this action." | ||
| exit 1 | ||
| fi | ||
| - id: run-stage | ||
| name: Run staging script | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
| uv run "${{ github.action_path }}/scripts/stage.py" "${{ inputs.config-file }}" "${{ inputs.target }}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| # /// script | ||
| # requires-python = ">=3.11" | ||
| # dependencies = [ | ||
| # "cyclopts>=0.14", | ||
| # ] | ||
| # /// | ||
|
|
||
| """Command-line entry point for the staging helper. | ||
|
|
||
| Examples | ||
| -------- | ||
| Run the staging helper locally after exporting the required environment | ||
| variables:: | ||
|
|
||
| export GITHUB_WORKSPACE="$(pwd)" | ||
| export GITHUB_OUTPUT="$(mktemp)" | ||
| uv run .github/actions/stage/scripts/stage.py \ | ||
| .github/release-staging.toml linux-x86_64 | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| from stage_common import StageError, load_config, require_env_path, stage_artefacts | ||
|
|
||
| import cyclopts | ||
|
|
||
| app = cyclopts.App(help="Stage release artefacts using a TOML configuration file.") | ||
|
|
||
|
|
||
| @app.default | ||
| def main(config_file: Path, target: str) -> None: | ||
| """Stage artefacts for ``target`` using ``config_file``. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| config_file: | ||
| Path to the project-specific TOML configuration file. | ||
| target: | ||
| Target key in the configuration file (for example ``"linux-x86_64"``). | ||
| """ | ||
| try: | ||
| config_path = Path(config_file) | ||
| github_output = require_env_path("GITHUB_OUTPUT") | ||
| config = load_config(config_path, target) | ||
| result = stage_artefacts(config, github_output) | ||
| except (FileNotFoundError, StageError) as exc: | ||
| print(f"::error title=Staging Failure::{exc}", file=sys.stderr) | ||
| raise SystemExit(1) from exc | ||
|
|
||
| staged_rel = result.staging_dir.relative_to(config.workspace) | ||
| print( | ||
| f"Staged {len(result.staged_artefacts)} artefact(s) into '{staged_rel}'.", | ||
| file=sys.stderr, | ||
| ) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| app() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| """Public interface for the staging helper package.""" | ||
|
|
||
| from .config import ArtefactConfig, StagingConfig, load_config | ||
| from .environment import require_env_path | ||
| from .errors import StageError | ||
| from .staging import RESERVED_OUTPUT_KEYS, StageResult, stage_artefacts | ||
|
|
||
| __all__ = [ | ||
| "ArtefactConfig", | ||
| "RESERVED_OUTPUT_KEYS", | ||
| "StageError", | ||
| "StageResult", | ||
| "StagingConfig", | ||
| "load_config", | ||
| "require_env_path", | ||
| "stage_artefacts", | ||
| ] |
21 changes: 21 additions & 0 deletions
21
.github/actions/stage/scripts/stage_common/checksum_utils.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| """Checksum helpers for staged artefacts.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import hashlib | ||
| from pathlib import Path | ||
|
|
||
| __all__ = ["write_checksum"] | ||
|
|
||
|
|
||
| def write_checksum(path: Path, algorithm: str) -> str: | ||
| """Write the checksum sidecar for ``path`` using ``algorithm``.""" | ||
|
|
||
| hasher = hashlib.new(algorithm) | ||
| with path.open("rb") as handle: | ||
| for chunk in iter(lambda: handle.read(8192), b""): | ||
| hasher.update(chunk) | ||
| digest = hasher.hexdigest() | ||
| checksum_path = path.with_name(f"{path.name}.{algorithm}") | ||
| checksum_path.write_text(f"{digest} {path.name}\n", encoding="utf-8") | ||
| return digest |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Remove redundant Path conversion.
The parameter
config_fileis already typed asPath, so converting it again is unnecessary.Apply this diff:
📝 Committable suggestion
🤖 Prompt for AI Agents