Skip to content
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

Fix .tool-versions from workspace root #325

Merged
merged 2 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions .github/workflows/test-version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ jobs:
- name: Checkout
uses: actions/checkout@v3

- name: Test terraform-version
- name: Test getting version from .tools-versions
uses: ./terraform-version
id: terraform-version
with:
Expand All @@ -115,7 +115,22 @@ jobs:
- name: Check the version
run: |
if [[ "${{ steps.terraform-version.outputs.terraform }}" != "0.12.11" ]]; then
echo "::error:: Terraform version not set from .terraform-version"
echo "::error:: Terraform version not set from .tool-versions"
exit 1
fi

mv tests/workflows/test-version/asdf/.tool-versions .tool-versions

- name: Test getting version from root .tools-versions
uses: ./terraform-version
id: root-version
with:
path: tests/workflows/test-version/asdf

- name: Check the version
run: |
if [[ "${{ steps.root-version.outputs.terraform }}" != "0.12.11" ]]; then
echo "::error:: Terraform version not set from .tool-versions"
exit 1
fi

Expand Down
5 changes: 4 additions & 1 deletion image/src/terraform_version/asdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def try_read_asdf(inputs: InitInputs, workspace_path: str, versions: Iterable[Ve

module_path = os.path.abspath(inputs.get('INPUT_PATH', '.'))

while module_path not in ['/', workspace_path]:
while module_path != '/':
asdf_path = os.path.join(module_path, '.tool-versions')

if os.path.isfile(asdf_path):
Expand All @@ -38,6 +38,9 @@ def try_read_asdf(inputs: InitInputs, workspace_path: str, versions: Iterable[Ve
except Exception as e:
debug(str(e))

if module_path == workspace_path:
break

module_path = os.path.dirname(module_path)

return None