Skip to content

Commit a6cd6bb

Browse files
authored
Merge pull request #325 from dflook/fix-root-tool-versions
Fix .tool-versions from workspace root
2 parents 977562a + 6bc62f7 commit a6cd6bb

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

.github/workflows/test-version.yaml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ jobs:
103103
- name: Checkout
104104
uses: actions/checkout@v3
105105

106-
- name: Test terraform-version
106+
- name: Test getting version from .tools-versions
107107
uses: ./terraform-version
108108
id: terraform-version
109109
with:
@@ -115,7 +115,22 @@ jobs:
115115
- name: Check the version
116116
run: |
117117
if [[ "${{ steps.terraform-version.outputs.terraform }}" != "0.12.11" ]]; then
118-
echo "::error:: Terraform version not set from .terraform-version"
118+
echo "::error:: Terraform version not set from .tool-versions"
119+
exit 1
120+
fi
121+
122+
mv tests/workflows/test-version/asdf/.tool-versions .tool-versions
123+
124+
- name: Test getting version from root .tools-versions
125+
uses: ./terraform-version
126+
id: root-version
127+
with:
128+
path: tests/workflows/test-version/asdf
129+
130+
- name: Check the version
131+
run: |
132+
if [[ "${{ steps.root-version.outputs.terraform }}" != "0.12.11" ]]; then
133+
echo "::error:: Terraform version not set from .tool-versions"
119134
exit 1
120135
fi
121136

image/src/terraform_version/asdf.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def try_read_asdf(inputs: InitInputs, workspace_path: str, versions: Iterable[Ve
2828

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

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

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

41+
if module_path == workspace_path:
42+
break
43+
4144
module_path = os.path.dirname(module_path)
4245

4346
return None

0 commit comments

Comments
 (0)