Skip to content

Read the Swift version from .swift-version when swift-version is empty - #11

Open
kantacky wants to merge 1 commit into
tryswift:mainfrom
kantacky:swift-version-file
Open

kantacky wants to merge 1 commit into
tryswift:mainfrom
kantacky:swift-version-file

Conversation

@kantacky

Copy link
Copy Markdown

Why

Many Swift projects pin their toolchain in a .swift-version file (read by swiftly, swiftenv and others). The action required swift-version on every call, so the version had to be kept in two places, or read from the file by an extra step in each workflow.

What

  • swift-version is no longer required (default ""). When it is empty, the first step reads .swift-version from the working directory and removes surrounding whitespace and newlines.
  • The value read from the file goes through the same exact-version check as the input (^[0-9]+\.[0-9]+(\.[0-9]+)?$), so ranges, latest and snapshot names are still rejected with the existing error.
  • An empty swift-version with no .swift-version file fails with a clear error naming the directory searched.
  • The resolved version is written to the first step's output, and every later step (plan, Linux/macOS/Windows install, version report, Swift SDKs) uses it instead of inputs.swift-version.
  • An explicit swift-version takes precedence, so nothing changes for existing users.
  • README: input table.

Test plan

  • action.yml parses as YAML
  • Trimming and the exact-version check run locally: " 6.4.1 \n\n" resolves to 6.4.1 and passes
  • Used in a real workflow with only .swift-version (no swift-version input): the action read 6.4.2 from the file and installed it (kantacky/gitignore-cli job 131185416478)
  • CI on this PR

🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants