Skip to content

Commit

Permalink
Merge pull request #325 from dflook/fix-root-tool-versions
Browse files Browse the repository at this point in the history
Fix .tool-versions from workspace root
  • Loading branch information
dflook committed Jan 17, 2024
2 parents 977562a + 6bc62f7 commit a6cd6bb
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
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

0 comments on commit a6cd6bb

Please sign in to comment.