Issue 401 GitHub action outputs#1403
Open
lilfetz22 wants to merge 6 commits intopython-semantic-release:masterfrom
Open
Issue 401 GitHub action outputs#1403lilfetz22 wants to merge 6 commits intopython-semantic-release:masterfrom
lilfetz22 wants to merge 6 commits intopython-semantic-release:masterfrom
Conversation
Add support for new GitHub Action outputs to expose release asset information: - id: The release ID from the remote VCS - upload_url: URL for uploading additional assets to the release - assets: JSON array containing information about all uploaded assets - assets_dist: JSON object of Python dist assets organized by type (wheel, sdist) These outputs enable users to programmatically access release metadata and uploaded asset information in their GitHub workflows. Asset information includes details such as name, size, content_type, and browser_download_url. Changes: - Updated VersionGitHubActionsOutput class with new properties for release_id, upload_url, assets, and assets_dist - Modified Github.create_release() to return ReleaseInfo namedtuple containing release ID, upload URL, and asset details - Updated upload_release_asset() to return asset metadata from API response - Added new output definitions to action.yml with detailed descriptions - Updated type signatures across HVCS implementations to support ReleaseInfo - Updated version command to populate new outputs after release creation Implements: python-semantic-release#401
Adds comprehensive unit tests for the new GitHub Actions output properties: - release_id property and validation - upload_url property and validation - assets list property and validation - assets_dist computed property (categorizes by wheel/sdist) - Output format includes new fields - File writing with JSON serialization Also updates existing test_version_github_actions_output_format to expect the new fields in the output with proper line ending handling.
Adds documentation for the new GitHub Actions outputs: - id: Release ID from GitHub API - upload_url: URL for uploading additional assets - assets: JSON array of all uploaded asset metadata - assets_dist: JSON object organizing assets by type (wheel/sdist) Includes a new 'Using Release Assets Outputs' example section demonstrating: - How to download specific distribution files - How to list all assets - How to use the release ID with the GitHub API
Updates test_version_writes_github_actions_output to verify the new output fields (id, upload_url, assets, assets_dist) are correctly written to the GITHUB_OUTPUT file. When using --no-push, these fields will be empty strings or empty JSON structures since no GitHub release is created.
Wraps the conditional expression for multiline output values in parentheses to improve readability and comply with code style guidelines. This change improves the formatting of the list comprehension that generates GitHub Actions output lines. The logic remains unchanged - it still generates either a heredoc format (<<EOF) for non-empty values or an empty assignment for empty values.
Splits the logger.error() call across multiple lines to improve code readability and comply with line length guidelines. The error message formatting remains functionally identical. This change addresses a formatting issue in the build_distributions function where the error logging statement exceeded preferred line length limits.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Purpose
Resolves: #401
Adds four new GitHub Action outputs to provide access to release asset information:
id: The GitHub release ID for API interactionsupload_url: The upload URL template for adding additional assetsassets: JSON array of all uploaded asset metadataassets_dist: JSON object organizing distribution files by type (wheel/sdist)These outputs enable downstream workflow steps to programmatically access and process release artifacts, download specific distribution files, or interact with the release via the GitHub API.
Rationale
The implementation follows the existing pattern established in
VersionGitHubActionsOutput:Data Structure: Created a
ReleaseInfoNamedTuple in the GitHub HVCS to encapsulate release metadata (id, upload_url, assets) returned from the GitHub API. This provides a clean, typed structure for passing release information.Property Design: Added validated properties to
VersionGitHubActionsOutputthat:JSON Serialization: Used
json.dumps()for complex data structures (assets list and assets_dist dict) to ensure proper formatting in GitHub Actions output files.Computed Property: Implemented
assets_distas a computed property that categorizes assets by file extension (.whl → "wheel", .tar.gz → "sdist"). This provides convenience for common use cases without requiring users to parse the assets array.Type Safety: Updated the HVCS base class and all implementations to maintain type consistency with Union types, ensuring compatibility across different hosting services.
Problems Avoided:
How did you test?
Unit Tests (9 new tests in
test_github_actions_output.py)assets_distcorrectly categorizes .whl and .tar.gz filestest_version_github_actions_output_formatto expect new fields with proper line ending handlingE2E Test (updated
test_version_writes_github_actions_output)--no-pushflag where fields are empty (no GitHub release created)Manual Validation
ruff formatandruff check- all checks passmypy .- no type errorsEdge Cases Considered:
How to Verify
Checkout and setup:
Run unit tests:
All 19 tests should pass, including the 9 new tests for release asset outputs.
Run E2E test:
Test should pass and verify new fields are written to GITHUB_OUTPUT.
Run type checking:
Should complete with no errors.
Run linting:
All checks should pass.
Review documentation:
Open
docs/configuration/automatic-releases/github-actions.rstand verify:id,upload_url,assets,assets_distReview action definition:
Check
action.ymlto confirm all four outputs are defined with descriptions.PR Completion Checklist
Reviewed & followed the Contributor Guidelines
Changes Implemented & Validation pipeline succeeds
Commits follow the Conventional Commits standard
and are separated into the proper commit type and scope (recommended order: test, build, feat/fix, docs)
Appropriate Unit tests added/updated
Appropriate End-to-End tests added/updated
Appropriate Documentation added/updated and syntax validated for sphinx build (see Contributor Guidelines)