Skip to content

Commit 6e1fe28

Browse files
Rn/prebuild mdx transforms (#910)
* Move to node style imports * Fix last bit of tests * create a /prebuild folder * fix prebuild path * Fix next.js ts compile path resolution * forgot to put prebuild back... * Add prebuild binaries and run them * pass in command line args to prebuild binary * Add prebuild binaries GHA * move to using execFileSync * Potential fix for code scanning alert no. 21: Workflow does not contain permissions Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com> * Add caching to see if that speeds anything up * Revert "Add caching to see if that speeds anything up" This reverts commit 6beea78. * Update wording for GHA * add linux arm binary for docker on macs * Update paths in watch-content that were missed * remove unnecessary code comments --------- Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 23af797 commit 6e1fe28

File tree

88 files changed

+633
-218
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+633
-218
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
name: Check Prebuild Binaries
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'scripts/prebuild/**'
7+
- 'scripts/utils/**'
8+
- 'scripts/algolia/**'
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
check-prebuild-binaries:
15+
runs-on: ubuntu-latest
16+
name: Validate prebuild binaries are updated
17+
18+
steps:
19+
- name: Checkout code
20+
uses: actions/checkout@eef61447b9ff4aafe5dcd4e0bbf5d482be7e7871 # v4.2.1
21+
22+
- name: Get changed files
23+
id: changed-files
24+
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
25+
with:
26+
files: |
27+
scripts/prebuild/**
28+
scripts/utils/**
29+
scripts/algolia/**
30+
files_ignore: |
31+
scripts/prebuild/prebuild-arm-mac-binary.gz
32+
scripts/prebuild/prebuild-x64-linux-binary.gz
33+
scripts/prebuild/prebuild-arm-linux-binary.gz
34+
35+
- name: Check if prebuild scripts changed
36+
id: check-changes
37+
run: |
38+
echo "Changed files: ${{ steps.changed-files.outputs.all_changed_files }}"
39+
if [[ "${{ steps.changed-files.outputs.any_changed }}" == "true" ]]; then
40+
echo "prebuild_changed=true" >> $GITHUB_OUTPUT
41+
echo "✅ Prebuild scripts have changed"
42+
else
43+
echo "prebuild_changed=false" >> $GITHUB_OUTPUT
44+
echo "ℹ️ No prebuild script changes detected"
45+
fi
46+
47+
- name: Check if binaries were updated
48+
id: check-binaries
49+
if: steps.check-changes.outputs.prebuild_changed == 'true'
50+
uses: tj-actions/changed-files@dcc7a0cba800f454d79fff4b993e8c3555bcc0a8 # v45.0.7
51+
with:
52+
files: |
53+
scripts/prebuild/prebuild-arm-mac-binary.gz
54+
scripts/prebuild/prebuild-x64-linux-binary.gz
55+
scripts/prebuild/prebuild-arm-linux-binary.gz
56+
57+
- name: Validate binary updates
58+
if: steps.check-changes.outputs.prebuild_changed == 'true'
59+
run: |
60+
echo "Prebuild scripts changed: ${{ steps.check-changes.outputs.prebuild_changed }}"
61+
echo "Binaries changed: ${{ steps.check-binaries.outputs.any_changed }}"
62+
echo "Changed binaries: ${{ steps.check-binaries.outputs.all_changed_files }}"
63+
64+
if [[ "${{ steps.check-binaries.outputs.any_changed }}" != "true" ]]; then
65+
echo "❌ ERROR: Prebuild scripts have been modified but the required gzipped binaries have not been updated!"
66+
echo ""
67+
echo "The following files were changed in scripts/prebuild/:"
68+
echo "${{ steps.changed-files.outputs.all_changed_files }}"
69+
echo ""
70+
echo "Please ensure you have updated the following gzipped binaries:"
71+
echo "- scripts/prebuild/prebuild-arm-mac-binary.gz"
72+
echo "- scripts/prebuild/prebuild-x64-linux-binary.gz"
73+
echo "- scripts/prebuild/prebuild-arm-linux-binary.gz"
74+
echo ""
75+
echo "ℹ️ You can rebuild them with 'npm run compile-prebuild' and then commit the changes."
76+
exit 1
77+
78+
else
79+
# Check if all binaries were updated
80+
ARM_MAC_UPDATED=false
81+
X64_LINUX_UPDATED=false
82+
ARM_LINUX_UPDATED=false
83+
84+
if echo "${{ steps.check-binaries.outputs.all_changed_files }}" | grep -q "prebuild-arm-mac-binary.gz"; then
85+
ARM_MAC_UPDATED=true
86+
echo "✅ ARM Mac binary updated"
87+
fi
88+
89+
if echo "${{ steps.check-binaries.outputs.all_changed_files }}" | grep -q "prebuild-x64-linux-binary.gz"; then
90+
X64_LINUX_UPDATED=true
91+
echo "✅ x64 Linux binary updated"
92+
fi
93+
94+
if echo "${{ steps.check-binaries.outputs.all_changed_files }}" | grep -q "prebuild-arm-linux-binary.gz"; then
95+
ARM_LINUX_UPDATED=true
96+
echo "✅ ARM Linux binary updated"
97+
fi
98+
99+
if [[ "$ARM_MAC_UPDATED" != "true" || "$X64_LINUX_UPDATED" != "true" || "$ARM_LINUX_UPDATED" != "true" ]]; then
100+
echo "⚠️ WARNING: Not all required binaries were updated:"
101+
[[ "$ARM_MAC_UPDATED" != "true" ]] && echo " - Missing: scripts/prebuild/prebuild-arm-mac-binary.gz"
102+
[[ "$X64_LINUX_UPDATED" != "true" ]] && echo " - Missing: scripts/prebuild/prebuild-x64-linux-binary.gz"
103+
[[ "$ARM_LINUX_UPDATED" != "true" ]] && echo " - Missing: scripts/prebuild/prebuild-arm-linux-binary.gz"
104+
echo ""
105+
echo "ℹ️ You can rebuild them with 'npm run compile-prebuild' and then commit the changes."
106+
exit 1
107+
fi
108+
fi
109+
110+
- name: No changes detected
111+
if: steps.check-changes.outputs.prebuild_changed == 'false'
112+
run: |
113+
echo "✅ No prebuild script changes detected. No binary validation required."

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,8 @@ tfe-releases-repos.json
5656

5757
# copy-cloud-docs-for-tfe action
5858
.github/actions/copy-cloud-docs-for-tfe/node_modules
59+
60+
# prebuild binaries as they are too large
61+
scripts/prebuild/prebuild-arm-mac-binary
62+
scripts/prebuild/prebuild-x64-linux-binary
63+
scripts/prebuild/prebuild-arm-linux-binary

app/api/all-docs-paths/route.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@
66
import { expect, test, vi, afterEach } from 'vitest'
77
import docsPathsMock from '__fixtures__/docsPathsAllVersionsMock.json'
88
import { GET } from './route'
9-
import * as getDocsPaths from '@utils/allDocsPaths'
10-
import { mockRequest } from '@utils/mockRequest'
9+
import * as getDocsPaths from '#utils/allDocsPaths'
10+
import { mockRequest } from '#utils/mockRequest'
1111

1212
afterEach(() => {
1313
vi.restoreAllMocks()
1414
})
1515

16-
vi.mock('@api/versionMetadata.json', () => {
16+
vi.mock('#api/versionMetadata.json', () => {
1717
return {
1818
default: {},
1919
}
2020
})
2121

22-
vi.mock('@api/docsPathsAllVersions.json', () => {
22+
vi.mock('#api/docsPathsAllVersions.json', () => {
2323
return {
2424
default: {},
2525
}

app/api/all-docs-paths/route.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* SPDX-License-Identifier: BUSL-1.1
44
*/
55

6-
import { errorResultToString } from '@utils/result'
7-
import { getDocsPaths } from '@utils/allDocsPaths'
8-
import { PRODUCT_CONFIG } from '@utils/productConfig.mjs'
6+
import { errorResultToString } from '#utils/result'
7+
import { getDocsPaths } from '#utils/allDocsPaths'
8+
import { PRODUCT_CONFIG } from '#productConfig.mjs'
99

1010
export async function GET(req: Request) {
1111
const url = new URL(req.url)

app/api/assets/[productSlug]/[version]/[...assetPath]/route.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55

66
import { expect, test, vi } from 'vitest'
77
import { GET } from './route'
8-
import { getAssetData } from '@utils/file'
9-
import { getProductVersionMetadata } from '@utils/contentVersions'
10-
import { mockRequest } from '@utils/mockRequest'
8+
import { getAssetData } from '#utils/file'
9+
import { getProductVersionMetadata } from '#utils/contentVersions'
10+
import { mockRequest } from '#utils/mockRequest'
1111

12-
vi.mock('@utils/file')
13-
vi.mock('@utils/contentVersions')
14-
vi.mock('@utils/productConfig.mjs', () => {
12+
vi.mock('#utils/file')
13+
vi.mock('#utils/contentVersions')
14+
vi.mock('#productConfig.mjs', () => {
1515
return {
1616
PRODUCT_CONFIG: {
1717
terraform: {},
1818
},
1919
}
2020
})
2121

22-
vi.mock('@api/versionMetadata.json', () => {
22+
vi.mock('#api/versionMetadata.json', () => {
2323
return {}
2424
})
2525

app/api/assets/[productSlug]/[version]/[...assetPath]/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
* SPDX-License-Identifier: BUSL-1.1
44
*/
55

6-
import { getAssetData, joinFilePath } from '@utils/file'
7-
import { getProductVersionMetadata } from '@utils/contentVersions'
8-
import { errorResultToString } from '@utils/result'
9-
import { PRODUCT_CONFIG } from '@utils/productConfig.mjs'
10-
import { VersionedProduct } from '@api/types'
6+
import { getAssetData, joinFilePath } from '#utils/file'
7+
import { getProductVersionMetadata } from '#utils/contentVersions'
8+
import { errorResultToString } from '#utils/result'
9+
import { PRODUCT_CONFIG } from '#productConfig.mjs'
10+
import { VersionedProduct } from '#api/types'
1111

1212
export type GetParams = VersionedProduct & {
1313
/**

app/api/content-versions/route.test.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55

66
import { expect, test, vi, beforeEach, afterEach } from 'vitest'
77
import { GET } from './route'
8-
import { mockRequest } from '@utils/mockRequest'
8+
import { mockRequest } from '#utils/mockRequest'
9+
import { findDocVersions } from '#utils/findDocVersions'
910

1011
import { vol } from 'memfs'
1112

@@ -14,7 +15,7 @@ vi.mock('node:fs')
1415
vi.mock('node:fs/promises')
1516

1617
// Mock PRODUCT_CONFIG
17-
vi.mock('@utils/productConfig.mjs', () => {
18+
vi.mock('#productConfig.mjs', () => {
1819
return {
1920
PRODUCT_CONFIG: {
2021
'terraform-cdk': {
@@ -30,6 +31,12 @@ vi.mock('@utils/productConfig.mjs', () => {
3031
}
3132
})
3233

34+
vi.mock('#utils/findDocVersions', () => {
35+
return {
36+
findDocVersions: vi.fn(),
37+
}
38+
})
39+
3340
beforeEach(() => {
3441
// Reset the state of in-memory fs
3542
vol.reset()
@@ -76,13 +83,8 @@ test('should return 404 if the product is invalid', async () => {
7683
})
7784

7885
test('should return 200 and array of strings on valid params', async () => {
79-
vi.mock('@utils/findDocVersions.ts', () => {
80-
return {
81-
findDocVersions: () => {
82-
return ['v0.20.x', 'v0.21.x']
83-
},
84-
}
85-
})
86+
vi.mocked(findDocVersions).mockReturnValue(['v0.20.x', 'v0.21.x'])
87+
8688
const mockedResponse = {
8789
versions: ['v0.20.x', 'v0.21.x'],
8890
}

app/api/content-versions/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
* SPDX-License-Identifier: BUSL-1.1
44
*/
55

6-
import { findDocVersions } from '../../utils/findDocVersions'
7-
import { PRODUCT_CONFIG } from '@utils/productConfig.mjs'
6+
import { findDocVersions } from '#utils/findDocVersions'
7+
import { PRODUCT_CONFIG } from '#productConfig.mjs'
88

99
export async function GET(request: Request) {
1010
const url = new URL(request.url)

app/api/content/[productSlug]/doc/[version]/[...docsPath]/route.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import {
1313
MockInstance,
1414
} from 'vitest'
1515
import { GET } from './route'
16-
import { Err, Ok } from '@utils/result'
17-
import { getProductVersionMetadata } from '@utils/contentVersions'
16+
import { Err, Ok } from '#utils/result'
17+
import { getProductVersionMetadata } from '#utils/contentVersions'
1818
import { PRODUCT_CONFIG } from '__fixtures__/productConfig.mjs'
19-
import { parseMarkdownFrontMatter, findFileWithMetadata } from '@utils/file'
20-
import { mockRequest } from '@utils/mockRequest'
19+
import { parseMarkdownFrontMatter, findFileWithMetadata } from '#utils/file'
20+
import { mockRequest } from '#utils/mockRequest'
2121

22-
vi.mock(import('@utils/contentVersions'), async (importOriginal: any) => {
22+
vi.mock('#utils/contentVersions', async (importOriginal: any) => {
2323
const mod = await importOriginal()
2424
return {
2525
...mod,
2626
getProductVersionMetadata: vi.fn(),
2727
}
2828
})
2929

30-
vi.mock(import('@utils/file'), async (importOriginal: any) => {
30+
vi.mock('#utils/file', async (importOriginal: any) => {
3131
const mod = await importOriginal()
3232
return {
3333
...mod,
@@ -38,14 +38,14 @@ vi.mock(import('@utils/file'), async (importOriginal: any) => {
3838
})
3939

4040
// Mock the versionMetadata json import in the route file
41-
vi.mock('@api/versionMetadata.json', () => {
41+
vi.mock('#api/versionMetadata.json', () => {
4242
return {
4343
default: {},
4444
}
4545
})
4646

4747
// Mock the docsPathsAllVersions json import in the route file
48-
vi.mock('@api/docsPathsAllVersions.json', () => {
48+
vi.mock('#api/docsPathsAllVersions.json', () => {
4949
return {
5050
default: {
5151
'terraform-plugin-framework': {},
@@ -55,7 +55,7 @@ vi.mock('@api/docsPathsAllVersions.json', () => {
5555
})
5656

5757
// Mock the product config import in the route file
58-
vi.mock('@utils/productConfig.mjs', () => {
58+
vi.mock('#productConfig.mjs', () => {
5959
return {
6060
PRODUCT_CONFIG: {
6161
'terraform-enterprise': { contentDir: 'docs', versionedDocs: true },

app/api/content/[productSlug]/doc/[version]/[...docsPath]/route.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import {
77
findFileWithMetadata,
88
joinFilePath,
99
parseMarkdownFrontMatter,
10-
} from '@utils/file'
11-
import { getProductVersionMetadata } from '@utils/contentVersions'
12-
import { errorResultToString } from '@utils/result'
13-
import { PRODUCT_CONFIG } from '@utils/productConfig.mjs'
14-
import docsPathsAllVersions from '@api/docsPathsAllVersions.json'
15-
import { VersionedProduct } from '@api/types'
10+
} from '#utils/file'
11+
import { getProductVersionMetadata } from '#utils/contentVersions'
12+
import { errorResultToString } from '#utils/result'
13+
import { PRODUCT_CONFIG } from '#productConfig.mjs'
14+
import docsPathsAllVersions from '#api/docsPathsAllVersions.json'
15+
import { VersionedProduct } from '#api/types'
1616

1717
/**
1818
* Parameters expected by `GET` route handler

0 commit comments

Comments
 (0)