Skip to content

Commit 0979837

Browse files
Fixing deploy udr workflow (#1302)
Please go to the `Preview` tab and select the appropriate template: * [HCP services](?expand=1&template=hcp_pull_request_template.md) * [Terraform Enterprise](?expand=1&template=ptfe_release_pull_request_template.md) Adding in fix re [this slack support ticket](https://ibm-hashicorp.slack.com/archives/C09LU1THDDE/p1763035653464379) Failure examples: - https://github.com/hashicorp/web-unified-docs/actions/runs/19330367957/job/55291645812 > repoDir = terraform-enterprise - https://github.com/hashicorp/web-unified-docs/actions/runs/19144489383/job/54718338551 > repoDir = hcp-docs Success examples: - https://github.com/hashicorp/web-unified-docs/actions/runs/19177028442/job/54824323564 > repoDir = vault - https://github.com/hashicorp/web-unified-docs/actions/runs/19302738699/job/55201485701 (large, full dev portal reload) > repoDir = tfe and tfcommon
2 parents 80cc45f + d8cac6f commit 0979837

File tree

6 files changed

+139
-5
lines changed

6 files changed

+139
-5
lines changed

__fixtures__/docsPathsAllVersionsMock.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
"terraform-docs-common": {
3+
"v0.0.x": [
4+
{
5+
"path": "terraform/plugin/debugging",
6+
"itemPath": "content/terraform-docs-common/docs/plugin/debugging.mdx",
7+
"created_at": "2025-06-03T18:02:21+00:00"
8+
}
9+
]
10+
},
211
"terraform-plugin-framework": {
312
"v1.14.x": [
413
{
-848 Bytes
Binary file not shown.
-720 Bytes
Binary file not shown.
-185 Bytes
Binary file not shown.

scripts/utils/file-path/url/index.mjs

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,38 @@ export function getUrlFromFilePath(
2222
productConfig = PRODUCT_CONFIG,
2323
) {
2424
const repoDir = getProductDirectoryFromFilePath(filePath)
25-
const version = getVersionFromFilePath(filePath)
2625
const isValidProduct = productConfig[repoDir]
2726

2827
if (!isValidProduct) {
2928
throw new Error(`Product not found for ${repoDir}`)
30-
} else {
31-
return allDocsPaths[repoDir][version].find((path) => {
32-
return filePath.endsWith(path.itemPath)
33-
}).path
3429
}
30+
31+
// Check for versionless products and use v0.0.x as the version key
32+
const version = productConfig[repoDir].versionedDocs
33+
? getVersionFromFilePath(filePath)
34+
: 'v0.0.x'
35+
36+
// Check if the version exists in allDocsPaths
37+
if (!allDocsPaths[repoDir]) {
38+
throw new Error(`No docs paths found for product: ${repoDir}`)
39+
}
40+
41+
if (!allDocsPaths[repoDir][version]) {
42+
throw new Error(
43+
`Version ${version} not found for product ${repoDir}. File path: ${filePath}`,
44+
)
45+
}
46+
47+
// Find the matching path
48+
const matchedPath = allDocsPaths[repoDir][version].find((path) => {
49+
return filePath.endsWith(path.itemPath)
50+
})
51+
52+
if (!matchedPath) {
53+
throw new Error(
54+
`No matching path found for file: ${filePath} in version ${version} of ${repoDir}`,
55+
)
56+
}
57+
58+
return matchedPath.path
3559
}

scripts/utils/file-path/url/index.test.mjs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,105 @@ describe('getUrlFromFilePath', () => {
5252
return getUrlFromFilePath(filePath, allDocsPathsJsonMock, PRODUCT_CONFIG)
5353
}).toThrow(`Product not found for ${repoDir}`)
5454
})
55+
56+
it('should use v0.0.x for versionless products (terraform-docs-common)', () => {
57+
const filePath = 'content/terraform-docs-common/docs/plugin/debugging.mdx'
58+
const repoDir = 'terraform-docs-common'
59+
const expectedUrl = 'terraform/plugin/debugging'
60+
61+
getProductDirectoryFromFilePath.mockReturnValue(repoDir)
62+
// versionedDocs: false, so should use v0.0.x
63+
64+
const result = getUrlFromFilePath(
65+
filePath,
66+
allDocsPathsJsonMock,
67+
PRODUCT_CONFIG,
68+
)
69+
expect(result).toBe(expectedUrl)
70+
})
71+
72+
it('should use v0.0.x for versionless products (hcp-docs)', () => {
73+
const filePath =
74+
'content/hcp-docs/content/docs/vagrant/reclaim-vagrant-cloud.mdx'
75+
const repoDir = 'hcp-docs'
76+
const expectedUrl = 'hcp/docs/vagrant/reclaim-vagrant-cloud'
77+
78+
// Add hcp-docs to product config for this test only
79+
const mockProductConfig = {
80+
...PRODUCT_CONFIG,
81+
'hcp-docs': {
82+
versionedDocs: false,
83+
productSlug: 'hcp',
84+
},
85+
}
86+
87+
// Add hcp-docs to allDocsPaths for this test only
88+
const mockAllDocsPaths = {
89+
...allDocsPathsJsonMock,
90+
'hcp-docs': {
91+
'v0.0.x': [
92+
{
93+
path: expectedUrl,
94+
itemPath: filePath,
95+
created_at: '2025-06-03T18:02:21+00:00',
96+
},
97+
],
98+
},
99+
}
100+
101+
getProductDirectoryFromFilePath.mockReturnValue(repoDir)
102+
// versionedDocs: false, so should use v0.0.x
103+
104+
const result = getUrlFromFilePath(
105+
filePath,
106+
mockAllDocsPaths,
107+
mockProductConfig,
108+
)
109+
expect(result).toBe(expectedUrl)
110+
})
111+
112+
it('should throw an error if no docs paths found for product', () => {
113+
const filePath = 'content/terraform-plugin-framework/v1.14.x/docs/test.mdx'
114+
const repoDir = 'terraform-plugin-framework'
115+
const versionValue = 'v1.14.x'
116+
const allDocsPathsEmpty = {}
117+
118+
getProductDirectoryFromFilePath.mockReturnValue(repoDir)
119+
getVersionFromFilePath.mockReturnValue(versionValue)
120+
121+
expect(() => {
122+
return getUrlFromFilePath(filePath, allDocsPathsEmpty, PRODUCT_CONFIG)
123+
}).toThrow(`No docs paths found for product: ${repoDir}`)
124+
})
125+
126+
it('should throw an error if version not found for product', () => {
127+
const filePath = 'content/terraform-plugin-framework/v99.99.x/docs/test.mdx'
128+
const repoDir = 'terraform-plugin-framework'
129+
const versionValue = 'v99.99.x'
130+
131+
getProductDirectoryFromFilePath.mockReturnValue(repoDir)
132+
getVersionFromFilePath.mockReturnValue(versionValue)
133+
134+
expect(() => {
135+
return getUrlFromFilePath(filePath, allDocsPathsJsonMock, PRODUCT_CONFIG)
136+
}).toThrow(
137+
`Version ${versionValue} not found for product ${repoDir}. File path: ${filePath}`,
138+
)
139+
})
140+
141+
it('should throw an error if no matching path found for file', () => {
142+
const filePath =
143+
'content/terraform-plugin-framework/v1.14.x/docs/nonexistent-file.mdx'
144+
const repoDir = 'terraform-plugin-framework'
145+
const versionValue = 'v1.14.x'
146+
147+
getProductDirectoryFromFilePath.mockReturnValue(repoDir)
148+
getVersionFromFilePath.mockReturnValue(versionValue)
149+
150+
expect(() => {
151+
return getUrlFromFilePath(filePath, allDocsPathsJsonMock, PRODUCT_CONFIG)
152+
}).toThrow(
153+
`No matching path found for file: ${filePath} in version ${versionValue} of ${repoDir}`,
154+
)
155+
})
55156
})

0 commit comments

Comments
 (0)