Skip to content

Conversation

Copy link

Copilot AI commented Dec 3, 2025

What does it do?

Addresses https://github.com/wordpress-mobile/release-toolkit/pull/677/files#r2583457311

The .buildkite/shared-pipeline-vars script hardcoded the Ruby version instead of reading from .ruby-version. This change uses ${BASH_SOURCE[0]} to construct a location-independent path to .ruby-version, ensuring the script works regardless of the sourcing directory.

Before:

export RUBY_VERSION="3.2.2"

After:

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
export RUBY_VERSION="$(cat "$SCRIPT_DIR/../.ruby-version")"

Checklist before requesting a review

  • Run bundle exec rubocop to test for code style violations and recommendations. (Shell script change only)
  • Add Unit Tests (aka specs/*_spec.rb) if applicable. (No test infrastructure for shell scripts)
  • Run bundle exec rspec to run the whole test suite and ensure all your tests pass. (Shell script change only)
  • Make sure you added an entry in the CHANGELOG.md file to describe your changes under the appropriate existing ### subsection of the existing ## Trunk section. (Internal tooling change)
  • If applicable, add an entry in the MIGRATION.md file to describe how the changes will affect the migration from the previous major version and what the clients will need to change and consider. (Not applicable)
Original prompt

This section details on the original issue you should resolve

<issue_title>Use robust path when reading .ruby-version</issue_title>
<issue_description>See https://github.com/wordpress-mobile/release-toolkit/pull/677/files#r2583457311

</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@dangermattic
Copy link
Collaborator

dangermattic commented Dec 3, 2025

1 Warning
⚠️ Please add an entry in the CHANGELOG.md file to describe the changes made by this PR

Generated by 🚫 Danger

Instead of hardcoding the Ruby version, read it from .ruby-version
file using a path relative to the script location. This makes the
script work correctly regardless of where it's sourced from.

Co-authored-by: mokagio <[email protected]>
Copilot AI changed the title [WIP] Use robust path when reading .ruby-version Use robust path when reading .ruby-version Dec 3, 2025
Copilot AI requested a review from mokagio December 3, 2025 03:27
Copilot finished work on behalf of mokagio December 3, 2025 03:27
@mokagio mokagio marked this pull request as ready for review December 5, 2025 01:52
Copy link
Contributor

@mokagio mokagio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed that the interpolation remains correct, as CI is using 3.2.2:

image

@AliSoftware @iangmaia keen to hear what you think of:

  • Using .ruby-version as the single source of truth
  • The path juggling

@AliSoftware
Copy link
Contributor

I'm ok with using .ruby-version as source for that.

The path juggling feels a bit ugly, but iinm that's how it's supposed to be done in bash (i.e. I've seen this pattern elsewhere in various occasions), as it covers the case of BASH_SOURCE[0] being a relative path with arbitrary depth—i.e. the reason it does cd $(dirname "${BASH_SOURCE[0]}") && pwd is to cover cases like if ${BASH_SOURCE[0]} is just ./shared-pipeline-vars, where dirname will return . and the ./../.ruby-version will still work, while doing REPO_ROOT=$(dirname "$(dirname "${BASH_SOURCE[0]}")) would not work because the outer dirname . would not return .. but just ., so would not go up one level as that upper level is not part of the relative path…

Another option would have been to leverage git rev-parse --show-toplevel to get a variable pointing to the root of the repo, instead of relying on ${BASH_SOURCE[0]}. But I feel like it's more idiomatic for the shared-pipeline-vars to fully rely on bash-isms only and not rely on the git command to do those path operations (and thus not rely on if that script is run in the context of a git repo or not), to keep things conceptually isolated.

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.

Use robust path when reading .ruby-version

4 participants